public ActionResult Features()
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
            {
                return(new HttpUnauthorizedResult());
            }

            var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();

            IEnumerable <ModuleFeature> features = _featureManager.GetAvailableFeatures()
                                                   .Where(f => !DefaultExtensionTypes.IsTheme(f.Extension.ExtensionType))
                                                   .Select(f => new ModuleFeature
            {
                Descriptor          = f,
                IsEnabled           = _shellDescriptor.Features.Any(sf => sf.Name == f.Id),
                IsRecentlyInstalled = _moduleService.IsRecentlyInstalled(f.Extension),
                NeedsUpdate         = featuresThatNeedUpdate.Contains(f.Id),
                DependentFeatures   = _moduleService.GetDependentFeatures(f.Id).Where(x => x.Id != f.Id).ToList()
            })
                                                   .ToList();

            return(View(new FeaturesViewModel
            {
                Features = features,
                IsAllowed = ExtensionIsAllowed
            }));
        }
        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, true);
            }

            foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate())
            {
                try {
                    _dataMigrationManager.Update(feature);
                }
                catch (Exception ex) {
                    if (ex.IsFatal())
                    {
                        throw;
                    }
                    Logger.Error("Could not run migrations automatically on " + feature, ex);
                }
            }
        }
        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[] {
                "Settings"
            };

            theseFeaturesShouldAlwaysBeActive = theseFeaturesShouldAlwaysBeActive.Concat(
                _featureManager.GetAvailableFeatures().Where(f => f.Id != "Coevery.Setup").Select(f => f.Id)).ToArray();

            var enabledFeatures  = _featureManager.GetEnabledFeatures().Select(f => f.Id).ToList();
            var featuresToEnable = theseFeaturesShouldAlwaysBeActive.Where(shouldBeActive => !enabledFeatures.Contains(shouldBeActive)).ToList();

            if (featuresToEnable.Any())
            {
                _featureManager.EnableFeatures(featuresToEnable, true);
            }

            foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate())
            {
                try {
                    _dataMigrationManager.Update(feature);
                }
                catch (Exception e) {
                    Logger.Error("Could not run migrations automatically on " + feature, e);
                }
            }
        }
Beispiel #4
0
        public void ShouldDetectFeaturesThatNeedUpdates()
        {
            Init(new[] { typeof(DataMigrationFeatureNeedUpdate1), typeof(DataMigrationFeatureNeedUpdate2), typeof(DataMigrationFeatureNeedUpdate3) });

            _folders.Manifests.Add("Module1", @"
Name: Module1
Version: 0.1
OrchardVersion: 1
Features:
    Feature1: 
        Description: Feature
    Feature2: 
        Description: Feature
    Feature3: 
        Description: Feature
    Feature4: 
        Description: Feature
");

            // even if there is a data migration class, as it is empty there should me no migration to do
            Assert.That(_dataMigrationManager.GetFeaturesThatNeedUpdate().Contains("Feature1"), Is.False);

            // there is no available class for this feature
            Assert.That(_dataMigrationManager.GetFeaturesThatNeedUpdate().Contains("Feature4"), Is.False);

            // there is a create method and no record in db, so let's create it
            Assert.That(_dataMigrationManager.GetFeaturesThatNeedUpdate().Contains("Feature2"), Is.True);

            // there is an UpdateFrom42 method, so it should be fired if Current == 42

            _repository.Create(new DataMigrationRecord {
                Version            = 42,
                DataMigrationClass = "Orchard.Tests.DataMigration.DataMigrationTests+DataMigrationFeatureNeedUpdate3"
            });

            Assert.That(_dataMigrationManager.GetFeaturesThatNeedUpdate().Contains("Feature3"), Is.True);

            _repository.Delete(_repository.Fetch(m => m.Version == 42).First());
            _repository.Flush();

            _repository.Create(new DataMigrationRecord {
                Version            = 43,
                DataMigrationClass = "Orchard.Tests.DataMigration.DataMigrationTests+DataMigrationFeatureNeedUpdate3"
            });

            Assert.That(_dataMigrationManager.GetFeaturesThatNeedUpdate().Contains("Feature3"), Is.False);
        }
        public IEnumerable <NotifyEntry> GetNotifications()
        {
            var features = _dataMigrationManager.GetFeaturesThatNeedUpdate();

            if (features.Any())
            {
                yield return(new NotifyEntry {
                    Message = T("Some features need to be upgraded: {0}", String.Join(", ", features)), Type = NotifyType.Warning
                });
            }
        }
Beispiel #6
0
 public void Activated()
 {
     foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate())
     {
         try {
             _dataMigrationManager.Update(feature);
         }
         catch (Exception e) {
             Logger.Error("Could not run migrations automatically on " + feature, e);
         }
     }
 }
