#5532: Checking for recipe steps having executed.

If no steps were scheduled, the user stays on the Import screen and a notification is displayed.

Fixes #5532
This commit is contained in:
Sipke Schoorstra
2015-07-17 10:41:46 +01:00
parent 9f7908a410
commit 42901c8ea5
4 changed files with 26 additions and 11 deletions

View File

@@ -12,6 +12,7 @@ using Orchard.ImportExport.Services;
using Orchard.ImportExport.ViewModels; using Orchard.ImportExport.ViewModels;
using Orchard.Mvc; using Orchard.Mvc;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
using Orchard.UI.Notify;
namespace Orchard.ImportExport.Providers.ImportActions { namespace Orchard.ImportExport.Providers.ImportActions {
public class UploadRecipeAction : ImportAction { public class UploadRecipeAction : ImportAction {
@@ -136,6 +137,12 @@ namespace Orchard.ImportExport.Providers.ImportActions {
_orchardServices.WorkContext.HttpContext.Server.ScriptTimeout = 600; _orchardServices.WorkContext.HttpContext.Server.ScriptTimeout = 600;
var executionId = ResetSite ? Setup() : ExecuteRecipe(); var executionId = ResetSite ? Setup() : ExecuteRecipe();
if(executionId == null) {
_orchardServices.Notifier.Warning(T("The recipe contained no steps. No work was scheduled."));
return;
}
context.ActionResult = new RedirectToRouteResult(new RouteValueDictionary(new { action = "ImportResult", controller = "Admin", area = "Orchard.ImportExport", executionId = executionId })); context.ActionResult = new RedirectToRouteResult(new RouteValueDictionary(new { action = "ImportResult", controller = "Admin", area = "Orchard.ImportExport", executionId = executionId }));
} }

View File

@@ -1,12 +1,12 @@
using System; using System;
using System.Linq;
using Orchard.Data; using Orchard.Data;
using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Recipes.Events; using Orchard.Recipes.Events;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
namespace Orchard.Recipes.Services { namespace Orchard.Recipes.Services {
public class RecipeManager : IRecipeManager { public class RecipeManager : Component, IRecipeManager {
private readonly IRecipeStepQueue _recipeStepQueue; private readonly IRecipeStepQueue _recipeStepQueue;
private readonly IRecipeScheduler _recipeScheduler; private readonly IRecipeScheduler _recipeScheduler;
private readonly IRecipeExecuteEventHandler _recipeExecuteEventHandler; private readonly IRecipeExecuteEventHandler _recipeExecuteEventHandler;
@@ -22,17 +22,18 @@ namespace Orchard.Recipes.Services {
_recipeScheduler = recipeScheduler; _recipeScheduler = recipeScheduler;
_recipeExecuteEventHandler = recipeExecuteEventHandler; _recipeExecuteEventHandler = recipeExecuteEventHandler;
_recipeStepResultRecordRepository = recipeStepResultRecordRepository; _recipeStepResultRecordRepository = recipeStepResultRecordRepository;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
} }
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public string Execute(Recipe recipe) { public string Execute(Recipe recipe) {
if (recipe == null) if (recipe == null) {
Logger.Information("Cannot execute a null recipe. No work has been scheduled.");
return null; return null;
}
if (!recipe.RecipeSteps.Any()) {
Logger.Information("Recipe '{0}' contains no steps. No work has been scheduled.");
return null;
}
var executionId = Guid.NewGuid().ToString("n"); var executionId = Guid.NewGuid().ToString("n");
Logger.Information("Executing recipe '{0}' using ExecutionId {1}.", recipe.Name, executionId); Logger.Information("Executing recipe '{0}' using ExecutionId {1}.", recipe.Name, executionId);

View File

@@ -7,7 +7,10 @@ using Orchard.Recipes.Models;
namespace Orchard.Recipes.Services { namespace Orchard.Recipes.Services {
public class RecipeParser : Component, IRecipeParser { public class RecipeParser : Component, IRecipeParser {
public Recipe ParseRecipe(XDocument recipeDocument) {
return ParseRecipe(recipeDocument.ToString(SaveOptions.DisableFormatting));
}
public Recipe ParseRecipe(string recipeText) { public Recipe ParseRecipe(string recipeText) {
var recipe = new Recipe(); var recipe = new Recipe();

View File

@@ -30,7 +30,11 @@ namespace Orchard.Recipes.Services {
public string Execute(Recipe recipe) { public string Execute(Recipe recipe) {
var executionId = _recipeManager.Execute(recipe); var executionId = _recipeManager.Execute(recipe);
UpdateShell();
// Only need to update the shell if work was actually done.
if(executionId != null)
UpdateShell();
return executionId; return executionId;
} }