Implementation of feature handler for recipes: provides disabling/enabling of features.

--HG--
branch : recipe
This commit is contained in:
Suha Can
2011-02-17 17:13:44 -08:00
parent 06f5898d72
commit f6579c7540
3 changed files with 34 additions and 6 deletions

View File

@@ -75,6 +75,10 @@
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
<Name>Orchard.Framework</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Modules\Orchard.Modules.csproj">
<Project>{17F86780-9A1F-4AA1-86F1-875EEC2730C7}</Project>
<Name>Orchard.Modules</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

View File

@@ -1,14 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Environment.Features;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Modules.Services;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
namespace Orchard.Recipes.RecipeHandlers {
public class FeatureRecipeHandler : IRecipeHandler {
public FeatureRecipeHandler() {
private readonly IFeatureManager _featureManager;
private readonly IModuleService _moduleService;
public FeatureRecipeHandler(IFeatureManager featureManager, IModuleService moduleService) {
_featureManager = featureManager;
_moduleService = moduleService;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
@@ -37,9 +44,25 @@ namespace Orchard.Recipes.RecipeHandlers {
}
}
// if both, tx and disable happens first.
// force cascading enabling and disabling.
// run migrations.
var availableFeatures = _featureManager.GetAvailableFeatures().Select(x => x.Id).ToArray();
foreach (var featureName in featuresToDisable) {
if (!availableFeatures.Contains(featureName)) {
throw new InvalidOperationException(string.Format("Could not disable feature {0} because it was not found.", featureName));
}
}
foreach (var featureName in featuresToEnable) {
if (!availableFeatures.Contains(featureName)) {
throw new InvalidOperationException(string.Format("Could not enable feature {0} because it was not found.", featureName));
}
}
if (featuresToDisable.Count != 0) {
_moduleService.DisableFeatures(featuresToDisable, true);
}
if (featuresToEnable.Count != 0) {
_moduleService.EnableFeatures(featuresToEnable, true);
}
recipeContext.Executed = true;
}

View File

@@ -9,6 +9,8 @@
<Version>1.0</Version>
</Recipe>
<Feature disable="Orchard.Media" enable="Orchard.Experimental" />
<Metadata>
<Types>
<Page ContentTypeSettings.Draftable="True" TypeIndexing.Included="true">
@@ -27,9 +29,8 @@
</Metadata>
<Command>
feature enable Orchard.Experimental
feature enable Orchard.Experimental.TestingLists
</Command>
<Migration features="Orchard.Experimental.TestingLists" />
<Migration features="*" />
</Orchard>