コード例 #1
0
        /// <summary>
        /// Migrate existing ContentPart settings to WithSettings<typeparamref name="TSettings"/>
        /// This method will be removed in a future release.
        /// </summary>
        /// <typeparam name="TPart"></typeparam>
        /// <typeparam name="TSettings"></typeparam>
        /// <param name="manager"></param>
        public static void MigratePartSettings <TPart, TSettings>(this IContentDefinitionManager manager)
            where TPart : ContentPart where TSettings : class
        {
            var contentTypes = manager.LoadTypeDefinitions();

            foreach (var contentType in contentTypes)
            {
                var partDefinition = contentType.Parts.FirstOrDefault(x => x.PartDefinition.Name == typeof(TPart).Name);
                if (partDefinition != null)
                {
                    var existingSettings = partDefinition.Settings.ToObject <TSettings>();

                    // Remove existing properties from JObject
                    var properties = typeof(TSettings).GetProperties();
                    foreach (var property in properties)
                    {
                        partDefinition.Settings.Remove(property.Name);
                    }

                    // Apply existing settings to type definition WithSettings<T>
                    manager.AlterTypeDefinition(contentType.Name, typeBuilder =>
                    {
                        typeBuilder.WithPart(partDefinition.Name, partBuilder =>
                        {
                            partBuilder.WithSettings(existingSettings);
                        });
                    });
                }
            }
        }
コード例 #2
0
 public IEnumerable <EditTypeViewModel> LoadTypes()
 {
     return(_contentDefinitionManager
            .LoadTypeDefinitions()
            .Select(ctd => new EditTypeViewModel(ctd))
            .OrderBy(m => m.DisplayName));
 }
コード例 #3
0
        public async Task MigrateAsync()
        {
            _logger.LogInformation("Migrate meta tags content from part to fields");

            var contentTypes = _contentDefinitionManager.LoadTypeDefinitions().Where(x => x.Parts.Any(p => p.Name.Equals(nameof(MetaTagsPart)))).Select(x => x.Name);
            var contentItems = await _session.Query <ContentItem>()
                               .With <ContentItemIndex>(x => x.Latest)
                               .Where(x => x.ContentType.IsIn(contentTypes))
                               .ListAsync();

            _logger.LogInformation($"Migrating meta tags content for {contentItems.Count()} content items");

            foreach (var contentItem in contentItems)
            {
                var part = contentItem.As <MetaTagsPart>();

                if (part == null || part.IsEmpty)
                {
                    continue;
                }

                part.UpdateDescription(part.Description);
                part.UpdateImage(part.Images);
                part.UpdateTitle(part.Title);

                contentItem.Apply(part);
                await _contentManager.UpdateAsync(contentItem);
            }

            _logger.LogInformation("Migration of meta tags complete");
        }
コード例 #4
0
        // This code can be removed in a later version.
        public int UpdateFrom2()
        {
            // For backwards compatability with liquid filters we disable html sanitization on existing field definitions.
            foreach (var contentType in _contentDefinitionManager.LoadTypeDefinitions())
            {
                if (contentType.Parts.Any(x => x.PartDefinition.Name == "MarkdownBodyPart"))
                {
                    _contentDefinitionManager.AlterTypeDefinition(contentType.Name, x => x.WithPart("MarkdownBodyPart", part =>
                    {
                        part.MergeSettings <MarkdownBodyPartSettings>(x => x.SanitizeHtml = false);
                    }));
                }
            }

            return(3);
        }
コード例 #5
0
ファイル: Migrations.cs プロジェクト: petedavis/OrchardCore
        // Migrate content type definitions. This only needs to run on old content definition schemas.
        // This code can be removed in a later version.
        public int UpdateFrom3()
        {
            var contentTypeDefinitions = _contentDefinitionManager.LoadTypeDefinitions();

            foreach (var contentTypeDefinition in contentTypeDefinitions)
            {
                var existingContentTypeSettings = contentTypeDefinition.Settings.ToObject <ContentTypeSettings>();

                // Do this before creating builder, so settings are removed from the builder settings object.
                // Remove existing properties from JObject
                var contentTypeSettingsProperties = existingContentTypeSettings.GetType().GetProperties();
                foreach (var property in contentTypeSettingsProperties)
                {
                    contentTypeDefinition.Settings.Remove(property.Name);
                }

                _contentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, builder =>
                {
                    builder.WithSettings(existingContentTypeSettings);

                    foreach (var contentTypePartDefinition in contentTypeDefinition.Parts)
                    {
                        var existingTypePartSettings = contentTypePartDefinition.Settings.ToObject <ContentTypePartSettings>();

                        // Remove existing properties from JObject
                        var contentTypePartSettingsProperties = existingTypePartSettings.GetType().GetProperties();
                        foreach (var property in contentTypePartSettingsProperties)
                        {
                            contentTypePartDefinition.Settings.Remove(property.Name);
                        }

                        builder.WithPart(contentTypePartDefinition.Name, contentTypePartDefinition.PartDefinition, partBuilder =>
                        {
                            partBuilder.WithSettings(existingTypePartSettings);
                        });
                    }
                });
            }

            return(4);
        }
コード例 #6
0
        public async Task <int> UpdateFrom3()
        {
            // This code can be removed in RC

            // Update content type definitions
            foreach (var contentType in _contentDefinitionManager.LoadTypeDefinitions())
            {
                if (contentType.Parts.Any(x => x.PartDefinition.Name == "BodyPart"))
                {
                    _contentDefinitionManager.AlterTypeDefinition(contentType.Name, x => x.RemovePart("BodyPart").WithPart("HtmlBodyPart"));
                }
            }

            _contentDefinitionManager.DeletePartDefinition("BodyPart");

            // We are patching all content item versions by moving the Title to DisplayText
            // This step doesn't need to be executed for a brand new site

            var lastDocumentId = 0;

            for (; ;)
            {
                var contentItemVersions = await _session.Query <ContentItem, ContentItemIndex>(x => x.DocumentId > lastDocumentId).Take(10).ListAsync();

                if (!contentItemVersions.Any())
                {
                    // No more content item version to process
                    break;
                }

                foreach (var contentItemVersion in contentItemVersions)
                {
                    if (UpdateBody(contentItemVersion.Content))
                    {
                        _session.Save(contentItemVersion);
                        _logger.LogInformation("A content item version's BodyPart was upgraded: {ContentItemVersionId}", contentItemVersion.ContentItemVersionId);
                    }

                    lastDocumentId = contentItemVersion.Id;
                }

                await _session.CommitAsync();
            }

            bool UpdateBody(JToken content)
            {
                var changed = false;

                if (content.Type == JTokenType.Object)
                {
                    var body = content["BodyPart"]?["Body"]?.Value <string>();

                    if (!String.IsNullOrWhiteSpace(body))
                    {
                        content["HtmlBodyPart"] = new JObject(new JProperty("Html", body));
                        changed = true;
                    }
                }

                foreach (var token in content)
                {
                    changed = UpdateBody(token) || changed;
                }

                return(changed);
            }

            return(4);
        }