mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
Cleanup and refactor module/theme recipe step handler code.
--HG-- branch : recipe
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
</Recipe>
|
||||
|
||||
<!-- Steps -->
|
||||
<Module src="http://" replace="false" />
|
||||
<Module name="module1" repository="somerepo" version="1.1" replace="true" />
|
||||
|
||||
<Feature disable="f1, f2" enable="f3,f4" />
|
||||
@@ -38,7 +37,6 @@
|
||||
|
||||
<Migration features="f2,f4"/>
|
||||
|
||||
<Theme src="http://" enable="true" current="true" />
|
||||
<Theme name="theme1" repository="somerepo" replace="true" />
|
||||
|
||||
<Custom1 attr1="value1" />
|
||||
|
@@ -125,7 +125,7 @@ namespace Orchard.Tests.Modules.Recipes.Services {
|
||||
var sampleRecipe = recipes[0];
|
||||
var recipeSteps = (List<RecipeStep>) sampleRecipe.RecipeSteps;
|
||||
|
||||
Assert.That(recipeSteps.Count, Is.EqualTo(11));
|
||||
Assert.That(recipeSteps.Count, Is.EqualTo(9));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@@ -38,22 +38,18 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
public Localizer T { get; set; }
|
||||
ILogger Logger { get; set; }
|
||||
|
||||
// <Module src="http://" replace="false" />
|
||||
// <Module name="module1" [repository="somerepo"] version="1.1" replace="true" />
|
||||
// install modules from url or feed.
|
||||
// <Module name="module1" [repository="somerepo"] version="1.1" replace="false" />
|
||||
// install modules from feed.
|
||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Module", StringComparison.OrdinalIgnoreCase)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool replace;
|
||||
string source = null, name = null, version = null, repository = null;
|
||||
string name = null, version = null, repository = null;
|
||||
|
||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "src", StringComparison.OrdinalIgnoreCase)) {
|
||||
source = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
|
||||
if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
|
||||
replace = Boolean.Parse(attribute.Value);
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "name", StringComparison.OrdinalIgnoreCase)) {
|
||||
@@ -70,11 +66,8 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
}
|
||||
}
|
||||
|
||||
if (source != null) {
|
||||
}
|
||||
else {
|
||||
if (name == null) {
|
||||
throw new InvalidOperationException("Either name or source is required in a Module declaration in a recipe file.");
|
||||
throw new InvalidOperationException("Name is required in a Module declaration in a recipe file.");
|
||||
}
|
||||
// download and install module from the orchard feed or a custom feed if repository is specified.
|
||||
bool enforceVersion = version != null;
|
||||
@@ -100,7 +93,6 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
||||
_moduleService.EnableFeatures(new[] { packagingEntry.Title }, true);
|
||||
_dataMigrationManager.Update(packagingEntry.Title);
|
||||
|
||||
installed = true;
|
||||
break;
|
||||
}
|
||||
@@ -110,7 +102,6 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
throw new InvalidOperationException(string.Format("Module {0} was not found in the specified location.", name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
recipeContext.Executed = true;
|
||||
}
|
||||
|
@@ -37,22 +37,18 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
public Localizer T { get; set; }
|
||||
ILogger Logger { get; set; }
|
||||
|
||||
// <Theme src="http://" enable="true" current="true />
|
||||
// <Theme name="theme1" repository="somethemerepo" version="1.1" replace="true" />
|
||||
// install themes from url or feed.
|
||||
// <Theme name="theme1" repository="somethemerepo" version="1.1" enable="true" current="true" replace="false" />
|
||||
// install themes from feed.
|
||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool replace, enable = false, current = false;
|
||||
string source = null, name = null, version = null, repository = null;
|
||||
string name = null, version = null, repository = null;
|
||||
|
||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "src", StringComparison.OrdinalIgnoreCase)) {
|
||||
source = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
|
||||
if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
|
||||
replace = Boolean.Parse(attribute.Value);
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
||||
@@ -75,11 +71,8 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
}
|
||||
}
|
||||
|
||||
if (source != null) {
|
||||
}
|
||||
else {
|
||||
if (name == null) {
|
||||
throw new InvalidOperationException("Either name or source is required in a Theme declaration in a recipe file.");
|
||||
throw new InvalidOperationException("Name is required in a Theme declaration in a recipe file.");
|
||||
}
|
||||
// download and install theme from the orchard feed or a custom feed if repository is specified.
|
||||
bool enforceVersion = version != null;
|
||||
@@ -103,12 +96,13 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
themeExists = true;
|
||||
}
|
||||
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
||||
if (enable) {
|
||||
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
||||
}
|
||||
if (current) {
|
||||
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
||||
_siteThemeService.SetSiteTheme(packagingEntry.Title);
|
||||
}
|
||||
else if (enable) {
|
||||
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
||||
}
|
||||
|
||||
installed = true;
|
||||
break;
|
||||
@@ -119,8 +113,6 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
throw new InvalidOperationException(string.Format("Theme {0} was not found in the specified location.", name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
recipeContext.Executed = true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user