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"));
        }
Exemple #2
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"));
        }
Exemple #3
0
        public ActionResult IndexPOST()
        {
            if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to migrate routes.")))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new MigrateViewModel {
                ContentTypes = new List <ContentTypeEntry>()
            };

            if (TryUpdateModel(viewModel))
            {
                // creating report
                _reportsCoordinator.Register("Migration", "Upgrade", "Migrating " + string.Join(" ,", viewModel.ContentTypes.Where(x => x.IsChecked).Select(x => x.ContentTypeName).ToArray()));

                var contentTypesToMigrate = viewModel.ContentTypes.Where(c => c.IsChecked).Select(c => c.ContentTypeName);

                var sessionFactory = _sessionFactoryHolder.GetSessionFactory();
                var session        = sessionFactory.OpenSession();

                foreach (var contentType in contentTypesToMigrate)
                {
                    _reportsCoordinator.Information("Migration", "Adding parts to " + contentType);

                    // migrating parts
                    _contentDefinitionManager.AlterTypeDefinition(contentType,
                                                                  builder => builder
                                                                  .WithPart("AutoroutePart")
                                                                  .WithPart("TitlePart"));

                    // force the first object to be reloaded in order to get a valid AutoroutePart
                    _orchardServices.ContentManager.Clear();

                    var count         = 0;
                    var isContainable = false;
                    IEnumerable <ContentItem> contents;
                    bool errors = false;

                    do
                    {
                        contents = _orchardServices.ContentManager.HqlQuery().ForType(contentType).ForVersion(VersionOptions.Latest).Slice(count, 100).ToList();

                        foreach (dynamic content in contents)
                        {
                            var autoroutePart = ((ContentItem)content).As <AutoroutePart>();
                            var titlePart     = ((ContentItem)content).As <TitlePart>();
                            var commonPart    = ((ContentItem)content).As <CommonPart>();

                            if (commonPart != null && commonPart.Container != null)
                            {
                                isContainable = true;
                            }

                            using (new TransactionScope(TransactionScopeOption.RequiresNew)) {
                                var command = session.Connection.CreateCommand();
                                command.CommandText = string.Format(@"
                                    SELECT Title, Path FROM {0} 
                                    INNER JOIN {1} ON {0}.Id = {1}.Id
                                    WHERE Latest = 1 AND {0}.ContentItemRecord_Id = {2}", GetPrefixedTableName("Routable_RoutePartRecord"), GetPrefixedTableName("Orchard_Framework_ContentItemVersionRecord"), autoroutePart.ContentItem.Id);
                                var reader = command.ExecuteReader();
                                reader.Read();

                                try {
                                    var title = reader.GetString(0);
                                    var path  = reader.GetString(1);

                                    reader.Close();

                                    autoroutePart.DisplayAlias = path ?? String.Empty;
                                    titlePart.Title            = title;

                                    _autorouteService.PublishAlias(autoroutePart);
                                }
                                catch (Exception e) {
                                    if (!reader.IsClosed)
                                    {
                                        reader.Close();
                                    }

                                    _reportsCoordinator.Error("Migration", "Migrating content item " + autoroutePart.ContentItem.Id + " failed with: " + e.Message);
                                    errors = true;
                                }
                            }

                            count++;
                        }

                        _orchardServices.ContentManager.Clear();
                    } while (contents.Any());

                    _contentDefinitionManager.AlterTypeDefinition(contentType, builder => builder.RemovePart("RoutePart"));

                    var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
                    if (isContainable || typeDefinition.Parts.Any(x => x.PartDefinition.Name == "ContainablePart"))
                    {
                        _autorouteService.CreatePattern(contentType, "Container and Title", "{Content.Container.Path}/{Content.Slug}", "my-container/a-sample-title", true);
                    }
                    else
                    {
                        _autorouteService.CreatePattern(contentType, "Title", "{Content.Slug}", "my-sample-title", true);
                    }

                    if (errors)
                    {
                        _orchardServices.Notifier.Warning(T("Some content items could not be imported. Please refer to the corresponding Report."));
                    }
                    else
                    {
                        _orchardServices.Notifier.Information(T("{0} was migrated successfully", contentType));
                    }
                }
            }

            return(RedirectToAction("Index"));
        }