From 95eecd30b98b951b06e7178678dc0f60b4afd513 Mon Sep 17 00:00:00 2001 From: Daniel Stolt Date: Thu, 9 Jul 2015 16:54:13 +0100 Subject: [PATCH] Added logging to replace removed recipe journals. --- .../RecipeHandlers/CommandRecipeHandler.cs | 20 ++++++---- .../RecipeHandlers/DataRecipeHandler.cs | 27 ++++++++++---- .../RecipeHandlers/FeatureRecipeHandler.cs | 11 ++++-- .../RecipeHandlers/MetaDataRecipeHandler.cs | 33 +++++++++++++---- .../RecipeHandlers/MigrationRecipeHandler.cs | 24 ++++++++++-- .../RecipeHandlers/ModuleRecipeHandler.cs | 10 ++--- .../RecipeHandlers/SettingsRecipeHandler.cs | 15 +++++--- .../RecipeHandlers/ThemeRecipeHandler.cs | 13 +++++-- .../Orchard.Recipes/Services/RecipeManager.cs | 3 +- .../Services/RecipeStepExecutor.cs | 34 +++++------------ .../ImportExport/RolesRecipeHandler.cs | 37 +++++++++++-------- 11 files changed, 145 insertions(+), 82 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/CommandRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/CommandRecipeHandler.cs index 27dd48c4f..ee3fdae68 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/CommandRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/CommandRecipeHandler.cs @@ -37,6 +37,8 @@ namespace Orchard.Recipes.RecipeHandlers { return; } + Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId); + var commands = recipeContext.RecipeStep.Step.Value .Split(new[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries) @@ -44,18 +46,22 @@ namespace Orchard.Recipes.RecipeHandlers { foreach (var command in commands) { if (!String.IsNullOrEmpty(command)) { - if (!String.IsNullOrEmpty(recipeContext.ExecutionId)) { - // TODO: ************** LOGGING - //_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, T("Commands: Executing item {0}.", command).Text); + Logger.Information("Executing command: {0}", command); + try { + var commandParameters = _commandParser.ParseCommandParameters(command); + var input = new StringReader(""); + var output = new StringWriter(); + _commandManager.Execute(new CommandParameters { Arguments = commandParameters.Arguments, Input = input, Output = output, Switches = commandParameters.Switches }); + } + catch (Exception ex) { + Logger.Error(ex, "Error while executing command: {0}", command); + throw; } - var commandParameters = _commandParser.ParseCommandParameters(command); - var input = new StringReader(""); - var output = new StringWriter(); - _commandManager.Execute(new CommandParameters { Arguments = commandParameters.Arguments, Input = input, Output = output, Switches = commandParameters.Switches }); } } recipeContext.Executed = true; + Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name); } } diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/DataRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/DataRecipeHandler.cs index b65957198..c2b49096c 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/DataRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/DataRecipeHandler.cs @@ -30,6 +30,8 @@ namespace Orchard.Recipes.RecipeHandlers { return; } + Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId); + var importContentSession = new ImportContentSession(_orchardServices.ContentManager); // Populate local dictionary with elements and their ids @@ -43,24 +45,32 @@ namespace Orchard.Recipes.RecipeHandlers { //Determine if the import is to be batched in multiple transactions var startIndex = 0; int batchSize = GetBatchSizeForDataStep(recipeContext.RecipeStep.Step); + Logger.Debug("Using batch size {0}.", batchSize); //Run the import try { while (startIndex < elementDictionary.Count) { + Logger.Debug("Importing batch starting at index {0}.", startIndex); importContentSession.InitializeBatch(startIndex, batchSize); //the session determines which items are included in the current batch //so that dependencies can be managed within the same transaction var nextIdentity = importContentSession.GetNextInBatch(); while (nextIdentity != null) { - if (!string.IsNullOrEmpty(recipeContext.ExecutionId) && elementDictionary[nextIdentity.ToString()].HasAttributes) { - var itemId = elementDictionary[nextIdentity.ToString()].FirstAttribute.Value; - // TODO: ************** LOGGING - //_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, T("Data: Importing {0}.", itemId).Text); + var itemId = ""; + if (elementDictionary[nextIdentity.ToString()].HasAttributes) { + itemId = elementDictionary[nextIdentity.ToString()].FirstAttribute.Value; + } + Logger.Information("Importing data item '{0}'.", itemId); + try { + _orchardServices.ContentManager.Import( + elementDictionary[nextIdentity.ToString()], + importContentSession); + } + catch (Exception ex) { + Logger.Error(ex, "Error while importing data item '{0}'.", itemId); + throw; } - _orchardServices.ContentManager.Import( - elementDictionary[nextIdentity.ToString()], - importContentSession); nextIdentity = importContentSession.GetNextInBatch(); } @@ -70,6 +80,8 @@ namespace Orchard.Recipes.RecipeHandlers { if (startIndex < elementDictionary.Count) { _transactionManager.RequireNew(); } + + Logger.Debug("Finished importing batch starting at index {0}.", startIndex); } } catch (Exception) { @@ -79,6 +91,7 @@ namespace Orchard.Recipes.RecipeHandlers { } recipeContext.Executed = true; + Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name); } private Dictionary CreateElementDictionary(XElement step) { diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/FeatureRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/FeatureRecipeHandler.cs index e68837c33..8da5b4137 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/FeatureRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/FeatureRecipeHandler.cs @@ -27,6 +27,8 @@ namespace Orchard.Recipes.RecipeHandlers { return; } + Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId); + var featuresToEnable = new List(); var featuresToDisable = new List(); foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) { @@ -37,7 +39,7 @@ namespace Orchard.Recipes.RecipeHandlers { featuresToEnable = ParseFeatures(attribute.Value); } else { - Logger.Error("Unrecognized attribute {0} encountered in step Feature. Skipping.", attribute.Name.LocalName); + Logger.Warning("Unrecognized attribute '{0}' encountered; skipping", attribute.Name.LocalName); } } @@ -54,14 +56,17 @@ namespace Orchard.Recipes.RecipeHandlers { } } - if (featuresToDisable.Count != 0) { + if (featuresToDisable.Any()) { + Logger.Information("Disabling features: {0}", String.Join(";", featuresToDisable)); _featureManager.DisableFeatures(featuresToDisable, true); } - if (featuresToEnable.Count != 0) { + if (featuresToEnable.Any()) { + Logger.Information("Enabling features: {0}", String.Join(";", featuresToEnable)); _featureManager.EnableFeatures(featuresToEnable, true); } recipeContext.Executed = true; + Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name); } private static List ParseFeatures(string csv) { diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/MetaDataRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/MetaDataRecipeHandler.cs index a6fe02382..db412c6fb 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/MetaDataRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/MetaDataRecipeHandler.cs @@ -46,36 +46,55 @@ namespace Orchard.Recipes.RecipeHandlers { return; } + Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId); + foreach (var metadataElement in recipeContext.RecipeStep.Step.Elements()) { + Logger.Debug("Processing element '{0}'.", metadataElement.Name.LocalName); switch (metadataElement.Name.LocalName) { case "Types": foreach (var element in metadataElement.Elements()) { var typeElement = element; var typeName = XmlConvert.DecodeName(element.Name.LocalName); - _contentDefinitonEventHandlers.ContentTypeImporting(new ContentTypeImportingContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName), ContentTypeName = typeName }); - _contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration)); - _contentDefinitonEventHandlers.ContentTypeImported(new ContentTypeImportedContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName) }); + Logger.Information("Importing content type '{0}'.", typeName); + try { + _contentDefinitonEventHandlers.ContentTypeImporting(new ContentTypeImportingContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName), ContentTypeName = typeName }); + _contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration)); + _contentDefinitonEventHandlers.ContentTypeImported(new ContentTypeImportedContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName) }); + } + catch (Exception ex) { + Logger.Error(ex, "Error while importing content type '{0}'.", typeName); + throw; + } } break; + case "Parts": - // create dynamic part. foreach (var element in metadataElement.Elements()) { var partElement = element; var partName = XmlConvert.DecodeName(element.Name.LocalName); - - _contentDefinitonEventHandlers.ContentPartImporting(new ContentPartImportingContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName), ContentPartName = partName }); + + Logger.Information("Importing content part '{0}'.", partName); + try { + _contentDefinitonEventHandlers.ContentPartImporting(new ContentPartImportingContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName), ContentPartName = partName }); _contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration)); _contentDefinitonEventHandlers.ContentPartImported(new ContentPartImportedContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName)}); + } + catch (Exception ex) { + Logger.Error(ex, "Error while importing content part '{0}'.", partName); + throw; + } } break; + default: - Logger.Error("Unrecognized element {0} encountered in step Metadata. Skipping.", metadataElement.Name.LocalName); + Logger.Warning("Unrecognized element '{0}' encountered; skipping", metadataElement.Name.LocalName); break; } } recipeContext.Executed = true; + Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/MigrationRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/MigrationRecipeHandler.cs index 281e6c85d..54c9110c5 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/MigrationRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/MigrationRecipeHandler.cs @@ -28,6 +28,8 @@ namespace Orchard.Recipes.RecipeHandlers { return; } + Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId); + bool runAll = false; var features = new List(); foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) { @@ -37,21 +39,35 @@ namespace Orchard.Recipes.RecipeHandlers { runAll = true; } else { - Logger.Error("Unrecognized attribute {0} encountered in step Migration. Skipping.", attribute.Name.LocalName); + Logger.Warning("Unrecognized attribute '{0}' encountered; skipping.", attribute.Name.LocalName); } } if (runAll) { foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate()) { - _dataMigrationManager.Update(feature); + Logger.Information("Updating feature '{0}'.", feature); + try { + _dataMigrationManager.Update(feature); + } + catch (Exception ex) { + Logger.Error(ex, "Error while updating feature '{0}'", feature); + throw; + } } } else { - _dataMigrationManager.Update(features); + Logger.Information("Updating features: {0}", String.Join(";", features)); + try { + _dataMigrationManager.Update(features); + } + catch (Exception ex) { + Logger.Error(ex, "Error while updating features: {0}", String.Join(";", features)); + throw; + } } - // run migrations recipeContext.Executed = true; + Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name); } private static List ParseFeatures(string csv) { diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ModuleRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ModuleRecipeHandler.cs index 7fca74b32..f0ad6db5b 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ModuleRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ModuleRecipeHandler.cs @@ -37,8 +37,10 @@ namespace Orchard.Recipes.RecipeHandlers { if (!String.Equals(recipeContext.RecipeStep.Name, "Module", StringComparison.OrdinalIgnoreCase)) { return; } - string packageId = null, version = null, repository = null; + Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId); + + string packageId = null, version = null, repository = null; foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) { if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase)) { packageId = attribute.Value; @@ -85,10 +87,7 @@ namespace Orchard.Recipes.RecipeHandlers { if (packagingEntry != null) { if (!ModuleAlreadyInstalled(packagingEntry.PackageId)) { - if (!string.IsNullOrEmpty(recipeContext.ExecutionId)) { - // TODO: ************** LOGGING - //_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, T("Installing module: {0}.", packagingEntry.Title).Text); - } + Logger.Information("Installing module {0}.", packagingEntry.Title); _packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/")); } installed = true; @@ -99,6 +98,7 @@ namespace Orchard.Recipes.RecipeHandlers { } recipeContext.Executed = true; + Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name); } private bool ModuleAlreadyInstalled(string packageId) { diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/SettingsRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/SettingsRecipeHandler.cs index 5e02c08f5..2c6a4f7aa 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/SettingsRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/SettingsRecipeHandler.cs @@ -39,6 +39,8 @@ namespace Orchard.Recipes.RecipeHandlers { return; } + Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId); + var siteContentItem = _siteService.GetSiteSettings().ContentItem; var importContentSession = new ImportContentSession(_contentManager); @@ -54,12 +56,14 @@ namespace Orchard.Recipes.RecipeHandlers { continue; } - if (!string.IsNullOrEmpty(recipeContext.ExecutionId)) { - // TODO: ************** LOGGING - //_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, T("Setting: {0}.", contentPart.PartDefinition.Name).Text); + Logger.Information("Importing settings part '{0}'.", contentPart.PartDefinition.Name); + try { + ImportSettingPart(contentPart, partElement); + } + catch (Exception ex) { + Logger.Error(ex, "Error while importing settings part '{0}'.", contentPart.PartDefinition.Name); + throw; } - - ImportSettingPart(contentPart, partElement); } foreach (var contentHandler in Handlers) { @@ -67,6 +71,7 @@ namespace Orchard.Recipes.RecipeHandlers { } recipeContext.Executed = true; + Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name); } private void ImportSettingPart(ContentPart sitePart, XElement element) { diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ThemeRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ThemeRecipeHandler.cs index 1d4673ca3..59a51dcc8 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ThemeRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ThemeRecipeHandler.cs @@ -46,6 +46,8 @@ namespace Orchard.Recipes.RecipeHandlers { return; } + Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId); + bool enable = false, current = false; string packageId = null, version = null, repository = null; @@ -66,12 +68,12 @@ namespace Orchard.Recipes.RecipeHandlers { repository = attribute.Value; } else { - Logger.Error("Unrecognized attribute {0} encountered in step Theme. Skipping.", attribute.Name.LocalName); + Logger.Warning("Unrecognized attribute '{0}' encountered; skipping.", attribute.Name.LocalName); } } if (packageId == null) { - throw new InvalidOperationException("PackageId is required in a Theme declaration in a recipe file."); + throw new InvalidOperationException("The PackageId attribute is required on a Theme declaration in a recipe file."); } // download and install theme from the orchard feed or a custom feed if repository is specified. @@ -101,13 +103,17 @@ namespace Orchard.Recipes.RecipeHandlers { if (packagingEntry != null) { if (!ThemeAlreadyInstalled(packagingEntry.PackageId)) { + Logger.Information("Installing theme package '{0}'.", packagingEntry.PackageId); _packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/")); } if (current) { + Logger.Information("Enabling theme '{0}'.", packagingEntry.Title); _themeService.EnableThemeFeatures(packagingEntry.Title); + Logger.Information("Setting theme '{0}' as the site theme.", packagingEntry.Title); _siteThemeService.SetSiteTheme(packagingEntry.Title); } else if (enable) { + Logger.Information("Enabling theme '{0}'.", packagingEntry.Title); _themeService.EnableThemeFeatures(packagingEntry.Title); } @@ -115,10 +121,11 @@ namespace Orchard.Recipes.RecipeHandlers { } if (!installed) { - throw new InvalidOperationException(string.Format("Theme {0} was not found in the specified location.", packageId)); + throw new InvalidOperationException(string.Format("Theme '{0}' was not found in the specified location.", packageId)); } recipeContext.Executed = true; + Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name); } private bool ThemeAlreadyInstalled(string packageId) { diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/Services/RecipeManager.cs b/src/Orchard.Web/Modules/Orchard.Recipes/Services/RecipeManager.cs index 459877922..492fc5183 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/Services/RecipeManager.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/Services/RecipeManager.cs @@ -30,8 +30,7 @@ namespace Orchard.Recipes.Services { return null; var executionId = Guid.NewGuid().ToString("n"); - // TODO: ************** LOGGING - //_recipeJournal.ExecutionStart(executionId); + Logger.Information("Executing recipe '{0}' using ExecutionId {1}.", recipe.Name, executionId); _recipeExecuteEventHandler.ExecutionStart(executionId, recipe); foreach (var recipeStep in recipe.RecipeSteps) { diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/Services/RecipeStepExecutor.cs b/src/Orchard.Web/Modules/Orchard.Recipes/Services/RecipeStepExecutor.cs index 6ab0e0467..f733d2a8a 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/Services/RecipeStepExecutor.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/Services/RecipeStepExecutor.cs @@ -27,15 +27,13 @@ namespace Orchard.Recipes.Services { public ILogger Logger { get; set; } public bool ExecuteNextStep(string executionId) { - var nextRecipeStep= _recipeStepQueue.Dequeue(executionId); + var nextRecipeStep = _recipeStepQueue.Dequeue(executionId); if (nextRecipeStep == null) { - // TODO: ************** LOGGING - //_recipeJournal.ExecutionComplete(executionId); + Logger.Information("Recipe execution {0} completed.", executionId); _recipeExecuteEventHandler.ExecutionComplete(executionId); return false; } - // TODO: ************** LOGGING - //_recipeJournal.WriteJournalEntry(executionId, string.Format("Executing step {0}.", nextRecipeStep.Name)); + Logger.Information("Running all recipe handlers for step '{0}'.", nextRecipeStep.Name); var recipeContext = new RecipeContext { RecipeStep = nextRecipeStep, Executed = false, ExecutionId = executionId }; try { _recipeExecuteEventHandler.RecipeStepExecuting(executionId, recipeContext); @@ -44,29 +42,17 @@ namespace Orchard.Recipes.Services { } _recipeExecuteEventHandler.RecipeStepExecuted(executionId, recipeContext); } - catch(Exception exception) { - Logger.Error(exception, "Recipe execution {0} was cancelled because a step failed to execute", executionId); - while (_recipeStepQueue.Dequeue(executionId) != null) ; - // TODO: ************** LOGGING - //_recipeJournal.ExecutionFailed(executionId); - var message = T("Recipe execution with id {0} was cancelled because the \"{1}\" step failed to execute. The following exception was thrown: {2}. Refer to the error logs for more information.", - executionId, nextRecipeStep.Name, exception.Message); - // TODO: ************** LOGGING - //_recipeJournal.WriteJournalEntry(executionId, message.ToString()); - + catch (Exception exception) { + Logger.Error(exception, "Recipe execution {0} failed because the step '{1}' failed.", executionId, nextRecipeStep.Name); + while (_recipeStepQueue.Dequeue(executionId) != null); + var message = T("Recipe execution with ID {0} failed because the step '{1}' failed to execute. The following exception was thrown:\n{2}\nRefer to the error logs for more information.", executionId, nextRecipeStep.Name, exception.Message); throw new OrchardCoreException(message); } if (!recipeContext.Executed) { - Logger.Error("Could not execute recipe step '{0}' because the recipe handler was not found.", recipeContext.RecipeStep.Name); - while (_recipeStepQueue.Dequeue(executionId) != null) ; - // TODO: ************** LOGGING - //_recipeJournal.ExecutionFailed(executionId); - var message = T("Recipe execution with id {0} was cancelled because the recipe handler for step \"{1}\" was not found. Refer to the error logs for more information.", - executionId, nextRecipeStep.Name); - // TODO: ************** LOGGING - //_recipeJournal.WriteJournalEntry(executionId, message.ToString()); - + Logger.Error("Recipe execution {0} failed because no matching handler for recipe step '{1}' was found.", executionId, recipeContext.RecipeStep.Name); + while (_recipeStepQueue.Dequeue(executionId) != null); + var message = T("Recipe execution with ID {0} failed because no matching handler for recipe step '{1}' was found. Refer to the error logs for more information.", executionId, nextRecipeStep.Name); throw new OrchardCoreException(message); } diff --git a/src/Orchard.Web/Modules/Orchard.Roles/ImportExport/RolesRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Roles/ImportExport/RolesRecipeHandler.cs index 6db2d1726..16b82cbad 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/ImportExport/RolesRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/ImportExport/RolesRecipeHandler.cs @@ -33,30 +33,37 @@ namespace Orchard.Roles.ImportExport { return; } + Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId); + var installedPermissions = _roleService.GetInstalledPermissions().SelectMany(p => p.Value).ToList(); foreach (var roleElement in recipeContext.RecipeStep.Step.Elements()) { var roleName = roleElement.Attribute("Name").Value; - if (string.IsNullOrEmpty(recipeContext.ExecutionId)) { - // TODO: ************** LOGGING - //_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, T("Roles: Executing item {0}.", roleName).Text); + Logger.Information("Processing role '{0}'.", roleName); + + try { + var role = _roleService.GetRoleByName(roleName); + if (role == null) { + _roleService.CreateRole(roleName); + role = _roleService.GetRoleByName(roleName); + } + + var permissions = roleElement.Attribute("Permissions").Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + // only import permissions for currenlty installed modules + var permissionsValid = permissions.Where(permission => installedPermissions.Any(x => x.Name == permission)).ToList(); + + // union to keep existing permissions + _roleService.UpdateRole(role.Id, role.Name, permissionsValid.Union(role.RolesPermissions.Select(p => p.Permission.Name))); } - - var role = _roleService.GetRoleByName(roleName); - if (role == null) { - _roleService.CreateRole(roleName); - role = _roleService.GetRoleByName(roleName); + catch (Exception ex) { + Logger.Error(ex, "Error while processing role '{0}'.", roleName); + throw; } - - var permissions = roleElement.Attribute("Permissions").Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - // only import permissions for currenlty installed modules - var permissionsValid = permissions.Where(permission => installedPermissions.Any(x => x.Name == permission)).ToList(); - - // union to keep existing permissions - _roleService.UpdateRole(role.Id, role.Name, permissionsValid.Union(role.RolesPermissions.Select(p => p.Permission.Name))); } + recipeContext.Executed = true; + Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name); } } } \ No newline at end of file