Beispiel #7
0
 public void Activated()
 {
     foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate())
     {
         try {
             _dataMigrationManager.Update(feature);
         }
         catch (Exception ex) {
             if (ex.IsFatal())
             {
                 throw;
             }
             _logger.LogError("Could not run migrations automatically on " + feature, ex);
         }
     }
 }
Beispiel #8
0
        // <Migration features="f1, f2" />
        // <Migration features="*" />
        // Run migration for features.
        public override void Execute(RecipeExecutionContext context)
        {
            var runAll   = false;
            var features = new List <string>();

            foreach (var attribute in context.RecipeStep.Step.Attributes())
            {
                if (String.Equals(attribute.Name.LocalName, "features", StringComparison.OrdinalIgnoreCase))
                {
                    features = ParseFeatures(attribute.Value);
                    if (features.Contains("*"))
                    {
                        runAll = true;
                    }
                }
                else
                {
                    Logger.Warning("Unrecognized attribute '{0}' encountered; skipping.", attribute.Name.LocalName);
                }
            }

            if (runAll)
            {
                foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate())
                {
                    Logger.Information("Updating feature '{0}'.", feature);
                    try {
                        _dataMigrationManager.Update(feature);
                    }
                    catch (Exception ex) {
                        Logger.Error(ex, "Error while updating feature '{0}'", feature);
                        throw;
                    }
                }
            }
            else
            {
                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;
                }
            }
        }
Beispiel #9
0
        public IEnumerable <NotifyEntry> GetNotifications()
        {
            var features = _dataMigrationManager.GetFeaturesThatNeedUpdate();

            if (features.Any())
            {
                UrlHelper urlHelper = new UrlHelper(_workContext.HttpContext.Request.RequestContext);

                yield return(new NotifyEntry {
                    Message = T("Some features need to be upgraded: {0}",
                                T(string.Join(", ", features
                                              .Select(feature =>
                                                      string.Format("<a href=\"{0}#{1}\">{2}</a>", urlHelper.Action("Features", "Admin", new RouteValueDictionary {
                        { "area", "Orchard.Modules" }
                    }), feature.AsFeatureId(n => T(n)), feature))))),
                    Type = NotifyType.Warning
                });
            }
        }
        // <Migration features="f1, f2" />
        // <Migration features="*" />
        // Run migration for features.
        public void ExecuteRecipeStep(RecipeContext recipeContext)
        {
            if (!String.Equals(recipeContext.RecipeStep.Name, "Migration", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            bool runAll   = false;
            var  features = new List <string>();

            foreach (var attribute in recipeContext.RecipeStep.Step.Attributes())
            {
                if (String.Equals(attribute.Name.LocalName, "features", StringComparison.OrdinalIgnoreCase))
                {
                    features = ParseFeatures(attribute.Value);
                    if (features.Contains("*"))
                    {
                        runAll = true;
                    }
                }
                else
                {
                    Logger.Error("Unrecognized attribute {0} encountered in step Migration. Skipping.", attribute.Name.LocalName);
                }
            }

            if (runAll)
            {
                foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate())
                {
                    _dataMigrationManager.Update(feature);
                }
            }
            else
            {
                _dataMigrationManager.Update(features);
            }

            // run migrations
            recipeContext.Executed = true;
        }
        public async Task ActivatedAsync()
        {
            var featuresThatNeedUpdate = await _dataMigrationManager.GetFeaturesThatNeedUpdate();

            foreach (var feature in featuresThatNeedUpdate)
            {
                try
                {
                    await _dataMigrationManager.UpdateAsync(feature);
                }
                catch (Exception ex)
                {
                    if (ex.IsFatal())
                    {
                        throw;
                    }

                    _logger.LogError("Could not run migrations automatically on " + feature, ex);
                }
            }
        }
Beispiel #12
0
        public void Activated()
        {
            EnsureDistributedLockSchemaExists();

            IDistributedLock @lock;

            if (_distributedLockService.TryAcquireLock(GetType().FullName, TimeSpan.FromMinutes(30), TimeSpan.FromMilliseconds(250), out @lock))
            {
                using (@lock)
                {
                    // 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[] {
                        "Settings", "Shapes",
                    };

                    var enabledFeatures  = _featureManager.GetEnabledFeatures().Select(f => f.Id).ToList();
                    var featuresToEnable = theseFeaturesShouldAlwaysBeActive.Where(shouldBeActive => !enabledFeatures.Contains(shouldBeActive)).ToList();
                    if (featuresToEnable.Any())
                    {
                        _featureManager.EnableFeatures(featuresToEnable, true);
                    }

                    foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate())
                    {
                        try
                        {
                            _dataMigrationManager.Update(feature);
                        }
                        catch (Exception ex)
                        {
                            if (ex.IsFatal())
                            {
                                throw;
                            }
                            Logger.Error("Could not run migrations automatically on " + feature, ex);
                        }
                    }
                }
            }
        }
        public void List()
        {
            var currentTheme           = _siteThemeService.GetSiteTheme();
            var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();

            var themes = _extensionManager.AvailableExtensions()
                         .Where(d => DefaultExtensionTypes.IsTheme(d.ExtensionType))
                         .Where(d => d.Tags != null && d.Tags.Split(',').Any(t => t.Trim().Equals("hidden", StringComparison.OrdinalIgnoreCase)) == false)
                         .Select(d => new ThemeEntry {
                Descriptor  = d,
                NeedsUpdate = featuresThatNeedUpdate.Contains(d.Id),
                Enabled     = _shellDescriptor.Features.Any(sf => sf.Name == d.Id)
            })
                         .ToArray();

            if (Summary)
            {
                foreach (var theme in themes)
                {
                    Context.Output.WriteLine(T("{0}", theme.Name));
                }
            }
            else
            {
                Context.Output.WriteLine(T("Current theme"));
                Context.Output.WriteLine(T("--------------------------"));
                WriteThemeLines(new ThemeEntry {
                    Descriptor  = currentTheme,
                    NeedsUpdate = featuresThatNeedUpdate.Contains(currentTheme.Id),
                    Enabled     = _shellDescriptor.Features.Any(sf => sf.Name == currentTheme.Id)
                });

                Context.Output.WriteLine(T("List of available themes"));
                Context.Output.WriteLine(T("--------------------------"));
                themes.Where(t => t.Name.Trim().Equals(currentTheme.Name.Trim(), StringComparison.OrdinalIgnoreCase) == false)
                .ToList()
                .ForEach(WriteThemeLines);
            }
        }
