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);
                }
            }
        }
        public void DataMigrationShouldDoNothingIfNoDataMigrationIsProvidedForFeature()
        {
            Init(new[] { typeof(DataMigrationEmpty) });

            _folders.Manifests.Add("Module2", @"
Name: Module2
Version: 0.1
CoeveryVersion: 1
Features:
    Feature1: 
        Description: Feature
");

            _dataMigrationManager.Update("Feature1");
            Assert.That(_repository.Table.Count(), Is.EqualTo(0));
        }
        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);
                }
            }
        }
예제 #4
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;
                }
            }
        }
예제 #5
0
        public ActionResult FeaturesPOST(FeaturesBulkAction bulkAction, IList <string> featureIds, bool?force)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (featureIds == null || !featureIds.Any())
            {
                ModelState.AddModelError("featureIds", T("Please select one or more features."));
            }

            if (ModelState.IsValid)
            {
                var availableFeatures = _moduleService.GetAvailableFeatures().Where(feature => ModuleIsAllowed(feature.Descriptor.Extension)).ToList();
                var selectedFeatures  = availableFeatures.Where(x => featureIds.Contains(x.Descriptor.Id)).ToList();
                var enabledFeatures   = availableFeatures.Where(x => x.IsEnabled && featureIds.Contains(x.Descriptor.Id)).Select(x => x.Descriptor.Id).ToList();
                var disabledFeatures  = availableFeatures.Where(x => !x.IsEnabled && featureIds.Contains(x.Descriptor.Id)).Select(x => x.Descriptor.Id).ToList();

                switch (bulkAction)
                {
                case FeaturesBulkAction.None:
                    break;

                case FeaturesBulkAction.Enable:
                    _moduleService.EnableFeatures(disabledFeatures, force == true);
                    break;

                case FeaturesBulkAction.Disable:
                    _moduleService.DisableFeatures(enabledFeatures, force == true);
                    break;

                case FeaturesBulkAction.Toggle:
                    _moduleService.EnableFeatures(disabledFeatures, force == true);
                    _moduleService.DisableFeatures(enabledFeatures, force == true);
                    break;

                case FeaturesBulkAction.Update:
                    foreach (var feature in selectedFeatures.Where(x => x.NeedsUpdate))
                    {
                        var id = feature.Descriptor.Id;
                        try {
                            _reportsCoordinator.Register("Data Migration", "Upgrade " + id, "Orchard installation");
                            _dataMigrationManager.Update(id);
                            Services.Notifier.Information(T("The feature {0} was updated successfully", id));
                        }
                        catch (Exception exception) {
                            Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, exception.Message));
                        }
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(RedirectToAction("Features"));
        }
        // <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;
        }
예제 #7
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);
         }
     }
 }
예제 #8
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);
         }
     }
 }
예제 #9
0
        public void UpgradeDatabase(params string[] featureNames)
        {
            var features = featureNames.Any()
                                   ? featureNames
                                   : _extensionManager.AvailableExtensions()
                           .SelectMany(ext => ext.Features)
                           .Select(f => f.Id);

            try {
                foreach (var feature in features)
                {
                    _dataMigrationManager.Update(feature);
                }
            }
            catch (Exception ex) {
                throw new OrchardException(T("An error occured while upgrading the database."), ex);
            }

            Context.Output.WriteLine(T("Database upgraded"));
        }
예제 #10
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);
                        }
                    }
                }
            }
        }
예제 #11
0
        public ActionResult Update(string id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (string.IsNullOrEmpty(id))
            {
                return(HttpNotFound());
            }

            try {
                _reportsCoordinator.Register("Data Migration", "Upgrade " + id, "Orchard installation");
                _dataMigrationManager.Update(id);
                Services.Notifier.Information(T("The feature {0} was updated successfully", id));
            } catch (Exception exception) {
                this.Error(exception, T("An error occured while updating the feature {0}: {1}", id, exception.Message), Logger, Services.Notifier);
            }

            return(RedirectToAction("Features"));
        }
예제 #12
0
        public ActionResult Update(string themeId)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Couldn't update theme")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (string.IsNullOrEmpty(themeId))
            {
                return(HttpNotFound());
            }

            try {
                _dataMigrationManager.Update(themeId);
                Services.Notifier.Information(T("The theme {0} was updated successfully.", themeId));
                Logger.Information("The theme {0} was updated successfully.", themeId);
            } catch (Exception exception) {
                Logger.Error(T("An error occurred while updating the theme {0}: {1}", themeId, exception.Message).Text);
                Services.Notifier.Error(T("An error occurred while updating the theme {0}: {1}", themeId, exception.Message));
            }

            return(RedirectToAction("Index"));
        }
        public void Installing(Feature feature)
        {
            var featureName = feature.Descriptor.Id;

            _dataMigrationManager.Update(featureName);
        }
예제 #14
0
 public void Update(params string[] featureNames)
 {
     Context.Output.WriteLine(T("Start update features"));
     _dataMigrationManager.Update(featureNames);
     Context.Output.WriteLine(T("Updated features  {0}", string.Join(",", featureNames)));
 }