Ejemplo n.º 1
0
        public void RemoveType(string name, bool deleteContent)
        {
            // first remove all attached parts
            var typeDefinition  = _contentDefinitionManager.GetTypeDefinition(name);
            var partDefinitions = typeDefinition.Parts.ToArray();

            foreach (var partDefinition in partDefinitions)
            {
                RemovePartFromType(partDefinition.PartDefinition.Name, name);

                // delete the part if it's its own part
                if (partDefinition.PartDefinition.Name == name)
                {
                    RemovePart(name);
                }
            }

            _contentDefinitionManager.DeleteTypeDefinition(name);

            // TODO: Create a scheduled job to delete the content items
            if (deleteContent)
            {
                var contentItems = _session
                                   .QueryAsync <ContentItem, ContentItemIndex>(x => x.ContentType == name)
                                   .List().Result;

                foreach (var contentItem in contentItems)
                {
                    _session.Delete(contentItem);
                }
            }
            _eventBus.Notify <IContentDefinitionEventHandler>(x => x.ContentTypeRemoved(new ContentTypeRemovedContext {
                ContentTypeDefinition = typeDefinition
            }));
        }
        public void RemoveType(string name, bool deleteContent)
        {
            // first remove all attached parts
            var typeDefinition  = _contentDefinitionManager.GetTypeDefinition(name);
            var partDefinitions = typeDefinition.Parts.ToArray();

            foreach (var partDefinition in partDefinitions)
            {
                RemovePartFromType(partDefinition.PartDefinition.Name, name);

                // delete the part if it's its own part
                if (partDefinition.PartDefinition.Name == name)
                {
                    RemovePart(name);
                }
            }

            _contentDefinitionManager.DeleteTypeDefinition(name);

            // delete all content items (but keep versions)
            if (deleteContent)
            {
                var contentItems = Services.ContentManager.Query(name).List();
                foreach (var contentItem in contentItems)
                {
                    Services.ContentManager.Remove(contentItem);
                }
            }
            _contentDefinitionEventHandlers.ContentTypeRemoved(new ContentTypeRemovedContext {
                ContentTypeDefinition = typeDefinition
            });
        }
        public void DeleteTaxonomy(TaxonomyPart taxonomy)
        {
            _contentManager.Remove(taxonomy.ContentItem);

            // Removing terms
            foreach (var term in GetTerms(taxonomy.Id))
            {
                DeleteTerm(term);
            }

            _contentDefinitionManager.DeleteTypeDefinition(taxonomy.TermTypeName);
        }
