mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added "recipes result" command to print result of a recipe execution.
This helps in automation scenarios where you need to programmatically find out whether setup succeeded or not. Also clarified "setup" command output and added execution ID to the message and cleaned up code in RecipeCommands.
This commit is contained in:
@@ -12,25 +12,31 @@ namespace Orchard.Recipes.Commands {
|
|||||||
private readonly IRecipeHarvester _recipeHarvester;
|
private readonly IRecipeHarvester _recipeHarvester;
|
||||||
private readonly IRecipeManager _recipeManager;
|
private readonly IRecipeManager _recipeManager;
|
||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IExtensionManager _extensionManager;
|
||||||
|
private readonly IRecipeResultAccessor _recipeResultAccessor;
|
||||||
|
|
||||||
public RecipesCommands(IRecipeHarvester recipeHarvester, IRecipeManager recipeManager, IExtensionManager extensionManager) {
|
public RecipesCommands(
|
||||||
|
IRecipeHarvester recipeHarvester,
|
||||||
|
IRecipeManager recipeManager,
|
||||||
|
IExtensionManager extensionManager,
|
||||||
|
IRecipeResultAccessor recipeResultAccessor) {
|
||||||
_recipeHarvester = recipeHarvester;
|
_recipeHarvester = recipeHarvester;
|
||||||
_recipeManager = recipeManager;
|
_recipeManager = recipeManager;
|
||||||
_extensionManager = extensionManager;
|
_extensionManager = extensionManager;
|
||||||
|
_recipeResultAccessor = recipeResultAccessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
[CommandHelp("recipes harvest <extension-id>\r\n\t" + "Display list of available recipes for an extension")]
|
[CommandHelp("recipes harvest <extensionId>\r\n\t" + "Displays a list of available recipes for a specific extension.")]
|
||||||
[CommandName("recipes harvest")]
|
[CommandName("recipes harvest")]
|
||||||
public void HarvestRecipes(string extensionId) {
|
public void Harvest(string extensionId) {
|
||||||
ExtensionDescriptor extensionDescriptor = _extensionManager.GetExtension(extensionId);
|
var extensionDescriptor = _extensionManager.GetExtension(extensionId);
|
||||||
if (extensionDescriptor == null) {
|
if (extensionDescriptor == null) {
|
||||||
Context.Output.WriteLine(T("Could not discover recipes because module '{0}' was not found.", extensionId));
|
Context.Output.WriteLine(T("Could not discover recipes because extension '{0}' was not found.", extensionId));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Recipe> recipes = _recipeHarvester.HarvestRecipes(extensionId);
|
var recipes = _recipeHarvester.HarvestRecipes(extensionId);
|
||||||
if (recipes.Count() == 0) {
|
if (recipes.Count() == 0) {
|
||||||
Context.Output.WriteLine(T("No recipes found for extension {0}.", extensionId));
|
Context.Output.WriteLine(T("No recipes found for extension '{0}'.", extensionId));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +44,7 @@ namespace Orchard.Recipes.Commands {
|
|||||||
Context.Output.WriteLine(T("--------------------------"));
|
Context.Output.WriteLine(T("--------------------------"));
|
||||||
Context.Output.WriteLine();
|
Context.Output.WriteLine();
|
||||||
|
|
||||||
foreach (Recipe recipe in recipes) {
|
foreach (var recipe in recipes) {
|
||||||
Context.Output.WriteLine(T("Recipe: {0}", recipe.Name));
|
Context.Output.WriteLine(T("Recipe: {0}", recipe.Name));
|
||||||
Context.Output.WriteLine(T(" Version: {0}", recipe.Version));
|
Context.Output.WriteLine(T(" Version: {0}", recipe.Version));
|
||||||
Context.Output.WriteLine(T(" Tags: {0}", recipe.Tags));
|
Context.Output.WriteLine(T(" Tags: {0}", recipe.Tags));
|
||||||
@@ -48,29 +54,49 @@ namespace Orchard.Recipes.Commands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[CommandHelp("recipes execute <extension-id> <recipe-name>\r\n\t" + "Executes a recipe from a module")]
|
[CommandHelp("recipes execute <extensionId> <recipe>\r\n\t" + "Executes a specific recipe for a specific extension.")]
|
||||||
[CommandName("recipes execute")]
|
[CommandName("recipes execute")]
|
||||||
public void ExecuteRecipe(string extensionId, string recipeName) {
|
public void Execute(string extensionId, string recipeName) {
|
||||||
ExtensionDescriptor extensionDescriptor = _extensionManager.GetExtension(extensionId);
|
var extensionDescriptor = _extensionManager.GetExtension(extensionId);
|
||||||
if (extensionDescriptor == null) {
|
if (extensionDescriptor == null) {
|
||||||
Context.Output.WriteLine(T("Could not discover recipes because module '{0}' was not found.", extensionId));
|
Context.Output.WriteLine(T("Could not discover recipes because extension '{0}' was not found.", extensionId));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Recipe> recipes = _recipeHarvester.HarvestRecipes(extensionId);
|
var recipes = _recipeHarvester.HarvestRecipes(extensionId);
|
||||||
if (recipes.Count() == 0) {
|
if (!recipes.Any()) {
|
||||||
Context.Output.WriteLine(T("No recipes found for extension {0}.", extensionId));
|
Context.Output.WriteLine(T("No recipes found for extension '{0}'.", extensionId));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipe recipe = recipes.FirstOrDefault(r => r.Name.Equals(recipeName, StringComparison.OrdinalIgnoreCase));
|
var recipe = recipes.FirstOrDefault(r => r.Name.Equals(recipeName, StringComparison.OrdinalIgnoreCase));
|
||||||
if (recipe == null) {
|
if (recipe == null) {
|
||||||
Context.Output.WriteLine(T("Invalid recipe name {0}.", recipeName));
|
Context.Output.WriteLine(T("No recipe with name '{0}' was found in extension '{1}'.", recipeName, extensionId));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_recipeManager.Execute(recipe);
|
var executionId = _recipeManager.Execute(recipe);
|
||||||
Context.Output.WriteLine(T("Recipe scheduled for execution successfully.").Text);
|
Context.Output.WriteLine(T("Recipe successfully scheduled with execution ID {0}. Use the 'recipes result' command to check the result of the execution.", executionId).Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
[CommandHelp("recipes result <executionId>\r\n\t" + "Prints the status/result of a specific recipe execution.")]
|
||||||
|
[CommandName("recipes result")]
|
||||||
|
public void Result(string executionId) {
|
||||||
|
var result = _recipeResultAccessor.GetResult(executionId);
|
||||||
|
|
||||||
|
Context.Output.WriteLine(T("Result of recipe execution:"));
|
||||||
|
Context.Output.WriteLine(T("---------------------------"));
|
||||||
|
Context.Output.WriteLine(T(" Execution ID: {0}", executionId));
|
||||||
|
Context.Output.WriteLine(T(" Completed: {0}", result.IsCompleted));
|
||||||
|
Context.Output.WriteLine(T(" Successful: {0}", result.IsSuccessful));
|
||||||
|
|
||||||
|
foreach (var step in result.Steps) {
|
||||||
|
Context.Output.WriteLine(T(" Step: {0}", step.StepName));
|
||||||
|
Context.Output.WriteLine(T(" Completed: {0}", step.IsCompleted));
|
||||||
|
Context.Output.WriteLine(T(" Successful: {0}", step.IsSuccessful));
|
||||||
|
if (!String.IsNullOrEmpty(step.ErrorMessage))
|
||||||
|
Context.Output.WriteLine(T(" Error message: {0}", step.ErrorMessage));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,16 +39,16 @@ namespace Orchard.Setup.Commands {
|
|||||||
[CommandHelp("setup /SiteName:<siteName> /AdminUsername:<username> /AdminPassword:<password> /DatabaseProvider:<SqlCe|SQLServer|MySql|PostgreSql> " +
|
[CommandHelp("setup /SiteName:<siteName> /AdminUsername:<username> /AdminPassword:<password> /DatabaseProvider:<SqlCe|SQLServer|MySql|PostgreSql> " +
|
||||||
"/DatabaseConnectionString:<connection_string> /DatabaseTablePrefix:<table_prefix> /EnabledFeatures:<feature1,feature2,...> " +
|
"/DatabaseConnectionString:<connection_string> /DatabaseTablePrefix:<table_prefix> /EnabledFeatures:<feature1,feature2,...> " +
|
||||||
"/Recipe:<recipe>" +
|
"/Recipe:<recipe>" +
|
||||||
"\r\n\tRun first time setup for the site or for a given tenant")]
|
"\r\n\tRuns first time setup for the site or for a given tenant.")]
|
||||||
[CommandName("setup")]
|
[CommandName("setup")]
|
||||||
[OrchardSwitches("SiteName,AdminUsername,AdminPassword,DatabaseProvider,DatabaseConnectionString,DatabaseTablePrefix,EnabledFeatures,Recipe")]
|
[OrchardSwitches("SiteName,AdminUsername,AdminPassword,DatabaseProvider,DatabaseConnectionString,DatabaseTablePrefix,EnabledFeatures,Recipe")]
|
||||||
public void Setup() {
|
public void Setup() {
|
||||||
IEnumerable<string> enabledFeatures = null;
|
IEnumerable<string> enabledFeatures = null;
|
||||||
if (!string.IsNullOrEmpty(EnabledFeatures)) {
|
if (!String.IsNullOrEmpty(EnabledFeatures)) {
|
||||||
enabledFeatures = EnabledFeatures
|
enabledFeatures = EnabledFeatures
|
||||||
.Split(',')
|
.Split(',')
|
||||||
.Select(s => s.Trim())
|
.Select(s => s.Trim())
|
||||||
.Where(s => !string.IsNullOrEmpty(s));
|
.Where(s => !String.IsNullOrEmpty(s));
|
||||||
}
|
}
|
||||||
Recipe = String.IsNullOrEmpty(Recipe) ? "Default" : Recipe;
|
Recipe = String.IsNullOrEmpty(Recipe) ? "Default" : Recipe;
|
||||||
|
|
||||||
@@ -63,13 +63,9 @@ namespace Orchard.Setup.Commands {
|
|||||||
Recipe = Recipe,
|
Recipe = Recipe,
|
||||||
};
|
};
|
||||||
|
|
||||||
_setupService.Setup(setupContext);
|
var executionId = _setupService.Setup(setupContext);
|
||||||
|
|
||||||
Context.Output.WriteLine(T("Site \"{0}\" successfully setup to run data provider \"{1}\" (with table prefix \"{2}\") and configured by recipe \"{3}\"",
|
Context.Output.WriteLine(T("Setup of site '{0}' was started with recipe execution ID {1}. Use the 'recipes result' command to check the result of the execution.", setupContext.SiteName, executionId));
|
||||||
setupContext.SiteName,
|
|
||||||
setupContext.DatabaseProvider,
|
|
||||||
setupContext.DatabaseTablePrefix,
|
|
||||||
setupContext.Recipe));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user