Beispiel #14
0
        public ActionResult Index()
        {
            bool installThemes =
                _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "PackagingServices") != null &&
                Services.Authorizer.Authorize(StandardPermissions.SiteOwner) && // only site owners
                _shellSettings.Name == ShellSettings.DefaultName;    // of the default tenant

            var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();

            ThemeEntry          currentTheme           = null;
            ExtensionDescriptor currentThemeDescriptor = _siteThemeService.GetSiteTheme();

            if (currentThemeDescriptor != null)
            {
                currentTheme = new ThemeEntry(currentThemeDescriptor);
            }

            IEnumerable <ThemeEntry> themes = _extensionManager.AvailableExtensions()
                                              .Where(extensionDescriptor => {
                bool hidden = false;
                string tags = extensionDescriptor.Tags;
                if (tags != null)
                {
                    hidden = tags.Split(',').Any(t => t.Trim().Equals("hidden", StringComparison.OrdinalIgnoreCase));
                }

                // is the theme allowed for this tenant ?
                bool allowed = _shellSettings.Themes.Length == 0 || _shellSettings.Themes.Contains(extensionDescriptor.Id);

                return(!hidden && allowed &&
                       DefaultExtensionTypes.IsTheme(extensionDescriptor.ExtensionType) &&
                       (currentTheme == null ||
                        !currentTheme.Descriptor.Id.Equals(extensionDescriptor.Id)));
            })
                                              .Select(extensionDescriptor => {
                ThemeEntry themeEntry = new ThemeEntry(extensionDescriptor)
                {
                    NeedsUpdate         = featuresThatNeedUpdate.Contains(extensionDescriptor.Id),
                    IsRecentlyInstalled = _themeService.IsRecentlyInstalled(extensionDescriptor),
                    Enabled             = _shellDescriptor.Features.Any(sf => sf.Name == extensionDescriptor.Id),
                    CanUninstall        = installThemes
                };

                if (_extensionDisplayEventHandler != null)
                {
                    foreach (string notification in _extensionDisplayEventHandler.Displaying(themeEntry.Descriptor, ControllerContext.RequestContext))
                    {
                        themeEntry.Notifications.Add(notification);
                    }
                }

                return(themeEntry);
            })
                                              .ToArray();

            return(View(new ThemesIndexViewModel {
                CurrentTheme = currentTheme,
                InstallThemes = installThemes,
                Themes = themes
            }));
        }