diff --git a/src/Orchard/Data/Migration/AutomaticDataMigrations.cs b/src/Orchard/Data/Migration/AutomaticDataMigrations.cs index 87d6a81ee..f3f537619 100644 --- a/src/Orchard/Data/Migration/AutomaticDataMigrations.cs +++ b/src/Orchard/Data/Migration/AutomaticDataMigrations.cs @@ -1,8 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Orchard.Environment; +using Orchard.Environment.Features; using Orchard.Logging; namespace Orchard.Data.Migration { @@ -11,9 +10,14 @@ namespace Orchard.Data.Migration { /// public class AutomaticDataMigrations : IOrchardShellEvents { private readonly IDataMigrationManager _dataMigrationManager; + private readonly IFeatureManager _featureManager; - public AutomaticDataMigrations(IDataMigrationManager dataMigrationManager) { + public AutomaticDataMigrations( + IDataMigrationManager dataMigrationManager, + IFeatureManager featureManager + ) { _dataMigrationManager = dataMigrationManager; + _featureManager = featureManager; Logger = NullLogger.Instance; } @@ -21,6 +25,18 @@ namespace Orchard.Data.Migration { public ILogger Logger { get; set; } public void Activated() { + + // Let's make sure that the basic set of features is enabled. If there are any that are not enabled, then let's enable them first. + var theseFeaturesShouldAlwaysBeActive = new[] { + "Common", "Containers", "Contents", "Dashboard", "Feeds", "Navigation", "Reports", "Scheduling", "Settings", "Shapes", "Title" + }; + + var enabledFeatures = _featureManager.GetEnabledFeatures().Select(f => f.Id).ToList(); + var featuresToEnable = theseFeaturesShouldAlwaysBeActive.Where(shouldBeActive => !enabledFeatures.Contains(shouldBeActive)).ToList(); + if (featuresToEnable.Any()) { + _featureManager.EnableFeatures(featuresToEnable); + } + foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate()) { try { _dataMigrationManager.Update(feature);