Ejemplo n.º 4
0
        // <RemoveContentDefinition>
        //  <Types>
        //   <Blog creatable = "true" >
        //    <Body format="abodyformat"/>
        //   </Blog>
        //  </Types>
        //  <Parts>
        //  </Parts>
        // </RemoveContentDefinition>
        public override void Execute(RecipeExecutionContext context)
        {
            foreach (var metadataElement in context.RecipeStep.Step.Elements())
            {
                Logger.Debug("Processing element '{0}'.", metadataElement.Name.LocalName);
                switch (metadataElement.Name.LocalName)
                {
                case "Types":
                    foreach (var element in metadataElement.Elements())
                    {
                        var typeName = XmlConvert.DecodeName(element.Name.LocalName);

                        Logger.Information("Removing content type '{0}'.", typeName);
                        try {
                            _contentDefinitionManager.DeleteTypeDefinition(typeName);
                            _contentDefinitonEventHandlers.ContentTypeRemoved(new ContentTypeRemovedContext {
                                ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName)
                            });
                        }
                        catch (Exception ex) {
                            Logger.Error(ex, "Error while removing content type '{0}'.", typeName);
                            throw;
                        }
                    }
                    break;

                case "Parts":
                    foreach (var element in metadataElement.Elements())
                    {
                        var partElement = element;
                        var partName    = XmlConvert.DecodeName(element.Name.LocalName);

                        Logger.Information("Removing content part definition '{0}'.", partName);
                        try {
                            _contentDefinitionManager.DeletePartDefinition(partName);
                            _contentDefinitonEventHandlers.ContentPartRemoved(new ContentPartRemovedContext {
                                ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName)
                            });
                        }
                        catch (Exception ex) {
                            Logger.Error(ex, "Error while removing content part definition for '{0}'.", partName);
                            throw;
                        }
                    }
                    break;

                default:
                    Logger.Warning("Unrecognized element '{0}' encountered; skipping", metadataElement.Name.LocalName);
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        public void DeleteTaxonomy(TaxonomyPart taxonomy)
        {
            _contentManager.Remove(taxonomy.ContentItem);

            // Removing terms
            foreach (var term in GetRootTerms(taxonomy.Id))
            {
                DeleteTerm(term);
            }

            if (_contentManager.Query <TaxonomyPart, TaxonomyPartRecord>().Where(x => x.Id != taxonomy.Id && x.TermTypeName == taxonomy.TermTypeName).Count() == 0)
            {
                _contentDefinitionManager.DeleteTypeDefinition(taxonomy.TermTypeName);
            }
        }
Ejemplo n.º 6
0
        public TaxonomyPartHandler(
            IRepository <TaxonomyPartRecord> repository,
            ITaxonomyService taxonomyService,
            IContentDefinitionManager contentDefinitionManager)
        {
            string previousName = null;

            Filters.Add(StorageFilter.For(repository));
            OnPublished <TaxonomyPart>((context, part) => {
                var previousTermTypeName = part.TermTypeName;
                taxonomyService.CreateTermContentType(part);

                if (previousName != null && part.Name != previousName)
                {
                    // remove previous term type
                    contentDefinitionManager.DeleteTypeDefinition(previousTermTypeName);

                    // update existing fields
                    foreach (var partDefinition in contentDefinitionManager.ListPartDefinitions())
                    {
                        foreach (var field in partDefinition.Fields)
                        {
                            if (field.FieldDefinition.Name == typeof(TaxonomyField).Name)
                            {
                                if (field.Settings.GetModel <TaxonomyFieldSettings>().Taxonomy == previousName)
                                {
                                    contentDefinitionManager.AlterPartDefinition(partDefinition.Name,
                                                                                 cfg => cfg.WithField(field.Name,
                                                                                                      builder => builder.WithSetting("TaxonomyFieldSettings.Taxonomy", part.Name)));
                                }
                            }
                        }
                    }
                }
            });

            OnLoading <TaxonomyPart>((context, part) => part.TermsField.Loader(x => taxonomyService.GetTerms(part.Id)));

            OnUpdating <TitlePart>((context, part) => {
                // if altering the title of a taxonomy, save the name
                if (part.As <TaxonomyPart>() != null)
                {
                    previousName = part.Title;
                }
            });
        }
Ejemplo n.º 7
0
        public OptionSetPartHandler(
            IRepository <OptionSetPartRecord> repository,
            IOptionSetService optionSetService,
            IContentDefinitionManager contentDefinitionManager)
        {
            int?previousId = null;

            Filters.Add(StorageFilter.For(repository));
            OnPublished <OptionSetPart>((context, part) => {
                var previousTermTypeName = part.TermTypeName;

                if (previousId != null && part.Id != previousId)
                {
                    // remove previous term type
                    contentDefinitionManager.DeleteTypeDefinition(previousTermTypeName);

                    // update existing fields
                    foreach (var partDefinition in contentDefinitionManager.ListPartDefinitions())
                    {
                        foreach (var field in partDefinition.Fields)
                        {
                            if (field.FieldDefinition.Name == typeof(OptionSetField).Name)
                            {
                                if (field.Settings.GetModel <OptionSetFieldSettings>().OptionSetId == previousId)
                                {
                                    contentDefinitionManager.AlterPartDefinition(partDefinition.Name,
                                                                                 cfg => cfg.WithField(field.Name,
                                                                                                      builder => builder.WithSetting("TaxonomyFieldSettings.TaxonomyId", part.Id.ToString())));
                                }
                            }
                        }
                    }
                }
            });

            OnLoading <OptionSetPart>((context, part) => part.OptionItemsField.Loader(x => optionSetService.GetOptionItems(part.Id)));

            OnUpdating <TitlePart>((context, part) => {
                // if altering the title of a taxonomy, save the name
                if (part.As <OptionSetPart>() != null)
                {
                    previousId = part.Id;
                }
            });
        }
Ejemplo n.º 8
0
        public TaxonomyPartHandler(
            IRepository<TaxonomyPartRecord> repository, 
            ITaxonomyService taxonomyService,
            IContentDefinitionManager contentDefinitionManager) {
            
            string previousName = null;

            Filters.Add(StorageFilter.For(repository));
            OnPublished<TaxonomyPart>((context, part) => {
                var previousTermTypeName = part.TermTypeName;
                taxonomyService.CreateTermContentType(part);

                if (previousName != null && part.Name != previousName) {

                    // remove previous term type
                    contentDefinitionManager.DeleteTypeDefinition(previousTermTypeName);

                    // update existing fields
                    foreach (var partDefinition in contentDefinitionManager.ListPartDefinitions()) {
                        foreach (var field in partDefinition.Fields) {
                            if (field.FieldDefinition.Name == typeof (TaxonomyField).Name) {

                                if (field.Settings.GetModel<TaxonomyFieldSettings>().Taxonomy == previousName) {
                                    contentDefinitionManager.AlterPartDefinition(partDefinition.Name, 
                                        cfg => cfg.WithField(field.Name, 
                                            builder => builder.WithSetting("TaxonomyFieldSettings.Taxonomy", part.Name)));
                                }
                            }
                        }
                    }
                }
            });

            OnLoading<TaxonomyPart>( (context, part) => part.TermsField.Loader(x => taxonomyService.GetTerms(part.Id)));

            OnUpdating<TitlePart>((context, part) => {
                // if altering the title of a taxonomy, save the name
                if (part.As<TaxonomyPart>() != null) {
                    previousName = part.Title;
                }
            });
        }
Ejemplo n.º 9
0
        public OptionSetPartHandler(
            IRepository<OptionSetPartRecord> repository, 
            IOptionSetService optionSetService,
            IContentDefinitionManager contentDefinitionManager) {

            int? previousId = null;

            Filters.Add(StorageFilter.For(repository));
            OnPublished<OptionSetPart>((context, part) => {
                var previousTermTypeName = part.TermTypeName;

                if (previousId != null && part.Id != previousId) {

                    // remove previous term type
                    contentDefinitionManager.DeleteTypeDefinition(previousTermTypeName);

                    // update existing fields
                    foreach (var partDefinition in contentDefinitionManager.ListPartDefinitions()) {
                        foreach (var field in partDefinition.Fields) {
                            if (field.FieldDefinition.Name == typeof (OptionSetField).Name) {

                                if (field.Settings.GetModel<OptionSetFieldSettings>().OptionSetId == previousId) {
                                    contentDefinitionManager.AlterPartDefinition(partDefinition.Name, 
                                        cfg => cfg.WithField(field.Name,
                                            builder => builder.WithSetting("TaxonomyFieldSettings.TaxonomyId", part.Id.ToString())));
                                }
                            }
                        }
                    }
                }
            });

            OnLoading<OptionSetPart>((context, part) => part.OptionItemsField.Loader(x => optionSetService.GetOptionItems(part.Id)));

            OnUpdating<TitlePart>((context, part) => {
                // if altering the title of a taxonomy, save the name
                if (part.As<OptionSetPart>() != null) {
                    previousId = part.Id;
                }
            });
        }
        public void RemoveType(string name, bool deleteContent)
        {
            // first remove all attached parts
            var typeDefinition  = _contentDefinitionManager.LoadTypeDefinition(name);
            var partDefinitions = typeDefinition.Parts.ToArray();

            foreach (var partDefinition in partDefinitions)
            {
                RemovePartFromType(partDefinition.PartDefinition.Name, name);

                // delete the part if it's its own part
                if (partDefinition.PartDefinition.Name == name)
                {
                    RemovePart(name);
                }
            }

            _contentDefinitionManager.DeleteTypeDefinition(name);

            _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentTypeRemoved(context), new ContentTypeRemovedContext {
                ContentTypeDefinition = typeDefinition
            }, Logger);
        }