diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs index a4dc3b12577..b703adabe6c 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs @@ -57,7 +57,7 @@ public async Task Index() if (model.CanManageDashboard || await _authorizationService.AuthorizeAsync(User, Permissions.AccessAdminDashboard)) { var wrappers = new List(); - var widgetContentTypes = GetDashboardWidgets(); + var widgetContentTypes = await GetDashboardWidgetsAsync(); var widgets = await _adminDashboardService.GetWidgetsAsync(x => x.Published); foreach (var widget in widgets) @@ -99,7 +99,7 @@ public async Task Manage() }); var dashboardCreatable = new List(); - var widgetContentTypes = GetDashboardWidgets(); + var widgetContentTypes = await GetDashboardWidgetsAsync(); var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); @@ -202,8 +202,8 @@ public async Task Update([FromForm] DashboardPartViewModel[] part return RedirectToAction(nameof(Manage)); } - private Dictionary GetDashboardWidgets() - => _contentDefinitionManager.ListTypeDefinitions() + private async Task> GetDashboardWidgetsAsync() + => (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(t => t.StereotypeEquals("DashboardWidget")) .ToDictionary(ctd => ctd.Name, ctd => ctd); } diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Migrations.cs index 9ad363a81f6..f58451d4d86 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Migrations.cs @@ -32,7 +32,7 @@ public async Task CreateAsync() "Position") ); - _contentDefinitionManager.AlterPartDefinition("DashboardPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("DashboardPart", builder => builder .Attachable() .WithDescription("Provides a way to add widgets to a dashboard.") ); diff --git a/src/OrchardCore.Modules/OrchardCore.Alias/Handlers/AliasPartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Alias/Handlers/AliasPartHandler.cs index 064d2afdd42..49fa883d1ff 100644 --- a/src/OrchardCore.Modules/OrchardCore.Alias/Handlers/AliasPartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Alias/Handlers/AliasPartHandler.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -61,7 +60,7 @@ public async override Task UpdatedAsync(UpdateContentContext context, AliasPart return; } - var pattern = GetPattern(part); + var pattern = await GetPatternAsync(part); if (!string.IsNullOrEmpty(pattern)) { @@ -122,9 +121,9 @@ public override async Task CloningAsync(CloneContentContext context, AliasPart p /// /// Get the pattern from the AliasPartSettings property for its type. /// - private string GetPattern(AliasPart part) + private async Task GetPatternAsync(AliasPart part) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(AliasPart))); var pattern = contentTypePartDefinition.GetSettings().Pattern; diff --git a/src/OrchardCore.Modules/OrchardCore.Alias/Indexes/AliasPartIndex.cs b/src/OrchardCore.Modules/OrchardCore.Alias/Indexes/AliasPartIndex.cs index e9b770d9081..06b8222d4f5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Alias/Indexes/AliasPartIndex.cs +++ b/src/OrchardCore.Modules/OrchardCore.Alias/Indexes/AliasPartIndex.cs @@ -31,7 +31,7 @@ public AliasPartIndexProvider(IServiceProvider serviceProvider) _serviceProvider = serviceProvider; } - public override Task UpdatedAsync(UpdateContentContext context) + public override async Task UpdatedAsync(UpdateContentContext context) { var part = context.ContentItem.As(); @@ -43,19 +43,19 @@ public override Task UpdatedAsync(UpdateContentContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for this part. - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); - if (!contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(AliasPart))) + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); + if (!contentTypeDefinition.Parts.Any(ctd => ctd.Name == nameof(AliasPart))) { context.ContentItem.Remove(); _partRemoved.Add(context.ContentItem.ContentItemId); } } - - return Task.CompletedTask; } public string CollectionName { get; set; } + public Type ForType() => typeof(ContentItem); + public void Describe(IDescriptor context) => Describe((DescribeContext)context); public void Describe(DescribeContext context) diff --git a/src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs index c56dc57bef9..36aa9307c3c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.Alias.Indexes; using OrchardCore.Alias.Models; using OrchardCore.ContentManagement.Metadata; @@ -16,9 +17,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition(nameof(AliasPart), builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(AliasPart), builder => builder .Attachable() .WithDescription("Provides a way to define custom aliases for content items.")); diff --git a/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Indexes/ArchiveLaterPartIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Indexes/ArchiveLaterPartIndexProvider.cs index c60ab08cae6..107d3d7a67e 100644 --- a/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Indexes/ArchiveLaterPartIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Indexes/ArchiveLaterPartIndexProvider.cs @@ -23,7 +23,7 @@ public ArchiveLaterPartIndexProvider(IServiceProvider serviceProvider) _serviceProvider = serviceProvider; } - public override Task UpdatedAsync(UpdateContentContext context) + public override async Task UpdatedAsync(UpdateContentContext context) { var part = context.ContentItem.As(); @@ -31,15 +31,13 @@ public override Task UpdatedAsync(UpdateContentContext context) { _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); if (!contentTypeDefinition.Parts.Any(pd => pd.Name == nameof(ArchiveLaterPart))) { context.ContentItem.Remove(); _partRemoved.Add(context.ContentItem.ContentItemId); } } - - return Task.CompletedTask; } public string CollectionName { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Migrations.cs index d91c8bb49d0..2bd447b0c96 100644 --- a/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Migrations.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using OrchardCore.ArchiveLater.Indexes; using OrchardCore.ArchiveLater.Models; using OrchardCore.ContentManagement.Metadata; @@ -17,9 +18,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition(nameof(ArchiveLaterPart), builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(ArchiveLaterPart), builder => builder .Attachable() .WithDescription("Adds the ability to schedule content items to be archived at a given future date and time.")); diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs index c74b245a37d..fae76d095a1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs @@ -152,9 +152,9 @@ public async override Task CloningAsync(CloneContentContext context, AutoroutePa public override Task GetContentItemAspectAsync(ContentItemAspectContext context, AutoroutePart part) { - return context.ForAsync(aspect => + return context.ForAsync(async aspect => { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "AutoroutePart")); var settings = contentTypePartDefinition.GetSettings(); if (settings.ManageContainedItemRoutes) @@ -163,8 +163,6 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context, aspect.Absolute = part.Absolute; aspect.Disabled = part.Disabled; } - - return Task.CompletedTask; }); } @@ -380,7 +378,7 @@ private async Task GenerateContainerPathFromPatternAsync(AutoroutePart part) return; } - var pattern = GetPattern(part); + var pattern = await GetPatternAsync(part); if (!string.IsNullOrEmpty(pattern)) { @@ -422,9 +420,9 @@ private async Task GenerateContainerPathFromPatternAsync(AutoroutePart part) /// /// Get the pattern from the AutoroutePartSettings property for its type. /// - private string GetPattern(AutoroutePart part) + private async Task GetPatternAsync(AutoroutePart part) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(AutoroutePart))); var pattern = contentTypePartDefinition.GetSettings().Pattern; diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs index e713304a1d5..4790ac7a190 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.Autoroute.Core.Indexes; using OrchardCore.Autoroute.Models; using OrchardCore.ContentManagement.Metadata; @@ -16,9 +17,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("AutoroutePart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("AutoroutePart", builder => builder .Attachable() .WithDescription("Provides a custom url for your content item.")); @@ -37,9 +38,9 @@ public int Create() // Migrate PartSettings. This only needs to run on old content definition schemas. // This code can be removed in a later version. - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - _contentDefinitionManager.MigratePartSettings(); + await _contentDefinitionManager.MigratePartSettingsAsync(); return 2; } diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Sitemaps/AutorouteContentTypeProvider.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Sitemaps/AutorouteContentTypeProvider.cs index c39ce338a10..2d256e7a71d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Sitemaps/AutorouteContentTypeProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Sitemaps/AutorouteContentTypeProvider.cs @@ -27,8 +27,7 @@ IContentManager contentManager public async Task GetRouteAsync(SitemapBuilderContext context, ContentItem contentItem) { - var ctd = ListRoutableTypeDefinitions()? - .FirstOrDefault(rctd => rctd.Name == contentItem.ContentType); + var ctd = (await ListRoutableTypeDefinitionsAsync())?.FirstOrDefault(ctd => ctd.Name == contentItem.ContentType); if (ctd != null) { @@ -36,16 +35,16 @@ public async Task GetRouteAsync(SitemapBuilderContext context, ContentIt var routes = contentItemMetadata.DisplayRouteValues; // UrlHelper.Action includes BasePath automatically if present. - // If content item is assigned as home route, Urlhelper resolves as site root. + // If content item is assigned as home route, UrlHelper resolves as site root. return context.HostPrefix + context.UrlHelper.Action(routes["Action"].ToString(), routes); } return null; } - public IEnumerable ListRoutableTypeDefinitions() + public async Task> ListRoutableTypeDefinitionsAsync() { - return _contentDefinitionManager.ListTypeDefinitions() + return (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(ctd => ctd.Parts.Any(p => p.Name == nameof(AutoroutePart))); } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/ContentPickerAdminController.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/ContentPickerAdminController.cs index 1ce879f427d..f8789f12b28 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/ContentPickerAdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/ContentPickerAdminController.cs @@ -34,7 +34,7 @@ public async Task SearchContentItems(string part, string field, s return BadRequest("Part and field are required parameters"); } - var partFieldDefinition = _contentDefinitionManager.GetPartDefinition(part)?.Fields + var partFieldDefinition = (await _contentDefinitionManager.GetPartDefinitionAsync(part))?.Fields .FirstOrDefault(f => f.Name == field); var fieldSettings = partFieldDefinition?.GetSettings(); @@ -57,7 +57,7 @@ public async Task SearchContentItems(string part, string field, s if (fieldSettings.DisplayedStereotypes != null && fieldSettings.DisplayedStereotypes.Length > 0) { - contentTypes = _contentDefinitionManager.ListTypeDefinitions() + contentTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(contentType => { var hasStereotype = contentType.TryGetStereotype(out var stereotype); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/LocalizationSetContentPickerAdminController.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/LocalizationSetContentPickerAdminController.cs index 3818679bd7e..be638ff8b04 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/LocalizationSetContentPickerAdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/LocalizationSetContentPickerAdminController.cs @@ -53,7 +53,7 @@ public async Task SearchLocalizationSets(string part, string fiel return BadRequest("Part and field are required parameters"); } - var partFieldDefinition = _contentDefinitionManager.GetPartDefinition(part)?.Fields + var partFieldDefinition = (await _contentDefinitionManager.GetPartDefinitionAsync(part))?.Fields .FirstOrDefault(f => f.Name == field); var fieldSettings = partFieldDefinition?.GetSettings(); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/UserPickerAdminController.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/UserPickerAdminController.cs index 2ce08072687..19743a752cf 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/UserPickerAdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/UserPickerAdminController.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -53,7 +52,7 @@ public async Task SearchUsers(string part, string field, string c return Forbid(); } - var partFieldDefinition = _contentDefinitionManager.GetPartDefinition(part)?.Fields + var partFieldDefinition = (await _contentDefinitionManager.GetPartDefinitionAsync(part))?.Fields .FirstOrDefault(f => f.Name == field); var fieldSettings = partFieldDefinition?.GetSettings(); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs index e45b87ceff2..53684debeb6 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs @@ -45,10 +45,10 @@ private static async Task RenderHtml(IResolveFieldContext ctx var paths = jsonPath.Split('.'); var partName = paths[0]; var fieldName = paths[1]; - var contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(ctx.Source.ContentItem.ContentType); + var contentTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(ctx.Source.ContentItem.ContentType); var contentPartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.Name, partName)); - var contentPartFieldDefintion = contentPartDefinition.PartDefinition.Fields.FirstOrDefault(x => string.Equals(x.Name, fieldName)); - var settings = contentPartFieldDefintion.GetSettings(); + var contentPartFieldDefinition = contentPartDefinition.PartDefinition.Fields.FirstOrDefault(x => string.Equals(x.Name, fieldName)); + var settings = contentPartFieldDefinition.GetSettings(); var html = ctx.Source.Html; @@ -59,7 +59,7 @@ private static async Task RenderHtml(IResolveFieldContext ctx Html = ctx.Source.Html, Field = ctx.Source, Part = ctx.Source.ContentItem.Get(partName), - PartFieldDefinition = contentPartFieldDefintion + PartFieldDefinition = contentPartFieldDefinition }; var liquidTemplateManager = serviceProvider.GetRequiredService(); var htmlEncoder = serviceProvider.GetService(); @@ -72,7 +72,7 @@ private static async Task RenderHtml(IResolveFieldContext ctx new Context { ["ContentItem"] = ctx.Source.ContentItem, - ["PartFieldDefinition"] = contentPartFieldDefintion + ["PartFieldDefinition"] = contentPartFieldDefinition }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/BooleanFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/BooleanFieldIndexProvider.cs index 7cbfc038321..de6e6cf4208 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/BooleanFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/BooleanFieldIndexProvider.cs @@ -29,7 +29,7 @@ public BooleanFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -47,7 +47,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for BooleanField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/ContentPickerFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/ContentPickerFieldIndexProvider.cs index e6ae7174854..544c09947a8 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/ContentPickerFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/ContentPickerFieldIndexProvider.cs @@ -29,7 +29,7 @@ public ContentPickerFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -47,7 +47,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for ContentPickerField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/DateFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/DateFieldIndexProvider.cs index 78c3cb27478..48f46d86035 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/DateFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/DateFieldIndexProvider.cs @@ -29,7 +29,7 @@ public DateFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -47,7 +47,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for DateField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/DateTimeFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/DateTimeFieldIndexProvider.cs index 4c28a278e9b..d9528d974e6 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/DateTimeFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/DateTimeFieldIndexProvider.cs @@ -29,7 +29,7 @@ public DateTimeFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -47,7 +47,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for DateTimeField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/HtmlFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/HtmlFieldIndexProvider.cs index afbb2fa5f92..4ed94e8a5bd 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/HtmlFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/HtmlFieldIndexProvider.cs @@ -29,7 +29,7 @@ public HtmlFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -47,7 +47,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for Html fields - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/LinkFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/LinkFieldIndexProvider.cs index 3bdd14a4461..3362b0dab17 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/LinkFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/LinkFieldIndexProvider.cs @@ -38,7 +38,7 @@ public LinkFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -61,7 +61,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for LinkField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/MultiTextFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/MultiTextFieldIndexProvider.cs index 438b2c71858..150caea6c59 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/MultiTextFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/MultiTextFieldIndexProvider.cs @@ -35,7 +35,7 @@ public MultiTextFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -53,7 +53,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for TextField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/NumericFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/NumericFieldIndexProvider.cs index 68c029b00fe..f129848d703 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/NumericFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/NumericFieldIndexProvider.cs @@ -29,7 +29,7 @@ public NumericFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -46,8 +46,8 @@ public override void Describe(DescribeContext context) // Lazy initialization because of ISession cyclic dependency _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); - // Search for NumericField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + // Search for NumericField + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/TextFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/TextFieldIndexProvider.cs index e4321ccf533..b269a2e1b4f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/TextFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/TextFieldIndexProvider.cs @@ -35,7 +35,7 @@ public TextFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -53,7 +53,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for TextField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/TimeFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/TimeFieldIndexProvider.cs index c05bfcd570d..10b0991c5a5 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/TimeFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/TimeFieldIndexProvider.cs @@ -29,7 +29,7 @@ public TimeFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -47,7 +47,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for TimeField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/UserPickerFieldIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/UserPickerFieldIndexProvider.cs index 7da6f362e68..d4a27dcb8c1 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/UserPickerFieldIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/UserPickerFieldIndexProvider.cs @@ -29,7 +29,7 @@ public UserPickerFieldIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -47,7 +47,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for ContentPickerField - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Migrations.cs index 475bdc97674..f97ad33f30f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Migrations.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentFields.Settings; using OrchardCore.ContentManagement.Metadata; @@ -17,60 +18,60 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) // This migration does not need to run on new installations, but because there is no // initial migration record, there is no way to shortcut the Create migration. - public int Create() + public async Task CreateAsync() { // Boolean field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Content picker field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Date field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Date time field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Html field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Link field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Localization set content picker field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // MultiText field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Numeric field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Text field - _contentDefinitionManager.MigrateFieldSettings(); - _contentDefinitionManager.MigrateFieldSettings(); - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Time field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Youtube field - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); // Shortcut other migration steps on new content definition schemas. return 2; } // This code can be removed in a later version. - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - // For backwards compatability with liquid filters we disable html sanitization on existing field definitions. - var partDefinitions = _contentDefinitionManager.LoadPartDefinitions(); + // For backwards compatibility with liquid filters we disable html sanitization on existing field definitions. + var partDefinitions = await _contentDefinitionManager.LoadPartDefinitionsAsync(); foreach (var partDefinition in partDefinitions) { if (partDefinition.Fields.Any(x => x.FieldDefinition.Name == "HtmlField")) { - _contentDefinitionManager.AlterPartDefinition(partDefinition.Name, partBuilder => + await _contentDefinitionManager.AlterPartDefinitionAsync(partDefinition.Name, partBuilder => { foreach (var fieldDefinition in partDefinition.Fields.Where(x => x.FieldDefinition.Name == "HtmlField")) { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Services/DefaultContentPickerResultProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Services/DefaultContentPickerResultProvider.cs index aba3c891a1d..177a5b2b5a2 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Services/DefaultContentPickerResultProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Services/DefaultContentPickerResultProvider.cs @@ -8,12 +8,9 @@ using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; -using OrchardCore.ContentManagement.Metadata.Settings; -using OrchardCore.ContentManagement.Models; using OrchardCore.ContentManagement.Records; using OrchardCore.Liquid; using OrchardCore.Localization; -using OrchardCore.Modules; using YesSql; using YesSql.Services; @@ -41,8 +38,7 @@ public async Task> Search(ContentPickerSearchCo var contentTypes = searchContext.ContentTypes; if (searchContext.DisplayAllContentTypes) { - contentTypes = _contentDefinitionManager - .ListTypeDefinitions() + contentTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(x => !x.HasStereotype()) .Select(x => x.Name) .AsEnumerable(); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/ContentLocalizationPartHandlerCoordinator.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/ContentLocalizationPartHandlerCoordinator.cs index d1abe83e6cd..32687dba983 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/ContentLocalizationPartHandlerCoordinator.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/ContentLocalizationPartHandlerCoordinator.cs @@ -30,9 +30,11 @@ ILogger logger public override async Task LocalizingAsync(LocalizationContentContext context) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); if (contentTypeDefinition == null) + { return; + } foreach (var typePartDefinition in contentTypeDefinition.Parts) { @@ -49,9 +51,11 @@ public override async Task LocalizingAsync(LocalizationContentContext context) public override async Task LocalizedAsync(LocalizationContentContext context) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); if (contentTypeDefinition == null) + { return; + } foreach (var typePartDefinition in contentTypeDefinition.Parts) { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Migrations.cs index d55ce9c5bab..b78df27c7d9 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using OrchardCore.ContentLocalization.Models; using OrchardCore.ContentManagement; @@ -19,9 +20,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition(nameof(LocalizationPart), builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(LocalizationPart), builder => builder .Attachable() .WithDescription("Provides a way to create localized version of content.")); @@ -81,7 +82,7 @@ public int UpdateFrom2() public int UpdateFrom3() #pragma warning restore CA1822 // Mark members as static { - // Defer this until after the subsequent migrations have succeded as the schema has changed. + // Defer this until after the subsequent migrations have succeeded as the schema has changed. ShellScope.AddDeferredTask(async scope => { var session = scope.ServiceProvider.GetRequiredService(); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Services/LocalizationPartContentsAdminListFilter.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Services/LocalizationPartContentsAdminListFilter.cs index ef39e01b9b8..2682fd54750 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Services/LocalizationPartContentsAdminListFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Services/LocalizationPartContentsAdminListFilter.cs @@ -31,8 +31,7 @@ public async Task FilterAsync(ContentOptionsViewModel model, IQuery // This is intended to be used by adding ?Localization.ShowLocalizedContentTypes to an AdminMenu url. if (viewModel.ShowLocalizedContentTypes) { - var localizedTypes = _contentDefinitionManager - .ListTypeDefinitions() + var localizedTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(x => x.Parts.Any(p => p.PartDefinition.Name == nameof(LocalizationPart))) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Sitemaps/LocalizedContentItemsQueryProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Sitemaps/LocalizedContentItemsQueryProvider.cs index 120864a91d6..4b7f66dd08a 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Sitemaps/LocalizedContentItemsQueryProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Sitemaps/LocalizedContentItemsQueryProvider.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Threading.Tasks; using OrchardCore.ContentLocalization.Models; @@ -33,15 +32,15 @@ ILocalizationService localizationService public async Task GetContentItemsAsync(ContentTypesSitemapSource source, ContentItemsQueryContext queryContext) { - var routeableContentTypeDefinitions = _routeableContentTypeCoordinator.ListRoutableTypeDefinitions(); + var routeableContentTypeDefinitions = await _routeableContentTypeCoordinator.ListRoutableTypeDefinitionsAsync(); if (source.IndexAll) { // Assumption here is that at least one content type will be localized. - var rctdNames = routeableContentTypeDefinitions.Select(rctd => rctd.Name); + var ctdNames = routeableContentTypeDefinitions.Select(ctd => ctd.Name); var queryResults = await _session.Query() - .With(x => x.Published && x.ContentType.IsIn(rctdNames)) + .With(x => x.Published && x.ContentType.IsIn(ctdNames)) .OrderBy(x => x.CreatedUtc) .ListAsync(); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentPreview/Handlers/PreviewPartHandler.cs b/src/OrchardCore.Modules/OrchardCore.ContentPreview/Handlers/PreviewPartHandler.cs index c2de07aeca4..115c7a922e5 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentPreview/Handlers/PreviewPartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentPreview/Handlers/PreviewPartHandler.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -27,11 +26,11 @@ public PreviewPartHandler( } /// - /// Get the pattern from the AutoroutePartSettings property for its type + /// Get the pattern from the AutoroutePartSettings property for its type. /// - private string GetPattern(PreviewPart part) + private async Task GetPatternAsync(PreviewPart part) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "PreviewPart")); var pattern = contentTypePartDefinition.GetSettings().Pattern; @@ -40,7 +39,7 @@ private string GetPattern(PreviewPart part) public override async Task GetContentItemAspectAsync(ContentItemAspectContext context, PreviewPart part) { - var pattern = GetPattern(part); + var pattern = await GetPatternAsync(part); if (!string.IsNullOrEmpty(pattern)) { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentPreview/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.ContentPreview/Migrations.cs index 9484cd2136e..9abbb8ddc87 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentPreview/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentPreview/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -13,9 +14,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("PreviewPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("PreviewPart", builder => builder .Attachable() .WithDescription("Provides a way to define the url that is used to render your content item for preview. You only need to use this for the content preview feature when running the frontend decoupled from the admin.")); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs index 1698b91e559..409386304e8 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs @@ -71,7 +71,7 @@ public async Task List() return View("List", new ListContentTypesViewModel { - Types = _contentDefinitionService.GetTypes() + Types = await _contentDefinitionService.GetTypesAsync() }); } @@ -100,8 +100,9 @@ public async Task CreatePOST(CreateTypeViewModel viewModel) { ModelState.AddModelError("DisplayName", S["The Display Name can't be empty."]); } + var types = await _contentDefinitionService.LoadTypesAsync(); - if (_contentDefinitionService.LoadTypes().Any(t => string.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) + if (types.Any(t => string.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", S["A type with the same Display Name already exists."]); } @@ -126,7 +127,7 @@ public async Task CreatePOST(CreateTypeViewModel viewModel) ModelState.AddModelError("Name", S["The Technical Name is reserved for internal use."]); } - if (_contentDefinitionService.LoadTypes().Any(t => string.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) + if (types.Any(t => string.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("Name", S["A type with the same Technical Name already exists."]); } @@ -137,7 +138,7 @@ public async Task CreatePOST(CreateTypeViewModel viewModel) return View(viewModel); } - var contentTypeDefinition = _contentDefinitionService.AddType(viewModel.Name, viewModel.DisplayName); + var contentTypeDefinition = await _contentDefinitionService.AddTypeAsync(viewModel.Name, viewModel.DisplayName); var typeViewModel = new EditTypeViewModel(contentTypeDefinition); @@ -153,7 +154,7 @@ public async Task Edit(string id) return Forbid(); } - var typeViewModel = _contentDefinitionService.GetType(id); + var typeViewModel = await _contentDefinitionService.GetTypeAsync(id); if (typeViewModel == null) { @@ -174,7 +175,7 @@ public async Task EditPOST(string id, EditTypeViewModel viewModel) return Forbid(); } - var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(id); + var contentTypeDefinition = await _contentDefinitionManager.LoadTypeDefinitionAsync(id); if (contentTypeDefinition == null) { @@ -194,12 +195,12 @@ public async Task EditPOST(string id, EditTypeViewModel viewModel) } else { - var ownedPartDefinition = _contentDefinitionManager.LoadPartDefinition(contentTypeDefinition.Name); + var ownedPartDefinition = await _contentDefinitionManager.LoadPartDefinitionAsync(contentTypeDefinition.Name); if (ownedPartDefinition != null && viewModel.OrderedFieldNames != null) { - _contentDefinitionService.AlterPartFieldsOrder(ownedPartDefinition, viewModel.OrderedFieldNames); + await _contentDefinitionService.AlterPartFieldsOrderAsync(ownedPartDefinition, viewModel.OrderedFieldNames); } - _contentDefinitionService.AlterTypePartsOrder(contentTypeDefinition, viewModel.OrderedPartNames); + await _contentDefinitionService.AlterTypePartsOrderAsync(contentTypeDefinition, viewModel.OrderedPartNames); await _notifier.SuccessAsync(H["\"{0}\" settings have been saved.", contentTypeDefinition.Name]); } @@ -215,14 +216,14 @@ public async Task Delete(string id) return Forbid(); } - var typeViewModel = _contentDefinitionService.LoadType(id); + var typeViewModel = await _contentDefinitionService.LoadTypeAsync(id); if (typeViewModel == null) { return NotFound(); } - _contentDefinitionService.RemoveType(id, true); + await _contentDefinitionService.RemoveTypeAsync(id, true); await _notifier.SuccessAsync(H["\"{0}\" has been removed.", typeViewModel.DisplayName]); @@ -236,7 +237,7 @@ public async Task AddPartsTo(string id) return Forbid(); } - var typeViewModel = _contentDefinitionService.GetType(id); + var typeViewModel = await _contentDefinitionService.GetTypeAsync(id); if (typeViewModel == null) { @@ -248,7 +249,7 @@ public async Task AddPartsTo(string id) var viewModel = new AddPartsViewModel { Type = typeViewModel, - PartSelections = _contentDefinitionService.GetParts(metadataPartsOnly: false) + PartSelections = (await _contentDefinitionService.GetPartsAsync(metadataPartsOnly: false)) .Where(cpd => !typePartNames.Contains(cpd.Name, StringComparer.OrdinalIgnoreCase) && cpd.PartDefinition != null && cpd.PartDefinition.GetSettings().Attachable) .Select(cpd => new PartSelectionViewModel { PartName = cpd.Name, PartDisplayName = cpd.DisplayName, PartDescription = cpd.Description }) .ToList() @@ -264,14 +265,14 @@ public async Task AddReusablePartTo(string id) return Forbid(); } - var typeViewModel = _contentDefinitionService.GetType(id); + var typeViewModel = await _contentDefinitionService.GetTypeAsync(id); if (typeViewModel == null) { return NotFound(); } - var reusableParts = _contentDefinitionService.GetParts(metadataPartsOnly: false) + var reusableParts = (await _contentDefinitionService.GetPartsAsync(metadataPartsOnly: false)) .Where(cpd => cpd.PartDefinition != null && cpd.PartDefinition.GetSettings().Attachable && cpd.PartDefinition.GetSettings().Reusable); @@ -296,7 +297,7 @@ public async Task AddPartsToPOST(string id) return Forbid(); } - var typeViewModel = _contentDefinitionService.LoadType(id); + var typeViewModel = await _contentDefinitionService.LoadTypeAsync(id); if (typeViewModel == null) { @@ -312,7 +313,7 @@ public async Task AddPartsToPOST(string id) var partsToAdd = viewModel.PartSelections.Where(ps => ps.IsSelected).Select(ps => ps.PartName); foreach (var partToAdd in partsToAdd) { - _contentDefinitionService.AddPartToType(partToAdd, typeViewModel.Name); + await _contentDefinitionService.AddPartToTypeAsync(partToAdd, typeViewModel.Name); await _notifier.SuccessAsync(H["The \"{0}\" part has been added.", partToAdd]); } @@ -333,7 +334,7 @@ public async Task AddReusablePartToPOST(string id) return Forbid(); } - var typeViewModel = _contentDefinitionService.LoadType(id); + var typeViewModel = await _contentDefinitionService.LoadTypeAsync(id); if (typeViewModel == null) { @@ -392,7 +393,7 @@ public async Task AddReusablePartToPOST(string id) var partToAdd = viewModel.SelectedPartName; - _contentDefinitionService.AddReusablePartToType(viewModel.Name, viewModel.DisplayName, viewModel.Description, partToAdd, typeViewModel.Name); + await _contentDefinitionService.AddReusablePartToTypeAsync(viewModel.Name, viewModel.DisplayName, viewModel.Description, partToAdd, typeViewModel.Name); await _notifier.SuccessAsync(H["The \"{0}\" part has been added.", partToAdd]); @@ -407,14 +408,14 @@ public async Task RemovePart(string id, string name) return Forbid(); } - var typeViewModel = _contentDefinitionService.LoadType(id); + var typeViewModel = await _contentDefinitionService.LoadTypeAsync(id); if (typeViewModel == null || !typeViewModel.TypeDefinition.Parts.Any(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase))) { return NotFound(); } - _contentDefinitionService.RemovePartFromType(name, id); + await _contentDefinitionService.RemovePartFromTypeAsync(name, id); await _notifier.SuccessAsync(H["The \"{0}\" part has been removed.", name]); @@ -435,7 +436,7 @@ public async Task ListParts() return View(new ListContentPartsViewModel { // only user-defined parts (not code as they are not configurable) - Parts = _contentDefinitionService.GetParts(true/*metadataPartsOnly*/) + Parts = await _contentDefinitionService.GetPartsAsync(true/*metadataPartsOnly*/) }); } @@ -464,7 +465,7 @@ public async Task CreatePartPOST(CreatePartViewModel viewModel) ModelState.AddModelError("Name", S["The Technical Name can't be empty."]); } - if (_contentDefinitionService.LoadParts(false).Any(p => string.Equals(p.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) + if ((await _contentDefinitionService.LoadPartsAsync(false)).Any(p => string.Equals(p.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("Name", S["A part with the same Technical Name already exists."]); } @@ -489,7 +490,7 @@ public async Task CreatePartPOST(CreatePartViewModel viewModel) return View(viewModel); } - var partViewModel = _contentDefinitionService.AddPart(viewModel); + var partViewModel = await _contentDefinitionService.AddPartAsync(viewModel); if (partViewModel == null) { @@ -509,7 +510,7 @@ public async Task EditPart(string id) return Forbid(); } - var contentPartDefinition = _contentDefinitionManager.GetPartDefinition(id); + var contentPartDefinition = await _contentDefinitionManager.GetPartDefinitionAsync(id); if (contentPartDefinition == null) { @@ -533,7 +534,7 @@ public async Task EditPartPOST(string id, string[] orderedFieldNam return Forbid(); } - var contentPartDefinition = _contentDefinitionManager.LoadPartDefinition(id); + var contentPartDefinition = await _contentDefinitionManager.LoadPartDefinitionAsync(id); if (contentPartDefinition == null) { @@ -552,7 +553,7 @@ public async Task EditPartPOST(string id, string[] orderedFieldNam } else { - _contentDefinitionService.AlterPartFieldsOrder(contentPartDefinition, orderedFieldNames); + await _contentDefinitionService.AlterPartFieldsOrderAsync(contentPartDefinition, orderedFieldNames); await _notifier.SuccessAsync(H["The settings of \"{0}\" have been saved.", contentPartDefinition.Name]); } @@ -568,14 +569,14 @@ public async Task DeletePart(string id) return Forbid(); } - var partViewModel = _contentDefinitionService.LoadPart(id); + var partViewModel = await _contentDefinitionService.LoadPartAsync(id); if (partViewModel == null) { return NotFound(); } - _contentDefinitionService.RemovePart(id); + await _contentDefinitionService.RemovePartAsync(id); await _notifier.InformationAsync(H["\"{0}\" has been removed.", partViewModel.DisplayName]); @@ -589,16 +590,16 @@ public async Task AddFieldTo(string id, string returnUrl = null) return Forbid(); } - var fields = _contentDefinitionService.GetFields().ToList(); + var fields = (await _contentDefinitionService.GetFieldsAsync()).ToList(); - if (!fields.Any()) + if (fields.Count == 0) { await _notifier.WarningAsync(H["There are no fields."]); return RedirectToAction(nameof(List)); } - var partViewModel = _contentDefinitionService.LoadPart(id); + var partViewModel = await _contentDefinitionService.LoadPartAsync(id); if (partViewModel == null) { @@ -623,14 +624,14 @@ public async Task AddFieldToPOST(AddFieldViewModel viewModel, stri return Forbid(); } - var partViewModel = _contentDefinitionService.LoadPart(id); + var partViewModel = await _contentDefinitionService.LoadPartAsync(id); if (partViewModel == null) { return NotFound(); } - var fields = _contentDefinitionService.GetFields().ToList(); + var fields = (await _contentDefinitionService.GetFieldsAsync()).ToList(); if (!fields.Any(field => string.Equals(field.Name, viewModel.FieldTypeName, StringComparison.OrdinalIgnoreCase))) { @@ -675,7 +676,7 @@ public async Task AddFieldToPOST(AddFieldViewModel viewModel, stri if (!ModelState.IsValid) { viewModel.Part = partDefinition; - viewModel.Fields = _contentDefinitionService.GetFields().Select(x => x.Name).OrderBy(x => x).ToList(); + viewModel.Fields = (await _contentDefinitionService.GetFieldsAsync()).Select(x => x.Name).OrderBy(x => x).ToList(); await _documentStore.CancelAsync(); @@ -683,7 +684,7 @@ public async Task AddFieldToPOST(AddFieldViewModel viewModel, stri return View(viewModel); } - _contentDefinitionService.AddFieldToPart(viewModel.Name, viewModel.DisplayName, viewModel.FieldTypeName, partDefinition.Name); + await _contentDefinitionService.AddFieldToPartAsync(viewModel.Name, viewModel.DisplayName, viewModel.FieldTypeName, partDefinition.Name); await _notifier.SuccessAsync(H["The field \"{0}\" has been added.", viewModel.DisplayName]); @@ -704,7 +705,7 @@ public async Task EditField(string id, string name, string returnU return Forbid(); } - var partViewModel = _contentDefinitionService.GetPart(id); + var partViewModel = await _contentDefinitionService.GetPartAsync(id); if (partViewModel == null) { @@ -714,7 +715,7 @@ public async Task EditField(string id, string name, string returnU var partFieldDefinition = partViewModel.PartDefinition.Fields.FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)); if (partFieldDefinition?.FieldDefinition?.Name == null - || !_contentDefinitionService.GetFields().Any(field => string.Equals(field.Name, partFieldDefinition.FieldDefinition.Name, StringComparison.OrdinalIgnoreCase))) + || !(await _contentDefinitionService.GetFieldsAsync()).Any(field => string.Equals(field.Name, partFieldDefinition.FieldDefinition.Name, StringComparison.OrdinalIgnoreCase))) { return NotFound(); } @@ -747,14 +748,14 @@ public async Task EditFieldPOST(string id, EditFieldViewModel view return NotFound(); } - var partViewModel = _contentDefinitionService.LoadPart(id); + var partViewModel = await _contentDefinitionService.LoadPartAsync(id); if (partViewModel == null) { return NotFound(); } - var field = _contentDefinitionManager.LoadPartDefinition(id).Fields.FirstOrDefault(x => string.Equals(x.Name, viewModel.Name, StringComparison.OrdinalIgnoreCase)); + var field = (await _contentDefinitionManager.LoadPartDefinitionAsync(id)).Fields.FirstOrDefault(x => string.Equals(x.Name, viewModel.Name, StringComparison.OrdinalIgnoreCase)); if (field == null) { @@ -773,7 +774,7 @@ public async Task EditFieldPOST(string id, EditFieldViewModel view ModelState.AddModelError("DisplayName", S["The Display Name can't be empty."]); } - if (_contentDefinitionService.LoadPart(partViewModel.Name).PartDefinition.Fields.Any(t => t.Name != viewModel.Name && string.Equals(t.DisplayName().Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) + if ((await _contentDefinitionService.LoadPartAsync(partViewModel.Name)).PartDefinition.Fields.Any(t => t.Name != viewModel.Name && string.Equals(t.DisplayName().Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", S["A field with the same Display Name already exists."]); } @@ -791,10 +792,10 @@ public async Task EditFieldPOST(string id, EditFieldViewModel view await _notifier.InformationAsync(H["Display name changed to {0}.", viewModel.DisplayName]); } - _contentDefinitionService.AlterField(partViewModel, viewModel); + await _contentDefinitionService.AlterFieldAsync(partViewModel, viewModel); // Refresh the local field variable in case it has been altered - field = _contentDefinitionManager.LoadPartDefinition(id).Fields.FirstOrDefault(x => string.Equals(x.Name, viewModel.Name, StringComparison.OrdinalIgnoreCase)); + field = (await _contentDefinitionManager.LoadPartDefinitionAsync(id)).Fields.FirstOrDefault(x => string.Equals(x.Name, viewModel.Name, StringComparison.OrdinalIgnoreCase)); viewModel.Shape = await _contentDefinitionDisplayManager.UpdatePartFieldEditorAsync(field, _updateModelAccessor.ModelUpdater); @@ -817,7 +818,7 @@ public async Task EditFieldPOST(string id, EditFieldViewModel view else { // Redirect to the type editor if a type exists with this name - var typeViewModel = _contentDefinitionService.LoadType(id); + var typeViewModel = await _contentDefinitionService.LoadTypeAsync(id); if (typeViewModel != null) { return RedirectToAction(nameof(Edit), new { id }); @@ -835,7 +836,7 @@ public async Task RemoveFieldFromPOST(string id, string name) return Forbid(); } - var partViewModel = _contentDefinitionService.LoadPart(id); + var partViewModel = await _contentDefinitionService.LoadPartAsync(id); if (partViewModel == null) { @@ -849,11 +850,11 @@ public async Task RemoveFieldFromPOST(string id, string name) return NotFound(); } - _contentDefinitionService.RemoveFieldFromPart(name, partViewModel.Name); + await _contentDefinitionService.RemoveFieldFromPartAsync(name, partViewModel.Name); await _notifier.SuccessAsync(H["The \"{0}\" field has been removed.", field.DisplayName()]); - if (_contentDefinitionService.LoadType(id) != null) + if (await _contentDefinitionService.LoadTypeAsync(id) != null) { return RedirectToAction(nameof(Edit), new { id }); } @@ -872,7 +873,7 @@ public async Task EditTypePart(string id, string name) return Forbid(); } - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(id); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(id); if (typeDefinition == null) { @@ -914,7 +915,7 @@ public async Task EditTypePartPOST(string id, EditTypePartViewMode return NotFound(); } - var typeDefinition = _contentDefinitionManager.LoadTypeDefinition(id); + var typeDefinition = await _contentDefinitionManager.LoadTypeDefinitionAsync(id); if (typeDefinition == null) { @@ -956,10 +957,10 @@ public async Task EditTypePartPOST(string id, EditTypePartViewMode } } - _contentDefinitionService.AlterTypePart(viewModel); + await _contentDefinitionService.AlterTypePartAsync(viewModel); // Refresh the local part variable in case it has been altered - part = _contentDefinitionManager.LoadTypeDefinition(id).Parts.FirstOrDefault(x => string.Equals(x.Name, viewModel.Name, StringComparison.OrdinalIgnoreCase)); + part = (await _contentDefinitionManager.LoadTypeDefinitionAsync(id)).Parts.FirstOrDefault(x => string.Equals(x.Name, viewModel.Name, StringComparison.OrdinalIgnoreCase)); viewModel.Shape = await _contentDefinitionDisplayManager.UpdateTypePartEditorAsync(part, _updateModelAccessor.ModelUpdater); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs index a0f464a68b3..0f1b38ffc55 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs @@ -20,37 +20,34 @@ public ContentDefinitionStep(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public Task ExecuteAsync(RecipeExecutionContext context) + public async Task ExecuteAsync(RecipeExecutionContext context) { if (!string.Equals(context.Name, "ContentDefinition", StringComparison.OrdinalIgnoreCase)) { - return Task.CompletedTask; + return; } var step = context.Step.ToObject(); foreach (var contentType in step.ContentTypes) { - var newType = _contentDefinitionManager.LoadTypeDefinition(contentType.Name) + var newType = await _contentDefinitionManager.LoadTypeDefinitionAsync(contentType.Name) ?? new ContentTypeDefinition(contentType.Name, contentType.DisplayName); - UpdateContentType(newType, contentType); + await UpdateContentTypeAsync(newType, contentType); } foreach (var contentPart in step.ContentParts) { - var newPart = _contentDefinitionManager.LoadPartDefinition(contentPart.Name) + var newPart = await _contentDefinitionManager.LoadPartDefinitionAsync(contentPart.Name) ?? new ContentPartDefinition(contentPart.Name); - UpdateContentPart(newPart, contentPart); + await UpdateContentPartAsync(newPart, contentPart); } - - return Task.CompletedTask; } - private void UpdateContentType(ContentTypeDefinition type, ContentTypeDefinitionRecord record) - { - _contentDefinitionManager.AlterTypeDefinition(type.Name, builder => + private Task UpdateContentTypeAsync(ContentTypeDefinition type, ContentTypeDefinitionRecord record) + => _contentDefinitionManager.AlterTypeDefinitionAsync(type.Name, builder => { if (!string.IsNullOrEmpty(record.DisplayName)) { @@ -63,11 +60,9 @@ private void UpdateContentType(ContentTypeDefinition type, ContentTypeDefinition builder.WithPart(part.Name, part.PartName, partBuilder => partBuilder.MergeSettings(part.Settings)); } }); - } - private void UpdateContentPart(ContentPartDefinition part, ContentPartDefinitionRecord record) - { - _contentDefinitionManager.AlterPartDefinition(part.Name, builder => + private Task UpdateContentPartAsync(ContentPartDefinition part, ContentPartDefinitionRecord record) + => _contentDefinitionManager.AlterPartDefinitionAsync(part.Name, builder => { builder.MergeSettings(record.Settings); @@ -80,7 +75,6 @@ private void UpdateContentPart(ContentPartDefinition part, ContentPartDefinition }); } }); - } private class ContentDefinitionStepModel { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs index ac5f136bad0..8790e82aa02 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs @@ -18,11 +18,11 @@ public DeleteContentDefinitionStep(IContentDefinitionManager contentDefinitionMa _contentDefinitionManager = contentDefinitionManager; } - public Task ExecuteAsync(RecipeExecutionContext context) + public async Task ExecuteAsync(RecipeExecutionContext context) { if (!string.Equals(context.Name, "DeleteContentDefinition", StringComparison.OrdinalIgnoreCase)) { - return Task.CompletedTask; + return; } var step = context.Step.ToObject(); @@ -30,16 +30,14 @@ public Task ExecuteAsync(RecipeExecutionContext context) foreach (var contentType in step.ContentTypes) { // The content definition manager tests existence before trying to delete. - _contentDefinitionManager.DeleteTypeDefinition(contentType); + await _contentDefinitionManager.DeleteTypeDefinitionAsync(contentType); } foreach (var contentPart in step.ContentParts) { // The content definition manager tests existence before trying to delete. - _contentDefinitionManager.DeletePartDefinition(contentPart); + await _contentDefinitionManager.DeletePartDefinitionAsync(contentPart); } - - return Task.CompletedTask; } private class DeleteContentDefinitionStepModel diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs index 421abb92728..6d417750271 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs @@ -19,11 +19,11 @@ public ReplaceContentDefinitionStep(IContentDefinitionManager contentDefinitionM _contentDefinitionManager = contentDefinitionManager; } - public Task ExecuteAsync(RecipeExecutionContext context) + public async Task ExecuteAsync(RecipeExecutionContext context) { if (!string.Equals(context.Name, "ReplaceContentDefinition", StringComparison.OrdinalIgnoreCase)) { - return Task.CompletedTask; + return; } var step = context.Step.ToObject(); @@ -31,26 +31,24 @@ public Task ExecuteAsync(RecipeExecutionContext context) // Delete existing parts first, as deleting them later will clear any imported content types using them. foreach (var contentPart in step.ContentParts) { - _contentDefinitionManager.DeletePartDefinition(contentPart.Name); + await _contentDefinitionManager.DeletePartDefinitionAsync(contentPart.Name); } foreach (var contentType in step.ContentTypes) { - _contentDefinitionManager.DeleteTypeDefinition(contentType.Name); - AlterContentType(contentType); + await _contentDefinitionManager.DeleteTypeDefinitionAsync(contentType.Name); + await AlterContentTypeAsync(contentType); } foreach (var contentPart in step.ContentParts) { - AlterContentPart(contentPart); + await AlterContentPartAsync(contentPart); } - - return Task.CompletedTask; } - private void AlterContentType(ContentTypeDefinitionRecord record) + private async Task AlterContentTypeAsync(ContentTypeDefinitionRecord record) { - _contentDefinitionManager.AlterTypeDefinition(record.Name, builder => + await _contentDefinitionManager.AlterTypeDefinitionAsync(record.Name, builder => { if (!string.IsNullOrEmpty(record.DisplayName)) { @@ -65,9 +63,9 @@ private void AlterContentType(ContentTypeDefinitionRecord record) }); } - private void AlterContentPart(ContentPartDefinitionRecord record) + private async Task AlterContentPartAsync(ContentPartDefinitionRecord record) { - _contentDefinitionManager.AlterPartDefinition(record.Name, builder => + await _contentDefinitionManager.AlterPartDefinitionAsync(record.Name, builder => { builder.MergeSettings(record.Settings); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs index 4e1d64a3af5..401f4e50ad6 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -38,12 +39,12 @@ public ContentDefinitionService( foreach (var element in contentParts.Select(x => x.GetType())) { - logger.LogWarning("The content part '{ContentPart}' should not be registerd in DI. Use AddContentPart instead.", element); + logger.LogWarning("The content part '{ContentPart}' should not be registered in DI. Use AddContentPart instead.", element); } foreach (var element in contentFields.Select(x => x.GetType())) { - logger.LogWarning("The content field '{ContentField}' should not be registerd in DI. Use AddContentField instead.", element); + logger.LogWarning("The content field '{ContentField}' should not be registered in DI. Use AddContentField instead.", element); } // TODO: This code can be removed in a future release and rationalized to only use ContentPartOptions. @@ -58,25 +59,19 @@ public ContentDefinitionService( S = localizer; } - public IEnumerable LoadTypes() - { - return _contentDefinitionManager - .LoadTypeDefinitions() + public async Task> LoadTypesAsync() + => (await _contentDefinitionManager.LoadTypeDefinitionsAsync()) .Select(ctd => new EditTypeViewModel(ctd)) .OrderBy(m => m.DisplayName); - } - public IEnumerable GetTypes() - { - return _contentDefinitionManager - .ListTypeDefinitions() + public async Task> GetTypesAsync() + => (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Select(ctd => new EditTypeViewModel(ctd)) .OrderBy(m => m.DisplayName); - } - public EditTypeViewModel LoadType(string name) + public async Task LoadTypeAsync(string name) { - var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(name); + var contentTypeDefinition = await _contentDefinitionManager.LoadTypeDefinitionAsync(name); if (contentTypeDefinition == null) { @@ -86,9 +81,9 @@ public EditTypeViewModel LoadType(string name) return new EditTypeViewModel(contentTypeDefinition); } - public EditTypeViewModel GetType(string name) + public async Task GetTypeAsync(string name) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(name); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(name); if (contentTypeDefinition == null) { @@ -98,7 +93,7 @@ public EditTypeViewModel GetType(string name) return new EditTypeViewModel(contentTypeDefinition); } - public ContentTypeDefinition AddType(string name, string displayName) + public async Task AddTypeAsync(string name, string displayName) { if (string.IsNullOrWhiteSpace(displayName)) { @@ -107,7 +102,7 @@ public ContentTypeDefinition AddType(string name, string displayName) if (string.IsNullOrWhiteSpace(name)) { - name = GenerateContentTypeNameFromDisplayName(displayName); + name = await GenerateContentTypeNameFromDisplayNameAsync(displayName); } else { @@ -121,80 +116,80 @@ public ContentTypeDefinition AddType(string name, string displayName) } } - while (_contentDefinitionManager.LoadTypeDefinition(name) != null) + while (await _contentDefinitionManager.LoadTypeDefinitionAsync(name) is not null) { name = VersionName(name); } var contentTypeDefinition = new ContentTypeDefinition(name, displayName); - _contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition); + await _contentDefinitionManager.StoreTypeDefinitionAsync(contentTypeDefinition); // Ensure it has its own part. - _contentDefinitionManager.AlterTypeDefinition(name, builder => builder.WithPart(name)); - _contentDefinitionManager.AlterTypeDefinition(name, cfg => cfg.Creatable().Draftable().Versionable().Listable().Securable()); + await _contentDefinitionManager.AlterTypeDefinitionAsync(name, builder => builder.WithPart(name)); + await _contentDefinitionManager.AlterTypeDefinitionAsync(name, cfg => cfg.Creatable().Draftable().Versionable().Listable().Securable()); _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentTypeCreated(context), new ContentTypeCreatedContext { ContentTypeDefinition = contentTypeDefinition }, _logger); return contentTypeDefinition; } - public void RemoveType(string name, bool deleteContent) + public async Task RemoveTypeAsync(string name, bool deleteContent) { // First remove all attached parts. - var typeDefinition = _contentDefinitionManager.LoadTypeDefinition(name); - var partDefinitions = typeDefinition.Parts.ToArray(); + var typeDefinition = await _contentDefinitionManager.LoadTypeDefinitionAsync(name); + var partDefinitions = typeDefinition.Parts.ToList(); foreach (var partDefinition in partDefinitions) { - RemovePartFromType(partDefinition.PartDefinition.Name, name); + await RemovePartFromTypeAsync(partDefinition.PartDefinition.Name, name); // Delete the part if it's its own part. if (partDefinition.PartDefinition.Name == name) { - RemovePart(name); + await RemovePartAsync(name); } } - _contentDefinitionManager.DeleteTypeDefinition(name); + await _contentDefinitionManager.DeleteTypeDefinitionAsync(name); _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentTypeRemoved(context), new ContentTypeRemovedContext { ContentTypeDefinition = typeDefinition }, _logger); } - public void AddPartToType(string partName, string typeName) + public async Task AddPartToTypeAsync(string partName, string typeName) { - _contentDefinitionManager.AlterTypeDefinition(typeName, typeBuilder => typeBuilder.WithPart(partName)); + await _contentDefinitionManager.AlterTypeDefinitionAsync(typeName, typeBuilder => typeBuilder.WithPart(partName)); _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentPartAttached(context), new ContentPartAttachedContext { ContentTypeName = typeName, ContentPartName = partName }, _logger); } - public void AddReusablePartToType(string name, string displayName, string description, string partName, string typeName) + public async Task AddReusablePartToTypeAsync(string name, string displayName, string description, string partName, string typeName) { - _contentDefinitionManager.AlterTypeDefinition(typeName, typeBuilder => typeBuilder.WithPart(name, partName, cfg => - { - cfg.WithDisplayName(displayName); - cfg.WithDescription(description); - })); + await _contentDefinitionManager.AlterTypeDefinitionAsync(typeName, typeBuilder => typeBuilder + .WithPart(name, partName, partBuilder => + { + partBuilder.WithDisplayName(displayName); + partBuilder.WithDescription(description); + }) + ); _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentPartAttached(context), new ContentPartAttachedContext { ContentTypeName = typeName, ContentPartName = partName }, _logger); } - public void RemovePartFromType(string partName, string typeName) + public async Task RemovePartFromTypeAsync(string partName, string typeName) { - _contentDefinitionManager.AlterTypeDefinition(typeName, typeBuilder => typeBuilder.RemovePart(partName)); + await _contentDefinitionManager.AlterTypeDefinitionAsync(typeName, typeBuilder => typeBuilder.RemovePart(partName)); _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentPartDetached(context), new ContentPartDetachedContext { ContentTypeName = typeName, ContentPartName = partName }, _logger); } - public IEnumerable LoadParts(bool metadataPartsOnly) + public async Task> LoadPartsAsync(bool metadataPartsOnly) { - var typeNames = new HashSet(LoadTypes().Select(ctd => ctd.Name)); + var typeNames = new HashSet((await LoadTypesAsync()).Select(ctd => ctd.Name)); // User-defined parts. // Except for those parts with the same name as a type (implicit type's part or a mistake). - var userContentParts = _contentDefinitionManager.LoadPartDefinitions() + var userContentParts = (await _contentDefinitionManager.LoadPartDefinitionsAsync()) .Where(cpd => !typeNames.Contains(cpd.Name)) .Select(cpd => new EditPartViewModel(cpd)) - .ToDictionary( - k => k.Name, - v => v); + .ToDictionary(k => k.Name); // Code-defined parts. var codeDefinedParts = metadataPartsOnly @@ -210,22 +205,20 @@ public IEnumerable LoadParts(bool metadataPartsOnly) .OrderBy(m => m.DisplayName); } - public IEnumerable GetParts(bool metadataPartsOnly) + public async Task> GetPartsAsync(bool metadataPartsOnly) { - var typeNames = new HashSet(GetTypes().Select(ctd => ctd.Name)); + var typeNames = new HashSet((await GetTypesAsync()).Select(ctd => ctd.Name)); // User-defined parts. // Except for those parts with the same name as a type (implicit type's part or a mistake). - var userContentParts = _contentDefinitionManager.ListPartDefinitions() + var userContentParts = (await _contentDefinitionManager.ListPartDefinitionsAsync()) .Where(cpd => !typeNames.Contains(cpd.Name)) .Select(cpd => new EditPartViewModel(cpd)) - .ToDictionary( - k => k.Name, - v => v); + .ToDictionary(k => k.Name); // Code-defined parts. var codeDefinedParts = metadataPartsOnly - ? Enumerable.Empty() + ? [] : _contentPartTypes .Where(cpd => !userContentParts.ContainsKey(cpd.Name)) .Select(cpi => new EditPartViewModel { Name = cpi.Name, DisplayName = cpi.Name }) @@ -237,13 +230,13 @@ public IEnumerable GetParts(bool metadataPartsOnly) .OrderBy(m => m.DisplayName); } - public EditPartViewModel LoadPart(string name) + public async Task LoadPartAsync(string name) { - var contentPartDefinition = _contentDefinitionManager.LoadPartDefinition(name); + var contentPartDefinition = await _contentDefinitionManager.LoadPartDefinitionAsync(name); if (contentPartDefinition == null) { - var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(name); + var contentTypeDefinition = await _contentDefinitionManager.LoadTypeDefinitionAsync(name); if (contentTypeDefinition == null) { @@ -258,13 +251,13 @@ public EditPartViewModel LoadPart(string name) return viewModel; } - public EditPartViewModel GetPart(string name) + public async Task GetPartAsync(string name) { - var contentPartDefinition = _contentDefinitionManager.GetPartDefinition(name); + var contentPartDefinition = await _contentDefinitionManager.GetPartDefinitionAsync(name); if (contentPartDefinition == null) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(name); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(name); if (contentTypeDefinition == null) { @@ -279,27 +272,30 @@ public EditPartViewModel GetPart(string name) return viewModel; } - public EditPartViewModel AddPart(CreatePartViewModel partViewModel) + public async Task AddPartAsync(CreatePartViewModel partViewModel) { var name = partViewModel.Name; - if (_contentDefinitionManager.LoadPartDefinition(name) != null) + if (await _contentDefinitionManager.LoadPartDefinitionAsync(name) is not null) + { throw new Exception(S["Cannot add part named '{0}'. It already exists.", name]); + } if (!string.IsNullOrEmpty(name)) { - _contentDefinitionManager.AlterPartDefinition(name, builder => builder.Attachable()); - var partDefinition = _contentDefinitionManager.LoadPartDefinition(name); + await _contentDefinitionManager.AlterPartDefinitionAsync(name, builder => builder.Attachable()); + var partDefinition = await _contentDefinitionManager.LoadPartDefinitionAsync(name); _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentPartCreated(context), new ContentPartCreatedContext { ContentPartDefinition = partDefinition }, _logger); + return new EditPartViewModel(partDefinition); } return null; } - public void RemovePart(string name) + public async Task RemovePartAsync(string name) { - var partDefinition = _contentDefinitionManager.LoadPartDefinition(name); + var partDefinition = await _contentDefinitionManager.LoadPartDefinitionAsync(name); if (partDefinition == null) { @@ -307,45 +303,40 @@ public void RemovePart(string name) return; } - var fieldDefinitions = partDefinition.Fields.ToArray(); - foreach (var fieldDefinition in fieldDefinitions) + foreach (var fieldDefinition in partDefinition.Fields) { - RemoveFieldFromPart(fieldDefinition.Name, name); + await RemoveFieldFromPartAsync(fieldDefinition.Name, name); } - _contentDefinitionManager.DeletePartDefinition(name); + await _contentDefinitionManager.DeletePartDefinitionAsync(name); _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentPartRemoved(context), new ContentPartRemovedContext { ContentPartDefinition = partDefinition }, _logger); } - public IEnumerable GetFields() - { - return _contentFieldTypes; - } + public Task> GetFieldsAsync() + => Task.FromResult(_contentFieldTypes); - public void AddFieldToPart(string fieldName, string fieldTypeName, string partName) - { - AddFieldToPart(fieldName, fieldName, fieldTypeName, partName); - } + public Task AddFieldToPartAsync(string fieldName, string fieldTypeName, string partName) + => AddFieldToPartAsync(fieldName, fieldName, fieldTypeName, partName); - public void AddFieldToPart(string fieldName, string displayName, string fieldTypeName, string partName) + public async Task AddFieldToPartAsync(string fieldName, string displayName, string fieldTypeName, string partName) { if (string.IsNullOrEmpty(fieldName)) { throw new ArgumentException("The 'fieldName' can't be null or empty.", nameof(fieldName)); } - var partDefinition = _contentDefinitionManager.LoadPartDefinition(partName); - var typeDefinition = _contentDefinitionManager.LoadTypeDefinition(partName); + var partDefinition = await _contentDefinitionManager.LoadPartDefinitionAsync(partName); + var typeDefinition = await _contentDefinitionManager.LoadTypeDefinitionAsync(partName); // If the type exists ensure it has its own part. if (typeDefinition != null) { - _contentDefinitionManager.AlterTypeDefinition(partName, builder => builder.WithPart(partName)); + await _contentDefinitionManager.AlterTypeDefinitionAsync(partName, builder => builder.WithPart(partName)); } fieldName = fieldName.ToSafeName(); - _contentDefinitionManager.AlterPartDefinition(partName, + await _contentDefinitionManager.AlterPartDefinitionAsync(partName, partBuilder => partBuilder.WithField(fieldName, fieldBuilder => fieldBuilder.OfType(fieldTypeName).WithDisplayName(displayName))); _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentFieldAttached(context), new ContentFieldAttachedContext @@ -357,9 +348,9 @@ public void AddFieldToPart(string fieldName, string displayName, string fieldTyp }, _logger); } - public void RemoveFieldFromPart(string fieldName, string partName) + public async Task RemoveFieldFromPartAsync(string fieldName, string partName) { - _contentDefinitionManager.AlterPartDefinition(partName, typeBuilder => typeBuilder.RemoveField(fieldName)); + await _contentDefinitionManager.AlterPartDefinitionAsync(partName, typeBuilder => typeBuilder.RemoveField(fieldName)); _contentDefinitionEventHandlers.Invoke((handler, context) => handler.ContentFieldDetached(context), new ContentFieldDetachedContext { ContentPartName = partName, @@ -367,9 +358,9 @@ public void RemoveFieldFromPart(string fieldName, string partName) }, _logger); } - public void AlterField(EditPartViewModel partViewModel, EditFieldViewModel fieldViewModel) + public async Task AlterFieldAsync(EditPartViewModel partViewModel, EditFieldViewModel fieldViewModel) { - _contentDefinitionManager.AlterPartDefinition(partViewModel.Name, partBuilder => + await _contentDefinitionManager.AlterPartDefinitionAsync(partViewModel.Name, partBuilder => { partBuilder.WithField(fieldViewModel.Name, fieldBuilder => { @@ -380,11 +371,11 @@ public void AlterField(EditPartViewModel partViewModel, EditFieldViewModel field }); } - public void AlterTypePart(EditTypePartViewModel typePartViewModel) + public async Task AlterTypePartAsync(EditTypePartViewModel typePartViewModel) { var typeDefinition = typePartViewModel.TypePartDefinition.ContentTypeDefinition; - _contentDefinitionManager.AlterTypeDefinition(typeDefinition.Name, type => + await _contentDefinitionManager.AlterTypeDefinitionAsync(typeDefinition.Name, type => { type.WithPart(typePartViewModel.Name, typePartViewModel.TypePartDefinition.PartDefinition, part => { @@ -396,9 +387,8 @@ public void AlterTypePart(EditTypePartViewModel typePartViewModel) }); } - public void AlterTypePartsOrder(ContentTypeDefinition typeDefinition, string[] partNames) - { - _contentDefinitionManager.AlterTypeDefinition(typeDefinition.Name, type => + public Task AlterTypePartsOrderAsync(ContentTypeDefinition typeDefinition, string[] partNames) + => _contentDefinitionManager.AlterTypeDefinitionAsync(typeDefinition.Name, type => { for (var i = 0; i < partNames.Length; i++) { @@ -409,11 +399,9 @@ public void AlterTypePartsOrder(ContentTypeDefinition typeDefinition, string[] p }); } }); - } - public void AlterPartFieldsOrder(ContentPartDefinition partDefinition, string[] fieldNames) - { - _contentDefinitionManager.AlterPartDefinition(partDefinition.Name, type => + public Task AlterPartFieldsOrderAsync(ContentPartDefinition partDefinition, string[] fieldNames) + => _contentDefinitionManager.AlterPartDefinitionAsync(partDefinition.Name, type => { for (var i = 0; i < fieldNames.Length; i++) { @@ -424,28 +412,29 @@ public void AlterPartFieldsOrder(ContentPartDefinition partDefinition, string[] }); } }); - } - public string GenerateContentTypeNameFromDisplayName(string displayName) + public async Task GenerateContentTypeNameFromDisplayNameAsync(string displayName) { displayName = displayName.ToSafeName(); - while (_contentDefinitionManager.LoadTypeDefinition(displayName) != null) + while (await _contentDefinitionManager.LoadTypeDefinitionAsync(displayName) != null) + { displayName = VersionName(displayName); + } return displayName; } - public string GenerateFieldNameFromDisplayName(string partName, string displayName) + public async Task GenerateFieldNameFromDisplayNameAsync(string partName, string displayName) { IEnumerable fieldDefinitions; - var part = _contentDefinitionManager.LoadPartDefinition(partName); + var part = await _contentDefinitionManager.LoadPartDefinitionAsync(partName); displayName = displayName.ToSafeName(); if (part == null) { - var type = _contentDefinitionManager.LoadTypeDefinition(partName) + var type = await _contentDefinitionManager.LoadTypeDefinitionAsync(partName) ?? throw new ArgumentException("The part doesn't exist: " + partName); var typePart = type.Parts.FirstOrDefault(x => x.PartDefinition.Name == partName); @@ -455,18 +444,18 @@ public string GenerateFieldNameFromDisplayName(string partName, string displayNa { return displayName; } - else - { - fieldDefinitions = typePart.PartDefinition.Fields.ToArray(); - } + + fieldDefinitions = typePart.PartDefinition.Fields.ToList(); } else { - fieldDefinitions = part.Fields.ToArray(); + fieldDefinitions = part.Fields.ToList(); } while (fieldDefinitions.Any(x => string.Equals(displayName.Trim(), x.Name.Trim(), StringComparison.OrdinalIgnoreCase))) + { displayName = VersionName(displayName); + } return displayName; } @@ -481,7 +470,7 @@ private static string VersionName(string name) version = version > 0 ? ++version : 2; // This could unintentionally chomp something that looks like a version. - name = string.Join("-", nameParts.Take(nameParts.Length - 1)); + name = string.Join('-', nameParts.Take(nameParts.Length - 1)); } else { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/DefaultStereotypesProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/DefaultStereotypesProvider.cs index b3affbc06ba..5c647b26cd4 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/DefaultStereotypesProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/DefaultStereotypesProvider.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace OrchardCore.ContentTypes.Services { @@ -11,10 +12,14 @@ public DefaultStereotypesProvider(IContentDefinitionService contentDefinitionSer _contentDefinitionService = contentDefinitionService; } - public IEnumerable GetStereotypes() + public async Task> GetStereotypesAsync() { // Harvest all available stereotypes by finding out about the stereotype of all content types - var stereotypes = _contentDefinitionService.GetTypes().Where(x => x.Settings["Stereotype"] != null).Select(x => x.Settings["Stereotype"].ToString()).Distinct(); + var stereotypes = (await _contentDefinitionService.GetTypesAsync()) + .Where(x => x.Settings["Stereotype"] != null) + .Select(x => x.Settings["Stereotype"].ToString()) + .Distinct(); + return stereotypes.Select(x => new StereotypeDescription { DisplayName = x, Stereotype = x }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IContentDefinitionService.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IContentDefinitionService.cs index d211deed663..a9358d426d8 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IContentDefinitionService.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IContentDefinitionService.cs @@ -1,40 +1,160 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.ViewModels; -namespace OrchardCore.ContentTypes.Services +namespace OrchardCore.ContentTypes.Services; + +public interface IContentDefinitionService { - public interface IContentDefinitionService - { - IEnumerable LoadTypes(); - IEnumerable GetTypes(); - EditTypeViewModel LoadType(string name); - EditTypeViewModel GetType(string name); - ContentTypeDefinition AddType(string name, string displayName); - void RemoveType(string name, bool deleteContent); - void AddPartToType(string partName, string typeName); - void AddReusablePartToType(string name, string displayName, string description, string partName, string typeName); - void RemovePartFromType(string partName, string typeName); - string GenerateContentTypeNameFromDisplayName(string displayName); - string GenerateFieldNameFromDisplayName(string partName, string displayName); - - IEnumerable LoadParts(bool metadataPartsOnly); - IEnumerable GetParts(bool metadataPartsOnly); - EditPartViewModel LoadPart(string name); - EditPartViewModel GetPart(string name); - EditPartViewModel AddPart(CreatePartViewModel partViewModel); - void RemovePart(string name); - - IEnumerable GetFields(); - void AddFieldToPart(string fieldName, string fieldTypeName, string partName); - void AddFieldToPart(string fieldName, string displayName, string fieldTypeName, string partName); - void RemoveFieldFromPart(string fieldName, string partName); - void AlterField(EditPartViewModel partViewModel, EditFieldViewModel fieldViewModel); - - void AlterTypePart(EditTypePartViewModel partViewModel); - - void AlterTypePartsOrder(ContentTypeDefinition typeDefinition, string[] partNames); - void AlterPartFieldsOrder(ContentPartDefinition partDefinition, string[] fieldNames); - } + Task> LoadTypesAsync(); + + Task> GetTypesAsync(); + + Task LoadTypeAsync(string name); + + Task GetTypeAsync(string name); + + Task AddTypeAsync(string name, string displayName); + + Task RemoveTypeAsync(string name, bool deleteContent); + + Task AddPartToTypeAsync(string partName, string typeName); + + Task AddReusablePartToTypeAsync(string name, string displayName, string description, string partName, string typeName); + + Task RemovePartFromTypeAsync(string partName, string typeName); + + Task GenerateContentTypeNameFromDisplayNameAsync(string displayName); + + Task GenerateFieldNameFromDisplayNameAsync(string partName, string displayName); + + Task> LoadPartsAsync(bool metadataPartsOnly); + + Task> GetPartsAsync(bool metadataPartsOnly); + + Task LoadPartAsync(string name); + + Task GetPartAsync(string name); + + Task AddPartAsync(CreatePartViewModel partViewModel); + + Task RemovePartAsync(string name); + + Task> GetFieldsAsync(); + + Task AddFieldToPartAsync(string fieldName, string fieldTypeName, string partName); + + Task AddFieldToPartAsync(string fieldName, string displayName, string fieldTypeName, string partName); + + Task RemoveFieldFromPartAsync(string fieldName, string partName); + + Task AlterFieldAsync(EditPartViewModel partViewModel, EditFieldViewModel fieldViewModel); + + Task AlterTypePartAsync(EditTypePartViewModel partViewModel); + + Task AlterTypePartsOrderAsync(ContentTypeDefinition typeDefinition, string[] partNames); + + Task AlterPartFieldsOrderAsync(ContentPartDefinition partDefinition, string[] fieldNames); + + [Obsolete($"Instead, utilize the {nameof(LoadTypesAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable LoadTypes() +=> LoadTypesAsync().GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(GetTypesAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable GetTypes() + => GetTypesAsync().GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(LoadTypeAsync)} method. This current method is slated for removal in upcoming releases.")] + EditTypeViewModel LoadType(string name) + => LoadTypeAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(GetTypeAsync)} method. This current method is slated for removal in upcoming releases.")] + EditTypeViewModel GetType(string name) + => GetTypeAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AddTypeAsync)} method. This current method is slated for removal in upcoming releases.")] + ContentTypeDefinition AddType(string name, string displayName) + => AddTypeAsync(name, displayName).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(RemoveTypeAsync)} method. This current method is slated for removal in upcoming releases.")] + void RemoveType(string name, bool deleteContent) + => RemoveTypeAsync(name, deleteContent).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AddPartToTypeAsync)} method. This current method is slated for removal in upcoming releases.")] + void AddPartToType(string partName, string typeName) + => AddPartToTypeAsync(partName, typeName).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AddReusablePartToTypeAsync)} method. This current method is slated for removal in upcoming releases.")] + void AddReusablePartToType(string name, string displayName, string description, string partName, string typeName) + => AddReusablePartToTypeAsync(name, displayName, description, partName, typeName).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(RemovePartFromTypeAsync)} method. This current method is slated for removal in upcoming releases.")] + void RemovePartFromType(string partName, string typeName) + => RemovePartFromTypeAsync(partName, typeName); + + [Obsolete($"Instead, utilize the {nameof(GenerateContentTypeNameFromDisplayNameAsync)} method. This current method is slated for removal in upcoming releases.")] + string GenerateContentTypeNameFromDisplayName(string displayName) + => GenerateContentTypeNameFromDisplayNameAsync(displayName).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(GenerateFieldNameFromDisplayNameAsync)} method. This current method is slated for removal in upcoming releases.")] + string GenerateFieldNameFromDisplayName(string partName, string displayName) + => GenerateFieldNameFromDisplayNameAsync(partName, displayName).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(LoadPartsAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable LoadParts(bool metadataPartsOnly) + => LoadPartsAsync(metadataPartsOnly).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(GetPartsAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable GetParts(bool metadataPartsOnly) + => GetPartsAsync(metadataPartsOnly).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(LoadPartAsync)} method. This current method is slated for removal in upcoming releases.")] + EditPartViewModel LoadPart(string name) + => LoadPartAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(GetPartAsync)} method. This current method is slated for removal in upcoming releases.")] + EditPartViewModel GetPart(string name) + => GetPartAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AddPartAsync)} method. This current method is slated for removal in upcoming releases.")] + EditPartViewModel AddPart(CreatePartViewModel partViewModel) + => AddPartAsync(partViewModel).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(RemovePartAsync)} method. This current method is slated for removal in upcoming releases.")] + void RemovePart(string name) + => RemovePartAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(GetFieldsAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable GetFields() + => GetFieldsAsync().GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AddFieldToPartAsync)} method. This current method is slated for removal in upcoming releases.")] + void AddFieldToPart(string fieldName, string fieldTypeName, string partName) + => AddFieldToPartAsync(fieldName, fieldTypeName, partName).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AddFieldToPartAsync)} method. This current method is slated for removal in upcoming releases.")] + void AddFieldToPart(string fieldName, string displayName, string fieldTypeName, string partName) + => AddFieldToPartAsync(fieldName, displayName, fieldTypeName, partName).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(RemoveFieldFromPartAsync)} method. This current method is slated for removal in upcoming releases.")] + void RemoveFieldFromPart(string fieldName, string partName) + => RemoveFieldFromPartAsync(fieldName, partName).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AlterFieldAsync)} method. This current method is slated for removal in upcoming releases.")] + void AlterField(EditPartViewModel partViewModel, EditFieldViewModel fieldViewModel) + => AlterFieldAsync(partViewModel, fieldViewModel).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AlterTypePartAsync)} method. This current method is slated for removal in upcoming releases.")] + void AlterTypePart(EditTypePartViewModel partViewModel) + => AlterTypePartAsync(partViewModel).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AlterTypePartsOrderAsync)} method. This current method is slated for removal in upcoming releases.")] + void AlterTypePartsOrder(ContentTypeDefinition typeDefinition, string[] partNames) + => AlterTypePartsOrderAsync(typeDefinition, partNames).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(AlterPartFieldsOrderAsync)} method. This current method is slated for removal in upcoming releases.")] + void AlterPartFieldsOrder(ContentPartDefinition partDefinition, string[] fieldNames) + => AlterPartFieldsOrderAsync(partDefinition, fieldNames).GetAwaiter().GetResult(); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IStereotypeService.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IStereotypeService.cs index 69944086637..069bd333a16 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IStereotypeService.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IStereotypeService.cs @@ -1,8 +1,14 @@ +using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace OrchardCore.ContentTypes.Services; public interface IStereotypeService { - IEnumerable GetStereotypes(); + Task> GetStereotypesAsync(); + + [Obsolete($"Instead, utilize the {nameof(GetStereotypesAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable GetStereotypes() + => GetStereotypesAsync().GetAwaiter().GetResult(); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IStereotypesProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IStereotypesProvider.cs index f8b5fa38578..10b3f06b44d 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IStereotypesProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/IStereotypesProvider.cs @@ -1,15 +1,14 @@ +using System; using System.Collections.Generic; +using System.Threading.Tasks; -namespace OrchardCore.ContentTypes.Services +namespace OrchardCore.ContentTypes.Services; + +public interface IStereotypesProvider { - public interface IStereotypesProvider - { - IEnumerable GetStereotypes(); - } + Task> GetStereotypesAsync(); - public class StereotypeDescription - { - public string Stereotype { get; set; } - public string DisplayName { get; set; } - } + [Obsolete($"Instead, utilize the {nameof(GetStereotypesAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable GetStereotypes() + => GetStereotypesAsync().GetAwaiter().GetResult(); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/StereotypeDescription.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/StereotypeDescription.cs new file mode 100644 index 00000000000..fcf1ef3ff22 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/StereotypeDescription.cs @@ -0,0 +1,7 @@ +namespace OrchardCore.ContentTypes.Services; + +public class StereotypeDescription +{ + public string Stereotype { get; set; } + public string DisplayName { get; set; } +} diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/StereotypeService.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/StereotypeService.cs index 66c4c1dc423..64539e6c21f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/StereotypeService.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/StereotypeService.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using System.Linq; +using System.Threading.Tasks; namespace OrchardCore.ContentTypes.Services { @@ -12,9 +12,16 @@ public StereotypeService(IEnumerable providers) _providers = providers; } - public IEnumerable GetStereotypes() + public async Task> GetStereotypesAsync() { - return _providers.SelectMany(x => x.GetStereotypes()); + var descriptions = new List(); + + foreach (var provider in _providers) + { + descriptions.AddRange(await provider.GetStereotypesAsync()); + } + + return descriptions; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/Edit.cshtml index 39ae97fb931..6ddbeac0611 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/Edit.cshtml @@ -2,33 +2,49 @@ @using OrchardCore.ContentManagement.Metadata.Models @using OrchardCore.ContentManagement.Metadata.Settings @using OrchardCore.Mvc.Utilities +@using System.Linq @inject OrchardCore.ContentManagement.Metadata.IContentDefinitionManager ContentDefinitionManager @inject OrchardCore.ContentTypes.Services.IContentDefinitionService ContentDefinitionService @{ var typePart = Model.TypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.Name, Model.TypeDefinition.Name, StringComparison.OrdinalIgnoreCase)); - var partDefinitions = Model.TypeDefinition.Parts - .Select(part => + + var sorted = new List(); + + foreach (var part in Model.TypeDefinition.Parts) + { + var partDefinition = await ContentDefinitionManager.GetPartDefinitionAsync(part.PartDefinition.Name); + + if (partDefinition == null) { - var defaultPosition = ContentDefinitionManager.GetPartDefinition(part.PartDefinition.Name)?.DefaultPosition() ?? "5"; - return new { Part = part, Order = int.Parse(part.GetSettings().Position ?? defaultPosition) }; - }) - .OrderBy(x => x.Order) - .Select(x => x.Part); + continue; + } + + var defaultPosition = partDefinition.DefaultPosition() ?? "5"; + + sorted.Add( + new + { + Part = part, + Order = int.Parse(part.GetSettings().Position ?? defaultPosition) + }); + } + + var partDefinitions = sorted.OrderBy(x => x.Order).Select(x => (ContentTypePartDefinition)x.Part).ToList(); - var fieldDefintions = new List(); + var fieldDefinitions = new List(); if (typePart?.PartDefinition?.Fields != null) { - fieldDefintions = typePart.PartDefinition.Fields + fieldDefinitions = typePart.PartDefinition.Fields .Select(field => new { Field = field, Order = int.Parse(field.GetSettings().Position ?? "0") }) .OrderBy(x => x.Order) .Select(x => x.Field) .ToList(); } - var fields = ContentDefinitionService.GetFields().ToList(); + var fields = (await ContentDefinitionService.GetFieldsAsync()).ToList(); }

@RenderTitleSegments(T["Edit Content Type - {0}", Model.TypeDefinition.DisplayName])

@@ -47,35 +63,35 @@ @await DisplayAsync(Model.Editor) - @if (fieldDefintions.Count > 0 || fields.Count > 0) + @if (fieldDefinitions.Count > 0 || fields.Count > 0) {

@T["Fields"]

    - @foreach (var fieldDefintion in fieldDefintions) + @foreach (var fieldDefinition in fieldDefinitions) {
  • - @if (fields.Any(field => string.Equals(field.Name, fieldDefintion.FieldDefinition.Name, StringComparison.OrdinalIgnoreCase))) + @if (fields.Any(field => string.Equals(field.Name, fieldDefinition.FieldDefinition.Name, StringComparison.OrdinalIgnoreCase))) { - @T["Edit"] + @T["Edit"] } - @T["Remove"] + @T["Remove"]
    - @fieldDefintion.DisplayName() @fieldDefintion.FieldDefinition.Name.CamelFriendly() + @fieldDefinition.DisplayName() @fieldDefinition.FieldDefinition.Name.CamelFriendly() - @if (!string.IsNullOrEmpty(fieldDefintion.DisplayMode())) + @if (!string.IsNullOrEmpty(fieldDefinition.DisplayMode())) { - @fieldDefintion.DisplayMode() + @fieldDefinition.DisplayMode() } - @if (!string.IsNullOrEmpty(fieldDefintion.Editor())) + @if (!string.IsNullOrEmpty(fieldDefinition.Editor())) { - @fieldDefintion.Editor() + @fieldDefinition.Editor() }
    - +
  • }
@@ -94,7 +110,7 @@
    @foreach (var partDefinition in partDefinitions) { -
  • +
  • @partDefinition.DisplayName() @@ -142,8 +158,8 @@ diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/EditPart.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/EditPart.cshtml index db1a07169bf..3ebb0ee268b 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/EditPart.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/EditPart.cshtml @@ -12,7 +12,7 @@ .Select(x => x.Field) .ToList(); - var fields = ContentDefinitionService.GetFields().ToList(); + var fields = (await ContentDefinitionService.GetFieldsAsync()).ToList(); }

    @RenderTitleSegments(T["Edit Content Part - {0}", Model.DisplayName])

    diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ContentDefinitionDeploymentStep.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ContentDefinitionDeploymentStep.Fields.Edit.cshtml index cdc3ba705e0..98be4bbc1af 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ContentDefinitionDeploymentStep.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ContentDefinitionDeploymentStep.Fields.Edit.cshtml @@ -5,8 +5,8 @@ var contentTypes = (string[])Model.ContentTypes; var contentParts = (string[])Model.ContentParts; - var allTypes = ContentDefinitionManager.ListTypeDefinitions().OrderBy(d => d.Name); - var allParts = ContentDefinitionManager.ListPartDefinitions().OrderBy(d => d.Name); + var allTypes = (await ContentDefinitionManager.ListTypeDefinitionsAsync()).OrderBy(d => d.Name); + var allParts = (await ContentDefinitionManager.ListPartDefinitionsAsync()).OrderBy(d => d.Name); var avaParts = allParts.Where(x => !allTypes.Any(y => y.Name == x.Name)); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ContentDefinitionDeploymentStep.Fields.Summary.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ContentDefinitionDeploymentStep.Fields.Summary.cshtml index 3ab8df78e52..6cdd237b9e4 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ContentDefinitionDeploymentStep.Fields.Summary.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ContentDefinitionDeploymentStep.Fields.Summary.cshtml @@ -14,14 +14,14 @@ else var contentTypes = Model.Value.ContentTypes; var contentParts = Model.Value.ContentParts; - var allTypes = ContentDefinitionManager.ListTypeDefinitions(); - var allParts = ContentDefinitionManager.ListPartDefinitions(); + var allTypes = await ContentDefinitionManager.ListTypeDefinitionsAsync(); + var allParts = await ContentDefinitionManager.ListPartDefinitionsAsync(); var parts = allParts.Where(x => !allTypes.Any(y => y.Name == x.Name)); if (contentTypes?.Length > 0) { - foreach (var def in ContentDefinitionManager.ListTypeDefinitions()) + foreach (var def in await ContentDefinitionManager.ListTypeDefinitionsAsync()) { if (contentTypes.Contains(def.Name)) { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ReplaceContentDefinitionDeploymentStep.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ReplaceContentDefinitionDeploymentStep.Fields.Edit.cshtml index 67958e14502..69515409e74 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ReplaceContentDefinitionDeploymentStep.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ReplaceContentDefinitionDeploymentStep.Fields.Edit.cshtml @@ -5,8 +5,8 @@ var contentTypes = (string[])Model.ContentTypes; var contentParts = (string[])Model.ContentParts; - var allTypes = ContentDefinitionManager.ListTypeDefinitions(); - var allParts = ContentDefinitionManager.ListPartDefinitions(); + var allTypes = await ContentDefinitionManager.ListTypeDefinitionsAsync(); + var allParts = await ContentDefinitionManager.ListPartDefinitionsAsync(); var avaParts = allParts.Where(x => !allTypes.Any(y => y.Name == x.Name)); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ReplaceContentDefinitionDeploymentStep.Fields.Summary.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ReplaceContentDefinitionDeploymentStep.Fields.Summary.cshtml index 8c2955f9298..a70efe84f77 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ReplaceContentDefinitionDeploymentStep.Fields.Summary.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Items/ReplaceContentDefinitionDeploymentStep.Fields.Summary.cshtml @@ -14,14 +14,14 @@ else var contentTypes = Model.Value.ContentTypes; var contentParts = Model.Value.ContentParts; - var allTypes = ContentDefinitionManager.ListTypeDefinitions(); - var allParts = ContentDefinitionManager.ListPartDefinitions(); + var allTypes = await ContentDefinitionManager.ListTypeDefinitionsAsync(); + var allParts = await ContentDefinitionManager.ListPartDefinitionsAsync(); var parts = allParts.Where(x => !allTypes.Any(y => y.Name == x.Name)); if (contentTypes?.Length > 0) { - foreach (var def in ContentDefinitionManager.ListTypeDefinitions()) + foreach (var def in await ContentDefinitionManager.ListTypeDefinitionsAsync()) { if (contentTypes.Contains(def.Name)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs index 7ea58da0d5f..35681e1a269 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs @@ -55,7 +55,7 @@ public async Task BuildNavigationAsync(string name, NavigationBuilder builder) return; } - var contentTypeDefinitions = _contentDefinitionManager.ListTypeDefinitions().OrderBy(d => d.Name); + var contentTypeDefinitions = (await _contentDefinitionManager.ListTypeDefinitionsAsync()).OrderBy(d => d.Name); var contentTypes = contentTypeDefinitions.Where(ctd => ctd.IsCreatable()).OrderBy(ctd => ctd.DisplayName); await builder.AddAsync(S["Content"], NavigationConstants.AdminMenuContentPosition, async content => { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNodeDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNodeDriver.cs index 73907eb4290..612de61c76e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNodeDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNodeDriver.cs @@ -82,7 +82,7 @@ public override async Task UpdateAsync(ContentTypesAdminNode tre private async Task> GetListableContentTypeDefinitionsAsync() { - var contentTypeDefinitions = _contentDefinitionManager.ListTypeDefinitions(); + var contentTypeDefinitions = await _contentDefinitionManager.ListTypeDefinitionsAsync(); var listableContentTypeDefinitions = new List(); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNodeNavigationBuilder.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNodeNavigationBuilder.cs index 86931fd7098..a6643d2429b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNodeNavigationBuilder.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNodeNavigationBuilder.cs @@ -88,7 +88,7 @@ public async Task BuildNavigationAsync(MenuItem menuItem, NavigationBuilder buil private async Task> GetListableContentTypeDefinitionsAsync(ContentTypesAdminNode node) { - var contentTypeDefinitions = _contentDefinitionManager.ListTypeDefinitions(); + var contentTypeDefinitions = await _contentDefinitionManager.ListTypeDefinitionsAsync(); var listableContentTypeDefinitions = new List(); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Migrations.cs index 0fe04fae51e..3cbcae6204a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Migrations.cs @@ -1,6 +1,6 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; -using OrchardCore.Contents.AuditTrail.Models; using OrchardCore.Data.Migration; using OrchardCore.Modules; @@ -16,9 +16,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition(nameof(AuditTrailPart), part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("AuditTrailPart", part => part .Attachable() .WithDescription("Allows editors to enter a comment to be saved into the Audit Trail event when saving a content item.")); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/AdminController.cs index 55385023722..fb97405d0a8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/AdminController.cs @@ -91,7 +91,7 @@ public async Task List( string contentTypeId = "", string stereotype = "") { - var contentTypeDefinitions = _contentDefinitionManager.ListTypeDefinitions() + var contentTypeDefinitions = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .OrderBy(ctd => ctd.DisplayName) .ToList(); @@ -106,7 +106,7 @@ public async Task List( options.SelectedContentType = contentTypeId; } - // The filter is bound seperately and mapped to the options. + // The filter is bound separately and mapped to the options. // The options must still be bound so that options that are not filters are still bound. options.FilterResult = queryFilterResult; @@ -117,7 +117,7 @@ public async Task List( // When the selected content type is provided via the route or options a placeholder node is used to apply a filter. options.FilterResult.TryAddOrReplace(new ContentTypeFilterNode(options.SelectedContentType)); - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(options.SelectedContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(options.SelectedContentType); if (contentTypeDefinition == null) { return NotFound(); @@ -132,7 +132,7 @@ public async Task List( options.FilterResult.TryAddOrReplace(new StereotypeFilterNode(stereotype)); var availableContentTypeDefinitions = contentTypeDefinitions - .Where(defintion => defintion.StereotypeEquals(stereotype, StringComparison.OrdinalIgnoreCase)) + .Where(definition => definition.StereotypeEquals(stereotype, StringComparison.OrdinalIgnoreCase)) .ToArray(); if (availableContentTypeDefinitions.Length > 0) @@ -343,7 +343,7 @@ public Task CreatePOST(string id, [Bind(Prefix = "submit.Save")] { await _contentManager.SaveDraftAsync(contentItem); - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); await _notifier.SuccessAsync(string.IsNullOrWhiteSpace(typeDefinition?.DisplayName) ? H["Your content draft has been saved."] @@ -361,7 +361,7 @@ public async Task CreateAndPublishPOST(string id, [Bind(Prefix = } var stayOnSamePage = submitPublish == "submit.PublishAndContinue"; - // Pass a dummy contentitem to the authorization check to check for "own" variations permissions. + // Pass a dummy content item to the authorization check to check for "own" variations permissions. if (!await _authorizationService.AuthorizeContentTypeAsync(User, CommonPermissions.PublishContent, id, CurrentUserId())) { return Forbid(); @@ -371,7 +371,7 @@ public async Task CreateAndPublishPOST(string id, [Bind(Prefix = { await _contentManager.PublishAsync(contentItem); - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); await _notifier.SuccessAsync(string.IsNullOrWhiteSpace(typeDefinition.DisplayName) ? H["Your content has been published."] @@ -426,7 +426,7 @@ public Task EditPOST(string contentItemId, [Bind(Prefix = "submit { await _contentManager.SaveDraftAsync(contentItem); - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); await _notifier.SuccessAsync(string.IsNullOrWhiteSpace(typeDefinition?.DisplayName) ? H["Your content draft has been saved."] @@ -456,7 +456,7 @@ public async Task EditAndPublishPOST(string contentItemId, [Bind( { await _contentManager.PublishAsync(contentItem); - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); await _notifier.SuccessAsync(string.IsNullOrWhiteSpace(typeDefinition?.DisplayName) ? H["Your content has been published."] @@ -513,7 +513,7 @@ public async Task DiscardDraft(string contentItemId, string retur { await _contentManager.DiscardDraftAsync(contentItem); - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); await _notifier.SuccessAsync(string.IsNullOrWhiteSpace(typeDefinition?.DisplayName) ? H["The draft has been removed."] @@ -537,7 +537,7 @@ public async Task Remove(string contentItemId, string returnUrl) { await _contentManager.RemoveAsync(contentItem); - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); await _notifier.SuccessAsync(string.IsNullOrWhiteSpace(typeDefinition?.DisplayName) ? H["That content has been removed."] @@ -563,7 +563,7 @@ public async Task Publish(string contentItemId, string returnUrl) await _contentManager.PublishAsync(contentItem); - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); if (string.IsNullOrEmpty(typeDefinition?.DisplayName)) { @@ -593,7 +593,7 @@ public async Task Unpublish(string contentItemId, string returnUr await _contentManager.UnpublishAsync(contentItem); - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); if (string.IsNullOrEmpty(typeDefinition?.DisplayName)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ApiController.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ApiController.cs index f11bbfb15dc..e33ab9e48e1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ApiController.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Net; using System.Security.Claims; @@ -101,7 +100,7 @@ public async Task Post(ContentItem model, bool draft = false) if (contentItem == null) { - if (string.IsNullOrEmpty(model?.ContentType) || _contentDefinitionManager.GetTypeDefinition(model.ContentType) == null) + if (string.IsNullOrEmpty(model?.ContentType) || await _contentDefinitionManager.GetTypeDefinitionAsync(model.ContentType) == null) { return BadRequest(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Drivers/ContentsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Drivers/ContentsDriver.cs index 3bae29b8e8e..36bdb9d5d4e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Drivers/ContentsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Drivers/ContentsDriver.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using OrchardCore.ContentManagement; @@ -28,14 +29,14 @@ public ContentsDriver( _authorizationService = authorizationService; } - public override IDisplayResult Display(ContentItem contentItem, IUpdateModel updater) + public override async Task DisplayAsync(ContentItem contentItem, IUpdateModel updater) { // We add custom alternates. This could be done generically to all shapes coming from ContentDisplayDriver but right now it's // only necessary on this shape. Otherwise c.f. ContentPartDisplayDriver var context = _httpContextAccessor.HttpContext; var results = new List(); - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var contentsMetadataShape = Shape("ContentsMetadata", new ContentItemViewModel(contentItem)) .Location("Detail", "Content:before"); @@ -90,10 +91,10 @@ public override IDisplayResult Display(ContentItem contentItem, IUpdateModel upd return Combine(results.ToArray()); } - public override IDisplayResult Edit(ContentItem contentItem, IUpdateModel updater) + public override async Task EditAsync(ContentItem contentItem, IUpdateModel updater) { var context = _httpContextAccessor.HttpContext; - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var results = new List(); if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Handlers/FullTextAspectContentHandler.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Handlers/FullTextAspectContentHandler.cs index 6adead84417..90f6888a88b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Handlers/FullTextAspectContentHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Handlers/FullTextAspectContentHandler.cs @@ -35,18 +35,18 @@ IServiceProvider serviceProvider _serviceProvider = serviceProvider; } - public override Task GetContentItemAspectAsync(ContentItemAspectContext context) + public override async Task GetContentItemAspectAsync(ContentItemAspectContext context) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); if (contentTypeDefinition == null) { - return Task.CompletedTask; + return; } - return context.ForAsync(async fullTextAspect => + await context.ForAsync(async fullTextAspect => { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); var settings = contentTypeDefinition.GetSettings(); if (settings.IncludeDisplayText) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Indexing/ContentItemIndexCoordinator.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Indexing/ContentItemIndexCoordinator.cs index ae8b1ed789f..8ee8123ed7a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Indexing/ContentItemIndexCoordinator.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Indexing/ContentItemIndexCoordinator.cs @@ -35,7 +35,7 @@ public ContentItemIndexCoordinator( public async Task BuildIndexAsync(BuildIndexContext context) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); if (contentTypeDefinition == null) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/ContentAnchorTag.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/ContentAnchorTag.cs index 30b6af7c921..add0f027081 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/ContentAnchorTag.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/ContentAnchorTag.cs @@ -51,7 +51,7 @@ public async ValueTask WriteToAsync(List argumentsLi ContentItem createFor = null; Dictionary routeValues = null; - Dictionary customAttributes = new Dictionary(); + Dictionary customAttributes = new(); foreach (var argument in argumentsList) { @@ -222,7 +222,7 @@ public async ValueTask WriteToAsync(List argumentsLi else { var contentDefinitionManager = services.GetRequiredService(); - var typeDefinition = contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); writer.Write(encoder.Encode(typeDefinition.ToString())); } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Migrations.cs index e046bf6d70f..acaa816438b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -13,9 +14,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("CommonPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("CommonPart", builder => builder .Attachable() .WithDescription("Provides an editor for the common properties of a content item.")); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Security/ContentTypePermissions.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Security/ContentTypePermissions.cs index e0ce9bab255..1bfc7b9aadc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Security/ContentTypePermissions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Security/ContentTypePermissions.cs @@ -16,10 +16,10 @@ public ContentTypePermissions(IContentDefinitionManager contentDefinitionManager _contentDefinitionManager = contentDefinitionManager; } - public Task> GetPermissionsAsync() + public async Task> GetPermissionsAsync() { // manage rights only for Securable types - var securableTypes = _contentDefinitionManager.ListTypeDefinitions() + var securableTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(ctd => ctd.IsSecurable()); var result = new List(); @@ -32,7 +32,7 @@ public Task> GetPermissionsAsync() } } - return Task.FromResult(result.AsEnumerable()); + return result; } public IEnumerable GetDefaultStereotypes() diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Services/DefaultContentsAdminListFilterProvider.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Services/DefaultContentsAdminListFilterProvider.cs index e329bbdb5ca..3ff5c6a02cc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Services/DefaultContentsAdminListFilterProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Services/DefaultContentsAdminListFilterProvider.cs @@ -135,7 +135,7 @@ public void Build(QueryEngineBuilder builder) // Filter for a specific type. if (!string.IsNullOrEmpty(contentType)) { - var contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(contentType); + var contentTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(contentType); if (contentTypeDefinition != null) { // We display a specific type even if it's not listable so that admin pages @@ -156,7 +156,7 @@ public void Build(QueryEngineBuilder builder) var listAnyContentTypes = new List(); var listOwnContentTypes = new List(); - foreach (var ctd in contentDefinitionManager.ListTypeDefinitions()) + foreach (var ctd in await contentDefinitionManager.ListTypeDefinitionsAsync()) { if (!ctd.IsListable()) { @@ -211,7 +211,7 @@ public void Build(QueryEngineBuilder builder) // Filter for a specific stereotype. if (!string.IsNullOrEmpty(stereotype)) { - var contentTypeDefinitionNames = contentDefinitionManager.ListTypeDefinitions() + var contentTypeDefinitionNames = (await contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(definition => definition.StereotypeEquals(stereotype, StringComparison.OrdinalIgnoreCase)) .Select(definition => definition.Name) .ToList(); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/ContentTypesSitemapSourceDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/ContentTypesSitemapSourceDriver.cs index 0a66205dd61..c168a46710f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/ContentTypesSitemapSourceDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/ContentTypesSitemapSourceDriver.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using OrchardCore.DisplayManagement.Handlers; @@ -11,13 +10,13 @@ namespace OrchardCore.Contents.Sitemaps { public class ContentTypesSitemapSourceDriver : DisplayDriver { - private readonly IEnumerable _routeableContentTypeDefinitionProviders; + private readonly IRouteableContentTypeCoordinator _routeableContentTypeCoordinator; public ContentTypesSitemapSourceDriver( - IEnumerable routeableContentTypeDefinitionProviders + IRouteableContentTypeCoordinator routeableContentTypeCoordinator ) { - _routeableContentTypeDefinitionProviders = routeableContentTypeDefinitionProviders; + _routeableContentTypeCoordinator = routeableContentTypeCoordinator; } public override IDisplayResult Display(ContentTypesSitemapSource sitemapSource) @@ -28,10 +27,9 @@ public override IDisplayResult Display(ContentTypesSitemapSource sitemapSource) ); } - public override IDisplayResult Edit(ContentTypesSitemapSource sitemapSource, IUpdateModel updater) + public override async Task EditAsync(ContentTypesSitemapSource sitemapSource, IUpdateModel updater) { - var contentTypeDefinitions = _routeableContentTypeDefinitionProviders - .SelectMany(x => x.ListRoutableTypeDefinitions()); + var contentTypeDefinitions = await _routeableContentTypeCoordinator.ListRoutableTypeDefinitionsAsync(); var entries = contentTypeDefinitions .Select(ctd => new ContentTypeSitemapEntryViewModel diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/ContentTypesSitemapSourceModifiedDateProvider.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/ContentTypesSitemapSourceModifiedDateProvider.cs index d20b6cc205b..df230bde0f3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/ContentTypesSitemapSourceModifiedDateProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/ContentTypesSitemapSourceModifiedDateProvider.cs @@ -31,8 +31,7 @@ ISession session if (source.IndexAll) { - var typesToIndex = _routeableContentTypeCoordinator - .ListRoutableTypeDefinitions() + var typesToIndex = (await _routeableContentTypeCoordinator.ListRoutableTypeDefinitionsAsync()) .Select(ctd => ctd.Name); var query = _session.Query() @@ -51,8 +50,7 @@ ISession session } else { - var typesToIndex = _routeableContentTypeCoordinator - .ListRoutableTypeDefinitions() + var typesToIndex = (await _routeableContentTypeCoordinator.ListRoutableTypeDefinitionsAsync()) .Where(ctd => source.ContentTypes.Any(s => string.Equals(ctd.Name, s.ContentTypeName))) .Select(ctd => ctd.Name); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/DefaultContentItemsQueryProvider.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/DefaultContentItemsQueryProvider.cs index 806f7710b82..e47ece9634e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/DefaultContentItemsQueryProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Sitemaps/DefaultContentItemsQueryProvider.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Threading.Tasks; using OrchardCore.ContentManagement; @@ -27,7 +26,7 @@ IRouteableContentTypeCoordinator routeableContentTypeCoordinator public async Task GetContentItemsAsync(ContentTypesSitemapSource source, ContentItemsQueryContext context) { - var routeableContentTypeDefinitions = _routeableContentTypeCoordinator.ListRoutableTypeDefinitions(); + var routeableContentTypeDefinitions = await _routeableContentTypeCoordinator.ListRoutableTypeDefinitionsAsync(); if (source.IndexAll) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/ViewComponents/SelectContentTypesViewComponent.cs b/src/OrchardCore.Modules/OrchardCore.Contents/ViewComponents/SelectContentTypesViewComponent.cs index 6b54de4531e..026715d0f4d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/ViewComponents/SelectContentTypesViewComponent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/ViewComponents/SelectContentTypesViewComponent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; @@ -17,11 +18,11 @@ public SelectContentTypesViewComponent(IContentDefinitionManager contentDefiniti _contentDefinitionManager = contentDefinitionManager; } - public IViewComponentResult Invoke(IEnumerable selectedContentTypes, string htmlName, string stereotype) + public async Task InvokeAsync(IEnumerable selectedContentTypes, string htmlName, string stereotype) { selectedContentTypes ??= Array.Empty(); - var contentTypes = ContentTypeSelection.Build(_contentDefinitionManager, selectedContentTypes); + var contentTypes = await ContentTypeSelection.BuildAsync(_contentDefinitionManager, selectedContentTypes); if (!string.IsNullOrEmpty(stereotype)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/ViewModels/SelectContentTypesViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Contents/ViewModels/SelectContentTypesViewModel.cs index 5a9e3cf3fd7..1a4ff7d0f39 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/ViewModels/SelectContentTypesViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/ViewModels/SelectContentTypesViewModel.cs @@ -1,5 +1,7 @@ +using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; @@ -16,10 +18,13 @@ public class ContentTypeSelection public bool IsSelected { get; set; } public ContentTypeDefinition ContentTypeDefinition { get; set; } + [Obsolete($"Instead, utilize the {nameof(BuildAsync)} method. This current method is slated for removal in upcoming releases.")] public static ContentTypeSelection[] Build(IContentDefinitionManager contentDefinitionManager, IEnumerable selectedContentTypes) + => BuildAsync(contentDefinitionManager, selectedContentTypes).GetAwaiter().GetResult(); + + public static async Task BuildAsync(IContentDefinitionManager contentDefinitionManager, IEnumerable selectedContentTypes) { - var contentTypes = contentDefinitionManager - .ListTypeDefinitions() + var contentTypes = (await contentDefinitionManager.ListTypeDefinitionsAsync()) .Select(x => new ContentTypeSelection { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Admin/Create.cshtml b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Admin/Create.cshtml index a60cf5a91b5..2f1365f2455 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Admin/Create.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Admin/Create.cshtml @@ -6,7 +6,7 @@ @{ ContentItem contentItem = Model.ContentItem; - var contentTypeDefinition = ContentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await ContentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var typeDisplayName = contentTypeDefinition?.DisplayName ?? contentItem.ContentType.CamelFriendly(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Admin/Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Admin/Edit.cshtml index 3f55bf652cf..815b2c59d11 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Admin/Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Admin/Edit.cshtml @@ -6,7 +6,7 @@ @{ ContentItem contentItem = Model.ContentItem; - var contentTypeDefinition = ContentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await ContentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var typeDisplayName = contentTypeDefinition?.DisplayName ?? contentItem.ContentType.CamelFriendly(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Download/Display.cshtml b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Download/Display.cshtml index 93965e0f885..2b04e3ba743 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Download/Display.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Download/Display.cshtml @@ -2,7 +2,7 @@ @inject IContentDefinitionManager ContentDefinitionManager @{ ContentItem contentItem = Model.ContentItem; - var contentTypeDefinition = ContentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await ContentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var typeDisplayName = contentTypeDefinition?.DisplayName ?? contentItem.ContentType.CamelFriendly(); var returnUrl = Context.Request.Query["returnUrl"]; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentDeploymentStep.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentDeploymentStep.Fields.Edit.cshtml index 029faf4ee3a..88af1383636 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentDeploymentStep.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentDeploymentStep.Fields.Edit.cshtml @@ -19,7 +19,7 @@
      - @foreach (var contentTypeDefinition in ContentDefinitionManager.ListTypeDefinitions().OrderBy(i => i.Name)) + @foreach (var contentTypeDefinition in (await ContentDefinitionManager.ListTypeDefinitionsAsync()).OrderBy(i => i.Name)) { var name = contentTypeDefinition.Name; var checkd = contentTypes?.Contains(name); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentDeploymentStep.Fields.Summary.cshtml b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentDeploymentStep.Fields.Summary.cshtml index b15cf032050..f4e3bb05da2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentDeploymentStep.Fields.Summary.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentDeploymentStep.Fields.Summary.cshtml @@ -8,7 +8,7 @@
      @T["Content"]
      @if (contentTypes != null && contentTypes.Length > 0) { - @foreach (var contentTypeDefinition in ContentDefinitionManager.ListTypeDefinitions()) + @foreach (var contentTypeDefinition in await ContentDefinitionManager.ListTypeDefinitionsAsync()) { if (contentTypes.Contains(contentTypeDefinition.Name)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentTypesAdminNode.Fields.TreeSummary.cshtml b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentTypesAdminNode.Fields.TreeSummary.cshtml index da808146a15..19d10cf16fc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentTypesAdminNode.Fields.TreeSummary.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentTypesAdminNode.Fields.TreeSummary.cshtml @@ -4,7 +4,7 @@ @inject OrchardCore.ContentManagement.Metadata.IContentDefinitionManager ContentDefinitionManager @{ - var allContentTypes = ContentDefinitionManager.ListTypeDefinitions(); + var allContentTypes = await ContentDefinitionManager.ListTypeDefinitionsAsync(); var selectedContentTypes = Model.Value.ContentTypes; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentTypesSitemapSource.SummaryAdmin.cshtml b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentTypesSitemapSource.SummaryAdmin.cshtml index cdcbcf63562..eede5e26c70 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentTypesSitemapSource.SummaryAdmin.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Views/Items/ContentTypesSitemapSource.SummaryAdmin.cshtml @@ -1,7 +1,7 @@ @model ShapeViewModel @inject OrchardCore.Sitemaps.Services.IRouteableContentTypeCoordinator RoutableContentTypeCoordinator @{ - var allRoutableContentTypes = RoutableContentTypeCoordinator.ListRoutableTypeDefinitions(); + var allRoutableContentTypes = await RoutableContentTypeCoordinator.ListRoutableTypeDefinitionsAsync(); var selectedContentTypes = Model.Value.ContentTypes ?? new ContentTypeSitemapEntry[] { }; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/ContentEventDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/ContentEventDisplayDriver.cs index 2c93e512895..74b8883a45f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/ContentEventDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/ContentEventDisplayDriver.cs @@ -30,7 +30,7 @@ public async override Task UpdateAsync(TActivity model, IUpdateM var viewModel = new TViewModel(); if (await updater.TryUpdateModelAsync(viewModel, Prefix, x => x.SelectedContentTypeNames)) { - model.ContentTypeFilter = FilterContentTypesQuery(viewModel.SelectedContentTypeNames).ToList(); + model.ContentTypeFilter = (await FilterContentTypesQueryAsync(viewModel.SelectedContentTypeNames)).ToList(); } return Edit(model); } @@ -39,9 +39,9 @@ public override IDisplayResult Display(TActivity activity) { return Combine( Shape($"{typeof(TActivity).Name}_Fields_Thumbnail", new ContentEventViewModel(activity)).Location("Thumbnail", "Content"), - Factory($"{typeof(TActivity).Name}_Fields_Design", ctx => + Factory($"{typeof(TActivity).Name}_Fields_Design", async ctx => { - var contentTypeDefinitions = ContentDefinitionManager.ListTypeDefinitions().ToDictionary(x => x.Name); + var contentTypeDefinitions = (await ContentDefinitionManager.ListTypeDefinitionsAsync()).ToDictionary(x => x.Name); var selectedContentTypeDefinitions = activity.ContentTypeFilter.Select(x => contentTypeDefinitions[x]).ToList(); var shape = new ContentEventViewModel @@ -58,9 +58,13 @@ public override IDisplayResult Display(TActivity activity) /// /// Filters out any content type that doesn't exist. /// + [Obsolete($"Instead, utilize the {nameof(FilterContentTypesQueryAsync)} method. This current method is slated for removal in upcoming releases.")] protected IEnumerable FilterContentTypesQuery(IEnumerable contentTypeNames) + => FilterContentTypesQueryAsync(contentTypeNames).GetAwaiter().GetResult(); + + protected async Task> FilterContentTypesQueryAsync(IEnumerable contentTypeNames) { - var contentTypeDefinitions = ContentDefinitionManager.ListTypeDefinitions().ToDictionary(x => x.Name); + var contentTypeDefinitions = (await ContentDefinitionManager.ListTypeDefinitionsAsync()).ToDictionary(x => x.Name); return contentTypeNames.Where(x => !string.IsNullOrWhiteSpace(x) && contentTypeDefinitions.ContainsKey(x)); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/CreateContentTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/CreateContentTaskDisplayDriver.cs index 259ef5f118c..c7790a78b0f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/CreateContentTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/CreateContentTaskDisplayDriver.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Rendering; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Contents.Workflows.Activities; @@ -16,9 +17,9 @@ public CreateContentTaskDisplayDriver(IContentDefinitionManager contentDefinitio _contentDefinitionManager = contentDefinitionManager; } - protected override void EditActivity(CreateContentTask activity, CreateContentTaskViewModel model) + protected override async ValueTask EditActivityAsync(CreateContentTask activity, CreateContentTaskViewModel model) { - model.AvailableContentTypes = _contentDefinitionManager.ListTypeDefinitions() + model.AvailableContentTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Select(x => new SelectListItem { Text = x.DisplayName, Value = x.Name }) .ToList(); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/UpdateContentTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/UpdateContentTaskDisplayDriver.cs index b456e73c9ba..7c52279f80e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/UpdateContentTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Drivers/UpdateContentTaskDisplayDriver.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Rendering; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; @@ -17,9 +18,9 @@ public UpdateContentTaskDisplayDriver(IContentDefinitionManager contentDefinitio _contentDefinitionManager = contentDefinitionManager; } - protected override void EditActivity(UpdateContentTask activity, UpdateContentTaskViewModel model) + protected override async ValueTask EditActivityAsync(UpdateContentTask activity, UpdateContentTaskViewModel model) { - model.AvailableContentTypes = _contentDefinitionManager.ListTypeDefinitions() + model.AvailableContentTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Select(x => new SelectListItem { Text = x.DisplayName, Value = x.Name }) .ToList(); diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/AdminMenu.cs index 232f79c7958..204b67e4032 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/AdminMenu.cs @@ -20,14 +20,14 @@ public AdminMenu( _customSettingsService = customSettingsService; } - public Task BuildNavigationAsync(string name, NavigationBuilder builder) + public async Task BuildNavigationAsync(string name, NavigationBuilder builder) { if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) { - return Task.CompletedTask; + return; } - foreach (var type in _customSettingsService.GetAllSettingsTypes()) + foreach (var type in await _customSettingsService.GetAllSettingsTypesAsync()) { builder .Add(S["Configuration"], configuration => configuration @@ -41,8 +41,6 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .LocalNav() ))); } - - return Task.CompletedTask; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentSource.cs index c691ffc727e..8f28a182cdd 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentSource.cs @@ -24,11 +24,11 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var settingsList = new List { new JProperty("name", "custom-settings") }; + var settingsList = new List { new("name", "custom-settings") }; var settingsTypes = customSettingsStep.IncludeAll - ? _customSettingsService.GetAllSettingsTypes().ToArray() - : _customSettingsService.GetSettingsTypes(customSettingsStep.SettingsTypeNames).ToArray(); + ? (await _customSettingsService.GetAllSettingsTypesAsync()).ToArray() + : (await _customSettingsService.GetSettingsTypesAsync(customSettingsStep.SettingsTypeNames)).ToArray(); foreach (var settingsType in settingsTypes) { diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentStepDriver.cs index 64a24822306..ecfece6f31b 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentStepDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentStepDriver.cs @@ -30,11 +30,11 @@ public override IDisplayResult Display(CustomSettingsDeploymentStep step) public override IDisplayResult Edit(CustomSettingsDeploymentStep step) { - return Initialize("CustomSettingsDeploymentStep_Fields_Edit", model => + return Initialize("CustomSettingsDeploymentStep_Fields_Edit", async model => { model.IncludeAll = step.IncludeAll; model.SettingsTypeNames = step.SettingsTypeNames; - model.AllSettingsTypeNames = _customSettingsService.GetAllSettingsTypeNames().ToArray(); + model.AllSettingsTypeNames = (await _customSettingsService.GetAllSettingsTypeNamesAsync()).ToArray(); }).Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Permissions.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Permissions.cs index f0ecc1b286b..229b5c79122 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Permissions.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Permissions.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -19,22 +18,20 @@ public Permissions(CustomSettingsService customSettingsService) _customSettingsService = customSettingsService; } - public Task> GetPermissionsAsync() + public async Task> GetPermissionsAsync() { var list = new List(); - foreach (var type in _customSettingsService.GetAllSettingsTypes()) + foreach (var type in await _customSettingsService.GetAllSettingsTypesAsync()) { list.Add(CreatePermissionForType(type)); } - return Task.FromResult(list.AsEnumerable()); + return list; } public static string CreatePermissionName(string name) - { - return string.Format(_manageCustomSettings.Name, name); - } + => string.Format(_manageCustomSettings.Name, name); public static Permission CreatePermissionForType(ContentTypeDefinition type) { @@ -46,8 +43,6 @@ public static Permission CreatePermissionForType(ContentTypeDefinition type) } public IEnumerable GetDefaultStereotypes() - { - return Enumerable.Empty(); - } + => Enumerable.Empty(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsService.cs index 6be5708738b..6b435e15017 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsService.cs @@ -19,7 +19,7 @@ public class CustomSettingsService private readonly IHttpContextAccessor _httpContextAccessor; private readonly IAuthorizationService _authorizationService; private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly Lazy> _settingsTypes; + private readonly Lazy>> _settingsTypes; public CustomSettingsService( ISiteService siteService, @@ -33,40 +33,51 @@ public CustomSettingsService( _httpContextAccessor = httpContextAccessor; _authorizationService = authorizationService; _contentDefinitionManager = contentDefinitionManager; - _settingsTypes = new Lazy>( - () => _contentDefinitionManager - .ListTypeDefinitions() - .Where(x => x.GetStereotype() == "CustomSettings") - .ToDictionary(x => x.Name)); + _settingsTypes = new Lazy>>(async () => await GetContentTypeAsync()); } + [Obsolete($"Instead, utilize the {nameof(GetAllSettingsTypeNamesAsync)} method. This current method is slated for removal in upcoming releases.")] public IEnumerable GetAllSettingsTypeNames() - { - return _settingsTypes.Value.Keys; - } + => GetAllSettingsTypeNamesAsync().GetAwaiter().GetResult(); + + public async Task> GetAllSettingsTypeNamesAsync() + => (await _settingsTypes.Value).Keys; + + [Obsolete($"Instead, utilize the {nameof(GetAllSettingsTypesAsync)} method. This current method is slated for removal in upcoming releases.")] public IEnumerable GetAllSettingsTypes() - { - return _settingsTypes.Value.Values; - } + => GetAllSettingsTypesAsync().GetAwaiter().GetResult(); + + public async Task> GetAllSettingsTypesAsync() + => (await _settingsTypes.Value).Values; + [Obsolete($"Instead, utilize the {nameof(GetSettingsTypesAsync)} method. This current method is slated for removal in upcoming releases.")] public IEnumerable GetSettingsTypes(params string[] settingsTypeNames) + => GetSettingsTypesAsync(settingsTypeNames).GetAwaiter().GetResult(); + + public async Task> GetSettingsTypesAsync(params string[] settingsTypeNames) { + var types = await _settingsTypes.Value; + var definitions = new List(); + foreach (var settingsTypeName in settingsTypeNames) { ContentTypeDefinition settingsType; - if (_settingsTypes.Value.TryGetValue(settingsTypeName, out settingsType)) + if (types.TryGetValue(settingsTypeName, out settingsType)) { - yield return settingsType; + definitions.Add(settingsType); } } + + return definitions; } public ContentTypeDefinition GetSettingsType(string settingsTypeName) - { - ContentTypeDefinition settingsType; + => GetSettingsTypeAsync(settingsTypeName).Result; - _settingsTypes.Value.TryGetValue(settingsTypeName, out settingsType); + public async Task GetSettingsTypeAsync(string settingsTypeName) + { + (await _settingsTypes.Value).TryGetValue(settingsTypeName, out var settingsType); return settingsType; } @@ -117,5 +128,15 @@ public async Task GetSettingsAsync(ISite site, ContentTypeDefinitio return contentItem; } + + private async Task> GetContentTypeAsync() + { + var contentTypes = await _contentDefinitionManager.ListTypeDefinitionsAsync(); + + var result = contentTypes.Where(x => x.StereotypeEquals("CustomSettings")) + .ToDictionary(x => x.Name); + + return result; + } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Demo/Migrations.cs index 5dec0ba2240..15aace2e8fa 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Data.Migration; @@ -12,9 +13,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterTypeDefinition("Foo", builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync("Foo", builder => builder .WithPart("TestContentPartA") .WithPart("TestContentPartB") ); diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Widgets/Drivers/FacebookPluginPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Widgets/Drivers/FacebookPluginPartDisplayDriver.cs index d5e4cbd5775..df841eba80c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Widgets/Drivers/FacebookPluginPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Widgets/Drivers/FacebookPluginPartDisplayDriver.cs @@ -16,30 +16,30 @@ namespace OrchardCore.Facebook.Widgets.Drivers public class FacebookPluginPartDisplayDriver : ContentPartDisplayDriver { private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly ILiquidTemplateManager _liquidTemplatemanager; + private readonly ILiquidTemplateManager _liquidTemplateManager; protected readonly IStringLocalizer S; public FacebookPluginPartDisplayDriver( IContentDefinitionManager contentDefinitionManager, - ILiquidTemplateManager liquidTemplatemanager, + ILiquidTemplateManager liquidTemplateManager, IStringLocalizer localizer) { _contentDefinitionManager = contentDefinitionManager; - _liquidTemplatemanager = liquidTemplatemanager; + _liquidTemplateManager = liquidTemplateManager; S = localizer; } public override IDisplayResult Display(FacebookPluginPart part) { return Combine( - Initialize("FacebookPluginPart", m => BuildViewModel(m, part)) + Initialize("FacebookPluginPart", async m => await BuildViewModelAsync(m, part)) .Location("Detail", "Content"), - Initialize("FacebookPluginPart_Summary", m => BuildViewModel(m, part)) + Initialize("FacebookPluginPart_Summary", async m => await BuildViewModelAsync(m, part)) .Location("Summary", "Content") ); } - private void BuildViewModel(FacebookPluginPartViewModel model, FacebookPluginPart part) + private async Task BuildViewModelAsync(FacebookPluginPartViewModel model, FacebookPluginPart part) { if (model == null) { @@ -47,29 +47,29 @@ private void BuildViewModel(FacebookPluginPartViewModel model, FacebookPluginPar } model.FacebookPluginPart = part ?? throw new ArgumentNullException(nameof(part)); - model.Settings = GetFacebookPluginPartSettings(part); + model.Settings = await GetFacebookPluginPartSettingsAsync(part); model.Liquid = part.Liquid; model.ContentItem = part.ContentItem; } public override IDisplayResult Edit(FacebookPluginPart part) { - return Initialize("FacebookPluginPart_Edit", model => + return Initialize("FacebookPluginPart_Edit", async model => { - model.Settings = GetFacebookPluginPartSettings(part); + model.Settings = await GetFacebookPluginPartSettingsAsync(part); model.FacebookPluginPart = part; model.Liquid = string.IsNullOrWhiteSpace(part.Liquid) ? model.Settings.Liquid : part.Liquid; }); } - private FacebookPluginPartSettings GetFacebookPluginPartSettings(FacebookPluginPart part) + private async Task GetFacebookPluginPartSettingsAsync(FacebookPluginPart part) { if (part == null) { throw new ArgumentNullException(nameof(part)); } - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(FacebookPluginPart))); return contentTypePartDefinition.GetSettings(); } @@ -80,7 +80,7 @@ public override async Task UpdateAsync(FacebookPluginPart model, if (await updater.TryUpdateModelAsync(viewModel, Prefix, t => t.Liquid)) { - if (!string.IsNullOrEmpty(viewModel.Liquid) && !_liquidTemplatemanager.Validate(viewModel.Liquid, out var errors)) + if (!string.IsNullOrEmpty(viewModel.Liquid) && !_liquidTemplateManager.Validate(viewModel.Liquid, out var errors)) { updater.ModelState.AddModelError(nameof(model.Liquid), S["The FaceBook Body doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]); } diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Widgets/WidgetMigrations.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Widgets/WidgetMigrations.cs index 09573b38007..8c876a063f4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Widgets/WidgetMigrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Widgets/WidgetMigrations.cs @@ -23,9 +23,9 @@ public WidgetMigrations(IRecipeMigrator recipeMigrator, IContentDefinitionManage public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition(nameof(FacebookPluginPart), builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(FacebookPluginPart), builder => builder .Attachable() - .WithDescription("Provides a facebook plugin part to create facebook social plugin widgets.")); + .WithDescription("Provides a Facebook plugin part to create Facebook social plugin widgets.")); await _recipeMigrator.ExecuteAsync($"Widgets/migration{RecipesConstants.RecipeExtension}", this); return 1; diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Controllers/AdminController.cs index 8ff966dce0f..5070d985e67 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Controllers/AdminController.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; using OrchardCore.ContentManagement.Metadata; @@ -36,7 +37,7 @@ public AdminController( _updateModelAccessor = updateModelAccessor; } - public async Task BuildEditor(string id, string prefix, string prefixesName, string contentTypesName, string contentItemsName, string targetId, bool flowmetadata, string parentContentType, string partName) + public async Task BuildEditor(string id, string prefix, string prefixesName, string contentTypesName, string contentItemsName, string targetId, bool flowMetadata, string parentContentType, string partName) { if (string.IsNullOrWhiteSpace(id)) { @@ -47,15 +48,15 @@ public async Task BuildEditor(string id, string prefix, string pr // Does this editor need the flow metadata editor? string cardCollectionType = null; - int colSize = 12; + var colSize = 12; IEnumerable containedContentTypes = null; - if (flowmetadata) + if (flowMetadata) { var metadata = new FlowMetadata(); contentItem.Weld(metadata); - colSize = (int)Math.Round((double)metadata.Size / 100.0 * 12); - containedContentTypes = GetContainedContentTypes(parentContentType, partName); + colSize = (int)Math.Round(metadata.Size / 100.0 * 12); + containedContentTypes = await GetContainedContentTypesAsync(parentContentType, partName); cardCollectionType = nameof(FlowPart); } @@ -64,36 +65,36 @@ public async Task BuildEditor(string id, string prefix, string pr cardCollectionType = nameof(BagPart); } - //Create a Card Shape + // Create a Card Shape dynamic contentCard = await _shapeFactory.New.ContentCard( - //Updater is the controller for AJAX Requests + // Updater is the controller for AJAX Requests Updater: _updateModelAccessor.ModelUpdater, - //Shape Specific + // Shape Specific CollectionShapeType: cardCollectionType, ContentItem: contentItem, BuildEditor: true, ParentContentType: parentContentType, CollectionPartName: partName, ContainedContentTypes: containedContentTypes, - //Card Specific Properties + // Card Specific Properties TargetId: targetId, Inline: true, CanMove: true, CanDelete: true, - //Input hidden - //Prefixes + // Input hidden + // Prefixes PrefixValue: prefix, PrefixesId: prefixesName.Replace('.', '_'), PrefixesName: prefixesName, - //ContentTypes + // ContentTypes ContentTypesId: contentTypesName.Replace('.', '_'), ContentTypesName: contentTypesName, - //ContentItems + // ContentItems ContentItemsId: contentItemsName.Replace('.', '_'), ContentItemsName: contentItemsName ); - //Only Add ColumnSize Property if Part has FlowMetadata - if (flowmetadata) + // Only Add ColumnSize Property if Part has FlowMetadata + if (flowMetadata) { contentCard.ColumnSize = colSize; } @@ -105,18 +106,30 @@ public async Task BuildEditor(string id, string prefix, string pr return View("Display", model); } - private IEnumerable GetContainedContentTypes(string contentType, string partName) + private async Task> GetContainedContentTypesAsync(string contentType, string partName) { - var settings = _contentDefinitionManager.GetTypeDefinition(contentType)?.Parts.SingleOrDefault(x => x.Name == partName)?.GetSettings(); + var settings = (await _contentDefinitionManager.GetTypeDefinitionAsync(contentType))?.Parts.SingleOrDefault(x => x.Name == partName)?.GetSettings(); - if (settings == null || settings.ContainedContentTypes == null || !settings.ContainedContentTypes.Any()) + if (settings?.ContainedContentTypes?.Length == 0) { - return _contentDefinitionManager.ListTypeDefinitions().Where(t => t.GetStereotype() == "Widget"); + return (await _contentDefinitionManager.ListTypeDefinitionsAsync()).Where(t => t.StereotypeEquals("Widget")); } - return settings.ContainedContentTypes - .Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType)) - .Where(t => t != null && t.GetStereotype() == "Widget"); + var definitions = new List(); + + foreach (var ct in settings.ContainedContentTypes) + { + var definition = await _contentDefinitionManager.GetTypeDefinitionAsync(ct); + + if (definition == null || !definition.StereotypeEquals("Widget")) + { + continue; + } + + definitions.Add(definition); + } + + return definitions; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/BagPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/BagPartDisplayDriver.cs index 2ab7eca9ed5..18019918baf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/BagPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/BagPartDisplayDriver.cs @@ -14,7 +14,6 @@ using OrchardCore.ContentManagement.Display.Models; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; -using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Contents; using OrchardCore.DisplayManagement.Notify; using OrchardCore.DisplayManagement.Views; @@ -58,7 +57,7 @@ IAuthorizationService authorizationService public override IDisplayResult Display(BagPart bagPart, BuildPartDisplayContext context) { - var hasItems = bagPart.ContentItems.Any(); + var hasItems = bagPart.ContentItems.Count > 0; return Initialize(hasItems ? "BagPart" : "BagPart_Empty", m => { @@ -148,7 +147,7 @@ public override async Task UpdateAsync(BagPart part, UpdatePartE if (await AuthorizeAsync(contentDefinitionManager, CommonPermissions.DeleteContent, existingContentItem)) { // at this point the user has permission to delete a securable item or the type isn't securable - // if the existsing content id isn't in the requested ids, don't add the content item... meaning the user deleted it + // if the existing content id isn't in the requested ids, don't add the content item... meaning the user deleted it if (!model.ContentItems.Contains(existingContentItem.ContentItemId)) { continue; @@ -179,12 +178,7 @@ private async Task> GetAccessibleWidgetsAsyn Deletable = true, }; - if (IsSecurable(contentDefinitionManager, contentItem.ContentType, out var contentTypeDefinition)) - { - widget.Viewable = await AuthorizeAsync(CommonPermissions.ViewContent, contentItem); - widget.Editable = await AuthorizeAsync(CommonPermissions.EditContent, contentItem); - widget.Deletable = await AuthorizeAsync(CommonPermissions.DeleteContent, contentItem); - } + var contentTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); if (contentTypeDefinition == null) { @@ -195,6 +189,13 @@ private async Task> GetAccessibleWidgetsAsyn continue; } + if (contentTypeDefinition.IsSecurable()) + { + widget.Viewable = await AuthorizeAsync(CommonPermissions.ViewContent, contentItem); + widget.Editable = await AuthorizeAsync(CommonPermissions.EditContent, contentItem); + widget.Deletable = await AuthorizeAsync(CommonPermissions.DeleteContent, contentItem); + } + widget.ContentTypeDefinition = contentTypeDefinition; if (widget.Editable || widget.Viewable) @@ -208,7 +209,9 @@ private async Task> GetAccessibleWidgetsAsyn private async Task AuthorizeAsync(IContentDefinitionManager contentDefinitionManager, Permission permission, ContentItem contentItem) { - if (!IsSecurable(contentDefinitionManager, contentItem.ContentType, out _)) + var contentType = await contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); + + if (contentType?.IsSecurable() ?? false) { return true; } @@ -216,19 +219,8 @@ private async Task AuthorizeAsync(IContentDefinitionManager contentDefinit return await AuthorizeAsync(permission, contentItem); } - private async Task AuthorizeAsync(Permission permission, ContentItem contentItem) - { - return await _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, permission, contentItem); - } - - private static bool IsSecurable(IContentDefinitionManager contentDefinitionManager, string contentType, out ContentTypeDefinition contentTypeDefinition) - { - contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(contentType); - - var settings = contentTypeDefinition?.GetSettings(); - - return settings?.Securable ?? false; - } + private Task AuthorizeAsync(Permission permission, ContentItem contentItem) + => _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, permission, contentItem); private async Task> GetContainedContentTypesAsync(ContentTypePartDefinition typePartDefinition) { @@ -237,15 +229,28 @@ private async Task> GetContainedContentTypesA if (settings.ContainedStereotypes != null && settings.ContainedStereotypes.Length > 0) { - contentTypes = _contentDefinitionManager.ListTypeDefinitions() + contentTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(contentType => contentType.HasStereotype() && settings.ContainedStereotypes.Contains(contentType.GetStereotype(), StringComparer.OrdinalIgnoreCase)); } else if (settings.ContainedContentTypes != null && settings.ContainedContentTypes.Length > 0) { - contentTypes = settings.ContainedContentTypes - .Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType)) - .Where(contentType => contentType != null); + var definitions = new List(); + + foreach (var contentType in settings.ContainedContentTypes) + { + var definition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentType); + + if (definition == null) + { + continue; + } + + definitions.Add(definition); + } + + contentTypes = definitions; } + var user = _httpContextAccessor.HttpContext.User; var accessibleContentTypes = new List(); diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/FlowPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/FlowPartDisplayDriver.cs index e71d46a80b9..9f361066cd5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/FlowPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/FlowPartDisplayDriver.cs @@ -46,7 +46,7 @@ ILogger logger public override IDisplayResult Display(FlowPart flowPart, BuildPartDisplayContext context) { - var hasItems = flowPart.Widgets.Any(); + var hasItems = flowPart.Widgets.Count > 0; return Initialize(hasItems ? "FlowPart" : "FlowPart_Empty", m => { @@ -60,7 +60,7 @@ public override IDisplayResult Edit(FlowPart flowPart, BuildPartEditorContext co { return Initialize(GetEditorShapeType(context), async model => { - var containedContentTypes = GetContainedContentTypes(context.TypePartDefinition); + var containedContentTypes = await GetContainedContentTypesAsync(context.TypePartDefinition); var notify = false; var existingWidgets = new List(); @@ -107,7 +107,7 @@ public override async Task UpdateAsync(FlowPart part, UpdatePart var contentItem = await _contentManager.NewAsync(model.ContentTypes[i]); var existingContentItem = part.Widgets.FirstOrDefault(x => string.Equals(x.ContentItemId, model.ContentItems[i], StringComparison.OrdinalIgnoreCase)); - // When the content item already exists merge its elements to preverse nested content item ids. + // When the content item already exists merge its elements to reverse nested content item ids. // All of the data for these merged items is then replaced by the model values on update, while a nested content item id is maintained. // This prevents nested items which rely on the content item id, i.e. the media attached field, losing their reference point. if (existingContentItem != null) @@ -128,16 +128,17 @@ public override async Task UpdateAsync(FlowPart part, UpdatePart return Edit(part, context); } - private IEnumerable GetContainedContentTypes(ContentTypePartDefinition typePartDefinition) + private async Task> GetContainedContentTypesAsync(ContentTypePartDefinition typePartDefinition) { var settings = typePartDefinition.GetSettings(); - if (settings.ContainedContentTypes == null || !settings.ContainedContentTypes.Any()) + if (settings?.ContainedContentTypes?.Length == 0) { - return _contentDefinitionManager.ListTypeDefinitions().Where(t => t.StereotypeEquals("Widget")); + return (await _contentDefinitionManager.ListTypeDefinitionsAsync()) + .Where(t => t.StereotypeEquals("Widget")); } - return _contentDefinitionManager.ListTypeDefinitions() + return (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(t => settings.ContainedContentTypes.Contains(t.Name) && t.StereotypeEquals("Widget")); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Migrations.cs index d3b6c69b061..d0b98cfcf6b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -14,13 +15,13 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("FlowPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("FlowPart", builder => builder .Attachable() .WithDescription("Provides a customizable body for your content item where you can build a content structure with widgets.")); - _contentDefinitionManager.AlterPartDefinition("BagPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("BagPart", builder => builder .Attachable() .Reusable() .WithDescription("Provides a collection behavior for your content item where you can place other content items.")); @@ -30,9 +31,9 @@ public int Create() } // This code can be removed in a later version. - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - _contentDefinitionManager.AlterPartDefinition("BagPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("BagPart", builder => builder .Attachable() .Reusable() .WithDescription("Provides a collection behavior for your content item where you can place other content items.")); @@ -42,9 +43,9 @@ public int UpdateFrom1() // Migrate PartSettings. This only needs to run on old content definition schemas. // This code can be removed in a later version. - public int UpdateFrom2() + public async Task UpdateFrom2Async() { - _contentDefinitionManager.MigratePartSettings(); + await _contentDefinitionManager.MigratePartSettingsAsync(); return 3; } diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Settings/BagPartSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Settings/BagPartSettingsDisplayDriver.cs index 18571bb50d0..8934d428263 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Settings/BagPartSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Settings/BagPartSettingsDisplayDriver.cs @@ -28,7 +28,7 @@ public BagPartSettingsDisplayDriver( public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater) { - return Initialize("BagPartSettings_Edit", model => + return Initialize("BagPartSettings_Edit", async model => { var settings = contentTypePartDefinition.GetSettings(); @@ -38,7 +38,7 @@ public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDef model.ContentTypes = new NameValueCollection(); model.Source = settings.ContainedStereotypes != null && settings.ContainedStereotypes.Length > 0 ? BagPartSettingType.Stereotypes : BagPartSettingType.ContentTypes; model.Stereotypes = string.Join(',', settings.ContainedStereotypes ?? Array.Empty()); - foreach (var contentTypeDefinition in _contentDefinitionManager.ListTypeDefinitions()) + foreach (var contentTypeDefinition in await _contentDefinitionManager.ListTypeDefinitionsAsync()) { model.ContentTypes.Add(contentTypeDefinition.Name, contentTypeDefinition.DisplayName); } diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Settings/FlowPartSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Settings/FlowPartSettingsDisplayDriver.cs index b4905bcc9bc..b204c09defb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Settings/FlowPartSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Settings/FlowPartSettingsDisplayDriver.cs @@ -22,13 +22,13 @@ public FlowPartSettingsDisplayDriver(IContentDefinitionManager contentDefinition public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater) { - return Initialize("FlowPartSettings_Edit", model => + return Initialize("FlowPartSettings_Edit", async model => { model.FlowPartSettings = contentTypePartDefinition.GetSettings(); model.ContainedContentTypes = model.FlowPartSettings.ContainedContentTypes; model.ContentTypes = new NameValueCollection(); - foreach (var contentTypeDefinition in _contentDefinitionManager.ListTypeDefinitions().Where(t => t.GetStereotype() == "Widget")) + foreach (var contentTypeDefinition in (await _contentDefinitionManager.ListTypeDefinitionsAsync()).Where(t => t.GetStereotype() == "Widget")) { model.ContentTypes.Add(contentTypeDefinition.Name, contentTypeDefinition.DisplayName); } diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Views/ContentCard-BagPart.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Flows/Views/ContentCard-BagPart.Edit.cshtml index 00bef8e6c07..7eb635c97a7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Views/ContentCard-BagPart.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Views/ContentCard-BagPart.Edit.cshtml @@ -4,7 +4,7 @@ @{ ContentItem contentItem = Model.ContentItem; - var contentType = ContentDefinitionManager.GetTypeDefinition(contentItem.ContentType).DisplayName; + var contentType = (await ContentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType))?.DisplayName; var collapsed = !Model.Inline; if (!ViewContext.ModelState.IsValid && ViewContext.ModelState.Keys.Any(key => key.StartsWith(Model.PrefixValue, StringComparison.OrdinalIgnoreCase))) diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Views/ContentCard-FlowPart.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Flows/Views/ContentCard-FlowPart.Edit.cshtml index 9f99b3283e7..de081a5d30a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Views/ContentCard-FlowPart.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Views/ContentCard-FlowPart.Edit.cshtml @@ -5,7 +5,7 @@ @{ var contentItem = (IContent)Model.ContentItem; - var contentTypeDisplayText = ContentDefinitionManager.GetTypeDefinition((string)Model.ContentItem.ContentType).DisplayName; + var contentTypeDisplayText = (await ContentDefinitionManager.GetTypeDefinitionAsync((string)Model.ContentItem.ContentType)).DisplayName; var contentItemDisplayText = contentItem.ContentItem.DisplayText; var widgetContentTypes = (IEnumerable)Model.ContainedContentTypes; @@ -39,17 +39,19 @@
    diff --git a/src/OrchardCore.Modules/OrchardCore.Forms/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Forms/Migrations.cs index 66245c77b6e..c1629600ef9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Forms/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Forms/Migrations.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -14,14 +15,14 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { // Form - _contentDefinitionManager.AlterPartDefinition("FormPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("FormPart", part => part .Attachable() .WithDescription("Turns your content item into a form.")); - _contentDefinitionManager.AlterTypeDefinition("Form", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Form", type => type .WithPart("TitlePart", part => part .WithSettings(new TitlePartSettings { RenderTitle = false }) .WithPosition("0") @@ -34,28 +35,28 @@ public int Create() .Stereotype("Widget")); // FormElement - _contentDefinitionManager.AlterPartDefinition("FormElementPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("FormElementPart", part => part .WithDescription("Provides attributes common to all form elements.")); - _contentDefinitionManager.AlterPartDefinition("FormElementLabelPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("FormElementLabelPart", part => part .Attachable() .WithDescription("Provides a way to capture element's label.") ); - _contentDefinitionManager.AlterPartDefinition("FormElementValidationPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("FormElementValidationPart", part => part .Attachable() .WithDescription("Provides validation options to form elements.") ); // FormInputElement - _contentDefinitionManager.AlterPartDefinition("FormInputElementPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("FormInputElementPart", part => part .WithDescription("Provides attributes common to all input form elements.")); // Label - _contentDefinitionManager.AlterPartDefinition("LabelPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("LabelPart", part => part .WithDescription("Provides label properties.")); - _contentDefinitionManager.AlterTypeDefinition("Label", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Label", type => type .WithPart("TitlePart", part => part .WithSettings(new TitlePartSettings { RenderTitle = false }) ) @@ -64,10 +65,10 @@ public int Create() .Stereotype("Widget")); // Input - _contentDefinitionManager.AlterPartDefinition("InputPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("InputPart", part => part .WithDescription("Provides input field properties.")); - _contentDefinitionManager.AlterTypeDefinition("Input", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Input", type => type .WithPart("FormInputElementPart", part => part .WithPosition("1") ) @@ -86,10 +87,10 @@ public int Create() .Stereotype("Widget")); // TextArea - _contentDefinitionManager.AlterPartDefinition("TextAreaPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("TextAreaPart", part => part .WithDescription("Provides text area properties.")); - _contentDefinitionManager.AlterTypeDefinition("TextArea", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("TextArea", type => type .WithPart("FormInputElementPart", part => part .WithPosition("1") ) @@ -108,10 +109,10 @@ public int Create() .Stereotype("Widget")); // Select - _contentDefinitionManager.AlterPartDefinition("SelectPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("SelectPart", part => part .WithDescription("Provides select field properties.")); - _contentDefinitionManager.AlterTypeDefinition("Select", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Select", type => type .WithPart("FormInputElementPart", part => part .WithPosition("1") ) @@ -130,28 +131,28 @@ public int Create() .Stereotype("Widget")); // Button - _contentDefinitionManager.AlterPartDefinition("ButtonPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("ButtonPart", part => part .WithDescription("Provides button properties.")); - _contentDefinitionManager.AlterTypeDefinition("Button", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Button", type => type .WithPart("FormInputElementPart") .WithPart("FormElementPart") .WithPart("ButtonPart") .Stereotype("Widget")); // Validation Summary - _contentDefinitionManager.AlterPartDefinition("ValidationSummaryPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("ValidationSummaryPart", part => part .WithDescription("Displays a validation summary.")); - _contentDefinitionManager.AlterTypeDefinition("ValidationSummary", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("ValidationSummary", type => type .WithPart("ValidationSummaryPart") .Stereotype("Widget")); // Validation - _contentDefinitionManager.AlterPartDefinition("ValidationPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("ValidationPart", part => part .WithDescription("Displays a field validation error.")); - _contentDefinitionManager.AlterTypeDefinition("Validation", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Validation", type => type .WithPart("ValidationPart") .Stereotype("Widget")); @@ -160,13 +161,13 @@ public int Create() } // This code can be removed in a later version. - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - _contentDefinitionManager.AlterTypeDefinition("Form", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Form", type => type .WithPart("TitlePart", part => part.MergeSettings(setting => setting.RenderTitle = false)) ); - _contentDefinitionManager.AlterTypeDefinition("Label", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Label", type => type .WithPart("TitlePart", part => part.MergeSettings(setting => setting.RenderTitle = false)) ); @@ -174,9 +175,9 @@ public int UpdateFrom1() } // This code can be removed in a later version. - public int UpdateFrom2() + public async Task UpdateFrom2Async() { - _contentDefinitionManager.AlterTypeDefinition("Form", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Form", type => type .WithPart("TitlePart", part => part .WithPosition("0") ) @@ -189,19 +190,19 @@ public int UpdateFrom2() } // This code can be removed in a later version. - public int UpdateFrom3() + public async Task UpdateFrom3Async() { - _contentDefinitionManager.AlterPartDefinition("FormElementLabelPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("FormElementLabelPart", part => part .Attachable() .WithDescription("Provides a way to capture element's label.") ); - _contentDefinitionManager.AlterPartDefinition("FormElementValidationPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("FormElementValidationPart", part => part .Attachable() .WithDescription("Provides validation options to form elements.") ); - _contentDefinitionManager.AlterTypeDefinition("Select", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Select", type => type .WithPart("FormInputElementPart", part => part .WithPosition("1") ) @@ -219,7 +220,7 @@ public int UpdateFrom3() ) ); - _contentDefinitionManager.AlterTypeDefinition("Input", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("Input", type => type .WithPart("FormInputElementPart", part => part .WithPosition("1") ) @@ -237,7 +238,7 @@ public int UpdateFrom3() ) ); - _contentDefinitionManager.AlterTypeDefinition("TextArea", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("TextArea", type => type .WithPart("FormInputElementPart", part => part .WithPosition("1") ) diff --git a/src/OrchardCore.Modules/OrchardCore.Html/GraphQL/HtmlBodyQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Html/GraphQL/HtmlBodyQueryObjectType.cs index 7aece9c58f3..d979a37af4f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Html/GraphQL/HtmlBodyQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Html/GraphQL/HtmlBodyQueryObjectType.cs @@ -36,7 +36,7 @@ private static async Task RenderHtml(IResolveFieldContext var shortcodeService = ctx.RequestServices.GetRequiredService(); var contentDefinitionManager = ctx.RequestServices.GetRequiredService(); - var contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(ctx.Source.ContentItem.ContentType); + var contentTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(ctx.Source.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "HtmlBodyPart")); var settings = contentTypePartDefinition.GetSettings(); diff --git a/src/OrchardCore.Modules/OrchardCore.Html/Handlers/HtmlBodyPartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Html/Handlers/HtmlBodyPartHandler.cs index 4ef995f8957..6c9d08f9af7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Html/Handlers/HtmlBodyPartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Html/Handlers/HtmlBodyPartHandler.cs @@ -40,7 +40,7 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context, { try { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "HtmlBodyPart")); var settings = contentTypePartDefinition.GetSettings(); diff --git a/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs index e710e991ccc..adc567f9102 100644 --- a/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Logging; @@ -29,9 +28,9 @@ public Migrations( _logger = logger; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("HtmlBodyPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("HtmlBodyPart", builder => builder .Attachable() .WithDescription("Provides an HTML Body for your content item.")); @@ -57,15 +56,15 @@ public int UpdateFrom2() public async Task UpdateFrom3() { // Update content type definitions - foreach (var contentType in _contentDefinitionManager.LoadTypeDefinitions()) + foreach (var contentType in await _contentDefinitionManager.LoadTypeDefinitionsAsync()) { if (contentType.Parts.Any(x => x.PartDefinition.Name == "BodyPart")) { - _contentDefinitionManager.AlterTypeDefinition(contentType.Name, x => x.RemovePart("BodyPart").WithPart("HtmlBodyPart")); + await _contentDefinitionManager.AlterTypeDefinitionAsync(contentType.Name, x => x.RemovePart("BodyPart").WithPart("HtmlBodyPart")); } } - _contentDefinitionManager.DeletePartDefinition("BodyPart"); + await _contentDefinitionManager.DeletePartDefinitionAsync("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 @@ -123,14 +122,14 @@ static bool UpdateBody(JToken content) } // This code can be removed in a later version. - public int UpdateFrom4() + public async Task UpdateFrom4() { - // For backwards compatability with liquid filters we disable html sanitization on existing field definitions. - foreach (var contentType in _contentDefinitionManager.LoadTypeDefinitions()) + // For backwards compatibility with liquid filters we disable html sanitization on existing field definitions. + foreach (var contentType in await _contentDefinitionManager.LoadTypeDefinitionsAsync()) { if (contentType.Parts.Any(x => x.PartDefinition.Name == "HtmlBodyPart")) { - _contentDefinitionManager.AlterTypeDefinition(contentType.Name, x => x.WithPart("HtmlBodyPart", part => + await _contentDefinitionManager.AlterTypeDefinitionAsync(contentType.Name, x => x.WithPart("HtmlBodyPart", part => { part.MergeSettings(x => x.SanitizeHtml = false); })); diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs index a11e626f843..1ca2004cb33 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs @@ -96,7 +96,7 @@ public async Task Index() var model = new LayersIndexViewModel { Layers = layers.Layers.ToList() }; var siteSettings = await _siteService.GetSiteSettingsAsync(); - var contentDefinitions = _contentDefinitionManager.ListTypeDefinitions(); + var contentDefinitions = await _contentDefinitionManager.ListTypeDefinitionsAsync(); model.Zones = siteSettings.As().Zones ?? Array.Empty(); model.Widgets = new Dictionary>(); diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Services/LayerFilter.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Services/LayerFilter.cs index 7024fc41e4b..7fd51cd5cca 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Services/LayerFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Services/LayerFilter.cs @@ -93,7 +93,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE var updater = _modelUpdaterAccessor.ModelUpdater; var layersCache = new Dictionary(); - var contentDefinitions = _contentDefinitionManager.ListTypeDefinitions(); + var contentDefinitions = await _contentDefinitionManager.ListTypeDefinitionsAsync(); foreach (var widget in widgets) { diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Views/Admin/Index.cshtml b/src/OrchardCore.Modules/OrchardCore.Layers/Views/Admin/Index.cshtml index e4ea05d2a78..c910b5ef9db 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Views/Admin/Index.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Views/Admin/Index.cshtml @@ -66,7 +66,7 @@ @if (Model.Layers.Count > 0) { - var widgetContentTypes = ContentDefinitionManager.ListTypeDefinitions() + var widgetContentTypes = (await ContentDefinitionManager.ListTypeDefinitionsAsync()) .Where(t => t.StereotypeEquals("Widget")) .ToList(); diff --git a/src/OrchardCore.Modules/OrchardCore.Liquid/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Liquid/Migrations.cs index 88e778c3d29..fb586f7d92e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Liquid/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Liquid/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -13,9 +14,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("LiquidPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("LiquidPart", builder => builder .Attachable() .WithDescription("Provides a Liquid formatted body for your content item.")); diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/AdminNodes/ListsAdminNodeDriver.cs b/src/OrchardCore.Modules/OrchardCore.Lists/AdminNodes/ListsAdminNodeDriver.cs index 6830d544ad2..caf3ee945d3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/AdminNodes/ListsAdminNodeDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/AdminNodes/ListsAdminNodeDriver.cs @@ -31,10 +31,10 @@ public override IDisplayResult Display(ListsAdminNode treeNode) public override IDisplayResult Edit(ListsAdminNode treeNode) { - return Initialize("ListsAdminNode_Fields_TreeEdit", model => + return Initialize("ListsAdminNode_Fields_TreeEdit", async model => { model.ContentType = treeNode.ContentType; - model.ContentTypes = GetContenTypesSelectList(); + model.ContentTypes = await GetContentTypesSelectListAsync(); model.IconForContentItems = treeNode.IconForContentItems; model.AddContentTypeAsParent = treeNode.AddContentTypeAsParent; model.IconForParentLink = treeNode.IconForParentLink; @@ -58,9 +58,9 @@ public override async Task UpdateAsync(ListsAdminNode treeNode, return Edit(treeNode); } - private List GetContenTypesSelectList() + private async Task> GetContentTypesSelectListAsync() { - return _contentDefinitionManager.ListTypeDefinitions() + return (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(ctd => ctd.Parts.Any(p => p.PartDefinition.Name.Equals(typeof(ListPart).Name, StringComparison.OrdinalIgnoreCase))) .OrderBy(ctd => ctd.DisplayName) .Select(ctd => new SelectListItem { Value = ctd.Name, Text = ctd.DisplayName }) diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/AdminNodes/ListsAdminNodeNavigationBuilder.cs b/src/OrchardCore.Modules/OrchardCore.Lists/AdminNodes/ListsAdminNodeNavigationBuilder.cs index edc7f22604b..18c3ab33a95 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/AdminNodes/ListsAdminNodeNavigationBuilder.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/AdminNodes/ListsAdminNodeNavigationBuilder.cs @@ -51,7 +51,7 @@ public async Task BuildNavigationAsync(MenuItem menuItem, NavigationBuilder buil return; } - _contentType = _contentDefinitionManager.GetTypeDefinition(_node.ContentType); + _contentType = await _contentDefinitionManager.GetTypeDefinitionAsync(_node.ContentType); if (_node.AddContentTypeAsParent) { diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Drivers/ContainedPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Drivers/ContainedPartDisplayDriver.cs index b215dda5442..b2c887cd66f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Drivers/ContainedPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Drivers/ContainedPartDisplayDriver.cs @@ -54,7 +54,7 @@ public override async Task EditAsync(ContentItem model, IUpdateM // The content type must be included to prevent any contained items, // such as widgets, from also having a ContainedPart shape built for them. - // Attach ContainedPart to the contentitem during edit to provide handlers container info. + // Attach ContainedPart to the content item during edit to provide handlers container info. await model.AlterAsync(async part => { part.ListContentItemId = viewModel.ContainerId; @@ -113,7 +113,7 @@ private async Task BuildViewModelAsync(string containerId, strin if (!string.IsNullOrEmpty(containerContentType)) { - var definition = _contentDefinitionManager.GetTypeDefinition(containerContentType); + var definition = await _contentDefinitionManager.GetTypeDefinitionAsync(containerContentType); if (definition != null) { @@ -127,9 +127,9 @@ private async Task BuildViewModelAsync(string containerId, strin if (container != null) { // Add list part navigation. - results.Add(Initialize("ListPartNavigationAdmin", model => + results.Add(Initialize("ListPartNavigationAdmin", async model => { - model.ContainedContentTypeDefinitions = GetContainedContentTypes(settings).ToArray(); + model.ContainedContentTypeDefinitions = (await GetContainedContentTypesAsync(settings)).ToArray(); model.Container = container; model.EnableOrdering = settings.EnableOrdering; model.ContainerContentTypeDefinition = definition; @@ -148,13 +148,13 @@ private async Task BuildViewModelAsync(string containerId, strin } private IDisplayResult GetListPartHeader(ContentItem containerContentItem, ListPartSettings listPartSettings) - => Initialize("ListPartHeaderAdmin", model => + => Initialize("ListPartHeaderAdmin", async model => { model.ContainerContentItem = containerContentItem; if (listPartSettings != null) { - model.ContainedContentTypeDefinitions = GetContainedContentTypes(listPartSettings).ToArray(); + model.ContainedContentTypeDefinitions = (await GetContainedContentTypesAsync(listPartSettings)).ToArray(); model.EnableOrdering = listPartSettings.EnableOrdering; } }).Location("Content:1"); @@ -164,10 +164,26 @@ private IDisplayResult GetListPartHeader(ContentItem containerContentItem, ListP private async Task GetContainerAsync(string containerId) => await _contentManager.GetAsync(containerId) ?? await _contentManager.GetAsync(containerId, VersionOptions.Latest); - private IEnumerable GetContainedContentTypes(ListPartSettings settings) - => settings.ContainedContentTypes - ?.Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType)) - .Where(definition => definition is not null) - ?? Enumerable.Empty(); + private async Task> GetContainedContentTypesAsync(ListPartSettings settings) + { + if (settings.ContainedContentTypes == null) + { + return Enumerable.Empty(); + } + + var definitions = new List(); + + foreach (var contentTypeDefinition in settings.ContainedContentTypes) + { + var definition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentTypeDefinition); + + if (definition is not null) + { + definitions.Add(definition); + } + } + + return definitions; + } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Drivers/ListPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Drivers/ListPartDisplayDriver.cs index e1763a8e3ed..5e33ea881d4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Drivers/ListPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Drivers/ListPartDisplayDriver.cs @@ -39,8 +39,8 @@ public override IDisplayResult Edit(ListPart part, BuildPartEditorContext contex return Combine( - InitilizeEditListPartNavigationAdmin(part, context, settings), - InitilizeEditListPartHeaderAdmin(part, context, settings) + InitializeEditListPartNavigationAdmin(part, context, settings), + InitializeEditListPartHeaderAdmin(part, context, settings) ); } @@ -50,32 +50,31 @@ public override IDisplayResult Display(ListPart listPart, BuildPartDisplayContex return Combine( - InitilizeDisplayListPartDisplayShape(listPart, context), - InitilizeDisplayListPartDetailAdminShape(listPart, context), - InitilizeDisplayListPartNavigationAdminShape(listPart, context, settings), - InitilizeDisplayListPartHeaderAdminShape(listPart, settings), - InitilizeDisplayListPartSummaryAdmin(listPart) + InitializeDisplayListPartDisplayShape(listPart, context), + InitializeDisplayListPartDetailAdminShape(listPart, context), + InitializeDisplayListPartNavigationAdminShape(listPart, context, settings), + InitializeDisplayListPartHeaderAdminShape(listPart, settings), + InitializeDisplayListPartSummaryAdmin(listPart) ); } - private ShapeResult InitilizeEditListPartHeaderAdmin(ListPart part, BuildPartEditorContext context, ListPartSettings settings) + private ShapeResult InitializeEditListPartHeaderAdmin(ListPart part, BuildPartEditorContext context, ListPartSettings settings) { - return Initialize("ListPartHeaderAdmin", (Action)(model => + return Initialize("ListPartHeaderAdmin", async model => { model.ContainerContentItem = part.ContentItem; - model.ContainedContentTypeDefinitions = GetContainedContentTypes(settings).ToArray(); + model.ContainedContentTypeDefinitions = (await GetContainedContentTypesAsync(settings)).ToArray(); model.EnableOrdering = settings.EnableOrdering; - })) - .Location("Content:1") - .RenderWhen(() => Task.FromResult(!context.IsNew && settings.ShowHeader)); + }).Location("Content:1") + .RenderWhen(() => Task.FromResult(!context.IsNew && settings.ShowHeader)); } - private ShapeResult InitilizeEditListPartNavigationAdmin(ListPart part, BuildPartEditorContext context, ListPartSettings settings) + private ShapeResult InitializeEditListPartNavigationAdmin(ListPart part, BuildPartEditorContext context, ListPartSettings settings) { - return Initialize("ListPartNavigationAdmin", model => + return Initialize("ListPartNavigationAdmin", async model => { model.Container = part.ContentItem; - model.ContainedContentTypeDefinitions = GetContainedContentTypes(settings).ToArray(); + model.ContainedContentTypeDefinitions = (await GetContainedContentTypesAsync(settings)).ToArray(); model.EnableOrdering = settings.EnableOrdering; model.ContainerContentTypeDefinition = context.TypePartDefinition.ContentTypeDefinition; }) @@ -83,37 +82,35 @@ private ShapeResult InitilizeEditListPartNavigationAdmin(ListPart part, BuildPar .RenderWhen(() => Task.FromResult(!context.IsNew)); } - private ShapeResult InitilizeDisplayListPartSummaryAdmin(ListPart listPart) + private ShapeResult InitializeDisplayListPartSummaryAdmin(ListPart listPart) { - return Initialize("ListPartSummaryAdmin", (Action)(model => model.ContentItem = listPart.ContentItem)) + return Initialize("ListPartSummaryAdmin", model => model.ContentItem = listPart.ContentItem) .Location("SummaryAdmin", "Actions:4"); } - private ShapeResult InitilizeDisplayListPartHeaderAdminShape(ListPart listPart, ListPartSettings settings) + private ShapeResult InitializeDisplayListPartHeaderAdminShape(ListPart listPart, ListPartSettings settings) { - return Initialize("ListPartHeaderAdmin", (Action)(model => + return Initialize("ListPartHeaderAdmin", async model => { model.ContainerContentItem = listPart.ContentItem; - model.ContainedContentTypeDefinitions = GetContainedContentTypes(settings).ToArray(); + model.ContainedContentTypeDefinitions = (await GetContainedContentTypesAsync(settings)).ToArray(); model.EnableOrdering = settings.EnableOrdering; - })) - .Location("DetailAdmin", "Content:1") - .RenderWhen(() => Task.FromResult(settings.ShowHeader)); + }).Location("DetailAdmin", "Content:1") + .RenderWhen(() => Task.FromResult(settings.ShowHeader)); } - private ShapeResult InitilizeDisplayListPartNavigationAdminShape(ListPart listPart, BuildPartDisplayContext context, ListPartSettings settings) + private ShapeResult InitializeDisplayListPartNavigationAdminShape(ListPart listPart, BuildPartDisplayContext context, ListPartSettings settings) { - return Initialize("ListPartNavigationAdmin", (Action)(model => + return Initialize("ListPartNavigationAdmin", async model => { - model.ContainedContentTypeDefinitions = GetContainedContentTypes(settings).ToArray(); + model.ContainedContentTypeDefinitions = (await GetContainedContentTypesAsync(settings)).ToArray(); model.Container = listPart.ContentItem; model.EnableOrdering = settings.EnableOrdering; model.ContainerContentTypeDefinition = context.TypePartDefinition.ContentTypeDefinition; - })) - .Location("DetailAdmin", "Content:1.5"); + }).Location("DetailAdmin", "Content:1.5"); } - private ShapeResult InitilizeDisplayListPartDetailAdminShape(ListPart listPart, BuildPartDisplayContext context) + private ShapeResult InitializeDisplayListPartDetailAdminShape(ListPart listPart, BuildPartDisplayContext context) { return Initialize("ListPartDetailAdmin", (Func)(async model => { @@ -134,7 +131,7 @@ private ShapeResult InitilizeDisplayListPartDetailAdminShape(ListPart listPart, pager, containedItemOptions)).ToArray(); - model.ContainedContentTypeDefinitions = GetContainedContentTypes(settings); + model.ContainedContentTypeDefinitions = await GetContainedContentTypesAsync(settings); model.Context = context; model.EnableOrdering = settings.EnableOrdering; model.Pager = await context.New.PagerSlim(pager); @@ -142,7 +139,7 @@ private ShapeResult InitilizeDisplayListPartDetailAdminShape(ListPart listPart, .Location("DetailAdmin", "Content:10"); } - private ShapeResult InitilizeDisplayListPartDisplayShape(ListPart listPart, BuildPartDisplayContext context) + private ShapeResult InitializeDisplayListPartDisplayShape(ListPart listPart, BuildPartDisplayContext context) { return Initialize(GetDisplayShapeType(context), async model => { @@ -155,7 +152,7 @@ private ShapeResult InitilizeDisplayListPartDisplayShape(ListPart listPart, Buil pager, containedItemOptions)).ToArray(); - model.ContainedContentTypeDefinitions = GetContainedContentTypes(settings); + model.ContainedContentTypeDefinitions = await GetContainedContentTypesAsync(settings); model.Context = context; model.Pager = await context.New.PagerSlim(pager); }) @@ -173,11 +170,25 @@ private static async Task GetPagerSlimAsync(BuildPartDisplayContext c return pager; } - private IEnumerable GetContainedContentTypes(ListPartSettings settings) + private async Task> GetContainedContentTypesAsync(ListPartSettings settings) { var contentTypes = settings.ContainedContentTypes ?? Enumerable.Empty(); - return contentTypes.Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType)); + var definitions = new List(); + + foreach (var contentType in contentTypes) + { + var definition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentType); + + if (definition == null) + { + continue; + } + + definitions.Add(definition); + } + + return definitions; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Handlers/ContainedPartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Handlers/ContainedPartHandler.cs index 8856eaa0ba8..8e986cd4218 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Handlers/ContainedPartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Handlers/ContainedPartHandler.cs @@ -31,7 +31,7 @@ public override async Task CloningAsync(CloneContentContext context) if (listContentItem != null) { var contentDefinitionManager = _serviceProvider.GetRequiredService(); - var contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(listContentItem.ContentType); + var contentTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(listContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "ListPart")); var settings = contentTypePartDefinition.GetSettings(); if (settings.EnableOrdering) diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs index 3aace78dcf7..e64011eb6ab 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -16,9 +17,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("ListPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("ListPart", builder => builder .Attachable() .WithDescription("Add a list behavior.")); @@ -52,9 +53,9 @@ public int Create() // Migrate PartSettings. This only needs to run on old content definition schemas. // This code can be removed in a later version. - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - _contentDefinitionManager.MigratePartSettings(); + await _contentDefinitionManager.MigratePartSettingsAsync(); return 2; } diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/RemotePublishing/MetaWeblogHandler.cs b/src/OrchardCore.Modules/OrchardCore.Lists/RemotePublishing/MetaWeblogHandler.cs index 736d0b6b846..cd9e6ae914e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/RemotePublishing/MetaWeblogHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/RemotePublishing/MetaWeblogHandler.cs @@ -185,7 +185,7 @@ private async Task MetaWeblogGetUserBlogsAsync(XmlRpcContext context, var array = new XRpcArray(); // Look for all types using ListPart. - foreach (var type in _contentDefinitionManager.ListTypeDefinitions()) + foreach (var type in await _contentDefinitionManager.ListTypeDefinitionsAsync()) { if (!type.Parts.Any(x => x.Name == nameof(ListPart))) { @@ -267,7 +267,7 @@ private async Task MetaWeblogNewPostAsync( var list = (await _contentManager.GetAsync(contentItemId)) ?? throw new InvalidOperationException("Could not find content item " + contentItemId); - var postType = GetContainedContentTypes(list).FirstOrDefault(); + var postType = (await GetContainedContentTypesAsync(list)).FirstOrDefault(); var contentItem = await _contentManager.NewAsync(postType.Name); contentItem.Owner = user.FindFirstValue(ClaimTypes.NameIdentifier); @@ -483,13 +483,28 @@ private async Task CheckAccessAsync(Permission permission, ClaimsPrincipal user, } } - private IEnumerable GetContainedContentTypes(ContentItem contentItem) + private async Task> GetContainedContentTypesAsync(ContentItem contentItem) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "ListPart")); var settings = contentTypePartDefinition.GetSettings(); var contentTypes = settings.ContainedContentTypes ?? Enumerable.Empty(); - return contentTypes.Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType)); + + var definitions = new List(); + + foreach (var contentType in contentTypes) + { + var definition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentType); + + if (definition == null) + { + continue; + } + + definitions.Add(definition); + } + + return definitions; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Services/ListPartContentsAdminListFilter.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Services/ListPartContentsAdminListFilter.cs index d0dbbef10fd..09fe7b0601e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Services/ListPartContentsAdminListFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Services/ListPartContentsAdminListFilter.cs @@ -31,8 +31,7 @@ public async Task FilterAsync(ContentOptionsViewModel model, IQuery // Show list content items if (viewModel.ShowListContentTypes) { - var listableTypes = _contentDefinitionManager - .ListTypeDefinitions() + var listableTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(x => x.Parts.Any(p => p.PartDefinition.Name == nameof(ListPart))) diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Settings/ListPartSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Settings/ListPartSettingsDisplayDriver.cs index e5b18bf126b..802a9ef13a4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Settings/ListPartSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Settings/ListPartSettingsDisplayDriver.cs @@ -30,7 +30,7 @@ public ListPartSettingsDisplayDriver( public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater) { - return Initialize("ListPartSettings_Edit", model => + return Initialize("ListPartSettings_Edit", async model => { model.ListPartSettings = contentTypePartDefinition.GetSettings(); model.PageSize = model.ListPartSettings.PageSize; @@ -39,7 +39,7 @@ public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDef model.ShowHeader = model.ListPartSettings.ShowHeader; model.ContentTypes = new NameValueCollection(); - foreach (var contentTypeDefinition in _contentDefinitionManager.ListTypeDefinitions()) + foreach (var contentTypeDefinition in await _contentDefinitionManager.ListTypeDefinitionsAsync()) { model.ContentTypes.Add(contentTypeDefinition.Name, contentTypeDefinition.DisplayName); } diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Views/Items/ListsAdminNode.Fields.TreeSummary.cshtml b/src/OrchardCore.Modules/OrchardCore.Lists/Views/Items/ListsAdminNode.Fields.TreeSummary.cshtml index a90a5431d50..cae64a9d10a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Views/Items/ListsAdminNode.Fields.TreeSummary.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Views/Items/ListsAdminNode.Fields.TreeSummary.cshtml @@ -3,7 +3,7 @@ @{ - var displayName = ContentDefinitionManager.GetTypeDefinition(Model.Value.ContentType); + var displayName = await ContentDefinitionManager.GetTypeDefinitionAsync(Model.Value.ContentType); }
    diff --git a/src/OrchardCore.Modules/OrchardCore.Markdown/GraphQL/MarkdownBodyQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Markdown/GraphQL/MarkdownBodyQueryObjectType.cs index 3244851b569..28d5b33872e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Markdown/GraphQL/MarkdownBodyQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Markdown/GraphQL/MarkdownBodyQueryObjectType.cs @@ -47,7 +47,7 @@ private static async Task ToHtml(IResolveFieldContext var shortcodeService = serviceProvider.GetRequiredService(); var contentDefinitionManager = serviceProvider.GetRequiredService(); - var contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(ctx.Source.ContentItem.ContentType); + var contentTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(ctx.Source.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "MarkdownBodyPart")); var settings = contentTypePartDefinition.GetSettings(); @@ -55,7 +55,7 @@ private static async Task ToHtml(IResolveFieldContext // so filters must be run after the markdown has been processed. var html = markdownService.ToHtml(ctx.Source.Markdown); - // The liquid rendering is for backwards compatability and can be removed in a future version. + // The liquid rendering is for backwards compatibility and can be removed in a future version. if (!settings.SanitizeHtml) { var liquidTemplateManager = serviceProvider.GetService(); diff --git a/src/OrchardCore.Modules/OrchardCore.Markdown/GraphQL/MarkdownFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Markdown/GraphQL/MarkdownFieldQueryObjectType.cs index b47b4a76da1..faef4491162 100644 --- a/src/OrchardCore.Modules/OrchardCore.Markdown/GraphQL/MarkdownFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Markdown/GraphQL/MarkdownFieldQueryObjectType.cs @@ -56,17 +56,17 @@ private static async Task ToHtml(IResolveFieldContext ctx var paths = jsonPath.Split('.'); var partName = paths[0]; var fieldName = paths[1]; - var contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(ctx.Source.ContentItem.ContentType); + var contentTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(ctx.Source.ContentItem.ContentType); var contentPartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.Name, partName)); - var contentPartFieldDefintion = contentPartDefinition.PartDefinition.Fields.FirstOrDefault(x => string.Equals(x.Name, fieldName)); + var contentPartFieldDefinition = contentPartDefinition.PartDefinition.Fields.FirstOrDefault(x => string.Equals(x.Name, fieldName)); - var settings = contentPartFieldDefintion.GetSettings(); + var settings = contentPartFieldDefinition.GetSettings(); // The default Markdown option is to entity escape html // so filters must be run after the markdown has been processed. var html = markdownService.ToHtml(ctx.Source.Markdown); - // The liquid rendering is for backwards compatability and can be removed in a future version. + // The liquid rendering is for backwards compatibility and can be removed in a future version. if (!settings.SanitizeHtml) { var liquidTemplateManager = serviceProvider.GetService(); @@ -78,7 +78,7 @@ private static async Task ToHtml(IResolveFieldContext ctx Html = html, Field = ctx.Source, Part = ctx.Source.ContentItem.Get(partName), - PartFieldDefinition = contentPartFieldDefintion + PartFieldDefinition = contentPartFieldDefinition }; html = await liquidTemplateManager.RenderStringAsync(html, htmlEncoder, model, @@ -89,7 +89,7 @@ private static async Task ToHtml(IResolveFieldContext ctx new Context { ["ContentItem"] = ctx.Source.ContentItem, - ["PartFieldDefinition"] = contentPartFieldDefintion + ["PartFieldDefinition"] = contentPartFieldDefinition }); if (settings.SanitizeHtml) diff --git a/src/OrchardCore.Modules/OrchardCore.Markdown/Handlers/MarkdownBodyPartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Markdown/Handlers/MarkdownBodyPartHandler.cs index 985305d9302..c4d319624ce 100644 --- a/src/OrchardCore.Modules/OrchardCore.Markdown/Handlers/MarkdownBodyPartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Markdown/Handlers/MarkdownBodyPartHandler.cs @@ -49,7 +49,7 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context, { try { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "MarkdownBodyPart")); var settings = contentTypePartDefinition.GetSettings(); @@ -57,7 +57,7 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context, // so filters must be run after the markdown has been processed. var html = _markdownService.ToHtml(part.Markdown); - // The liquid rendering is for backwards compatability and can be removed in a future version. + // The liquid rendering is for backwards compatibility and can be removed in a future version. if (!settings.SanitizeHtml) { var model = new MarkdownBodyPartViewModel() diff --git a/src/OrchardCore.Modules/OrchardCore.Markdown/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Markdown/Migrations.cs index 9b344c1a34f..66ec22a6e86 100644 --- a/src/OrchardCore.Modules/OrchardCore.Markdown/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Markdown/Migrations.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -16,9 +17,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("MarkdownBodyPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("MarkdownBodyPart", builder => builder .Attachable() .WithDescription("Provides a Markdown formatted body for your content item.")); @@ -28,21 +29,22 @@ public int Create() // Migrate FieldSettings. This only needs to run on old content definition schemas. // This code can be removed in a later version. - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); + return 2; } // This code can be removed in a later version. - public int UpdateFrom2() + public async Task UpdateFrom2Async() { - // For backwards compatability with liquid filters we disable html sanitization on existing field definitions. - foreach (var contentType in _contentDefinitionManager.LoadTypeDefinitions()) + // For backwards compatibility with liquid filters we disable html sanitization on existing field definitions. + foreach (var contentType in await _contentDefinitionManager.LoadTypeDefinitionsAsync()) { if (contentType.Parts.Any(x => x.PartDefinition.Name == "MarkdownBodyPart")) { - _contentDefinitionManager.AlterTypeDefinition(contentType.Name, x => x.WithPart("MarkdownBodyPart", part => + await _contentDefinitionManager.AlterTypeDefinitionAsync(contentType.Name, x => x.WithPart("MarkdownBodyPart", part => { part.MergeSettings(x => x.SanitizeHtml = false); })); @@ -53,15 +55,15 @@ public int UpdateFrom2() } // This code can be removed in a later version. - public int UpdateFrom3() + public async Task UpdateFrom3Async() { - // For backwards compatability with liquid filters we disable html sanitization on existing field definitions. - var partDefinitions = _contentDefinitionManager.LoadPartDefinitions(); + // For backwards compatibility with liquid filters we disable html sanitization on existing field definitions. + var partDefinitions = await _contentDefinitionManager.LoadPartDefinitionsAsync(); foreach (var partDefinition in partDefinitions) { if (partDefinition.Fields.Any(x => x.FieldDefinition.Name == "MarkdownField")) { - _contentDefinitionManager.AlterPartDefinition(partDefinition.Name, partBuilder => + await _contentDefinitionManager.AlterPartDefinitionAsync(partDefinition.Name, partBuilder => { foreach (var fieldDefinition in partDefinition.Fields.Where(x => x.FieldDefinition.Name == "MarkdownField")) { diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Media/Migrations.cs index 4f6f43cfac6..d4e3f045abb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Data.Migration; using OrchardCore.Media.Fields; @@ -16,9 +17,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) // This migration does not need to run on new installations, but because there is no // initial migration record, there is no way to shortcut the Create migration. - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); return 1; } diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs index d0f5b3d0d87..1457c17c567 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs @@ -80,7 +80,7 @@ public async Task CreatePost(string id, string menuContentItemId, ContentItem menu; - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition("Menu"); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync("Menu"); if (!contentTypeDefinition.IsDraftable()) { @@ -185,7 +185,7 @@ public async Task EditPost(string menuContentItemId, string menuI ContentItem menu; - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition("Menu"); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync("Menu"); if (!contentTypeDefinition.IsDraftable()) { @@ -251,7 +251,7 @@ public async Task Delete(string menuContentItemId, string menuIte ContentItem menu; - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition("Menu"); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync("Menu"); if (!contentTypeDefinition.IsDraftable()) { diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Drivers/MenuPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Menu/Drivers/MenuPartDisplayDriver.cs index 3561e665928..6ca09e5faae 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Drivers/MenuPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Drivers/MenuPartDisplayDriver.cs @@ -41,7 +41,7 @@ public override IDisplayResult Edit(MenuPart part) { return Initialize("MenuPart_Edit", async model => { - var menuItemContentTypes = _contentDefinitionManager.ListTypeDefinitions().Where(t => t.GetStereotype() == "MenuItem"); + var menuItemContentTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()).Where(t => t.StereotypeEquals("MenuItem")); var notify = false; foreach (var menuItem in part.ContentItem.As().MenuItems) diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Views/Admin/Create.cshtml b/src/OrchardCore.Modules/OrchardCore.Menu/Views/Admin/Create.cshtml index fefe2199f11..531984a42bd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Views/Admin/Create.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Views/Admin/Create.cshtml @@ -6,7 +6,7 @@ @{ ContentItem contentItem = Model.ContentItem; - var contentTypeDefinition = ContentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await ContentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var typeDisplayName = contentTypeDefinition?.DisplayName ?? contentItem.ContentType.CamelFriendly(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Views/Admin/Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Menu/Views/Admin/Edit.cshtml index cb55b46923c..5c341375051 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Views/Admin/Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Views/Admin/Edit.cshtml @@ -6,7 +6,7 @@ @{ ContentItem contentItem = Model.ContentItem; - var contentTypeDefinition = ContentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await ContentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var typeDisplayName = contentTypeDefinition?.DisplayName ?? contentItem.ContentType.CamelFriendly(); } diff --git a/src/OrchardCore.Modules/OrchardCore.PublishLater/Indexes/PublishLaterPartIndexProvider.cs b/src/OrchardCore.Modules/OrchardCore.PublishLater/Indexes/PublishLaterPartIndexProvider.cs index a39dd94edf5..ee6f37aff0e 100644 --- a/src/OrchardCore.Modules/OrchardCore.PublishLater/Indexes/PublishLaterPartIndexProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.PublishLater/Indexes/PublishLaterPartIndexProvider.cs @@ -23,7 +23,7 @@ public PublishLaterPartIndexProvider(IServiceProvider serviceProvider) _serviceProvider = serviceProvider; } - public override Task UpdatedAsync(UpdateContentContext context) + public override async Task UpdatedAsync(UpdateContentContext context) { var part = context.ContentItem.As(); @@ -35,15 +35,13 @@ public override Task UpdatedAsync(UpdateContentContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for this part. - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); - if (!contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(PublishLaterPart))) + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); + if (!contentTypeDefinition.Parts.Any(ctd => ctd.Name == nameof(PublishLaterPart))) { context.ContentItem.Remove(); _partRemoved.Add(context.ContentItem.ContentItemId); } } - - return Task.CompletedTask; } public string CollectionName { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs index 5cf878faa68..2e734d5e33a 100644 --- a/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -17,9 +18,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition(nameof(PublishLaterPart), builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("PublishLaterPart", builder => builder .Attachable() .WithDescription("Adds the ability to schedule content items to be published at a given future date and time.")); diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/Migrations.cs index 26094ae69f2..c96f6bc10ef 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -13,12 +14,12 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("ReCaptchaPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("ReCaptchaPart", part => part .WithDescription("Provides captcha properties.")); - _contentDefinitionManager.AlterTypeDefinition("ReCaptcha", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("ReCaptcha", type => type .WithPart("ReCaptchaPart") .Stereotype("Widget")); diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs index 812da45789a..de7e1092e12 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs @@ -174,7 +174,7 @@ public async Task Edit(string indexName = null) .Select(x => new SelectListItem { Text = x.Name + " (" + x.DisplayName + ")", Value = x.Name }), Analyzers = _elasticSearchOptions.Analyzers .Select(x => new SelectListItem { Text = x.Key, Value = x.Key }), - IndexedContentTypes = IsCreate ? _contentDefinitionManager.ListTypeDefinitions() + IndexedContentTypes = IsCreate ? (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Select(x => x.Name).ToArray() : settings.IndexedContentTypes, StoreSourceData = settings.StoreSourceData }; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs index 90f05f36447..3599900d536 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs @@ -173,7 +173,7 @@ public async Task Edit(string indexName = null) .Select(x => new SelectListItem { Text = x.Name + " (" + x.DisplayName + ")", Value = x.Name }).Prepend(new SelectListItem { Text = S["Any culture"], Value = "any" }), Analyzers = _luceneAnalyzerManager.GetAnalyzers() .Select(x => new SelectListItem { Text = x.Name, Value = x.Name }), - IndexedContentTypes = IsCreate ? _contentDefinitionManager.ListTypeDefinitions() + IndexedContentTypes = IsCreate ? (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Select(x => x.Name).ToArray() : settings.IndexedContentTypes, StoreSourceData = !IsCreate && settings.StoreSourceData }; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Migrations.cs index caa27252295..b46e0a7153e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Migrations.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Dapper; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -21,15 +22,15 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - var contentTypeDefinitions = _contentDefinitionManager.LoadTypeDefinitions(); + var contentTypeDefinitions = await _contentDefinitionManager.LoadTypeDefinitionsAsync(); foreach (var contentTypeDefinition in contentTypeDefinitions) { foreach (var partDefinition in contentTypeDefinition.Parts) { - _contentDefinitionManager.AlterPartDefinition(partDefinition.Name, partBuilder => + await _contentDefinitionManager.AlterPartDefinitionAsync(partDefinition.Name, partBuilder => { if (partDefinition.Settings.TryGetValue("ContentIndexSettings", out var existingPartSettings) && !partDefinition.Settings.ContainsKey(nameof(LuceneContentIndexSettings))) @@ -55,7 +56,7 @@ public int Create() } } - // We remove unecessary properties from old releases. + // We remove unnecessary properties from old releases. existingPartSettings["Analyzed"]?.Parent.Remove(); existingPartSettings["Tokenized"]?.Parent.Remove(); existingPartSettings["Template"]?.Parent.Remove(); @@ -68,83 +69,83 @@ public int Create() } } - var partDefinitions = _contentDefinitionManager.LoadPartDefinitions(); + var partDefinitions = await _contentDefinitionManager.LoadPartDefinitionsAsync(); foreach (var partDefinition in partDefinitions) { - _contentDefinitionManager.AlterPartDefinition(partDefinition.Name, partBuilder => - { - if (partDefinition.Settings.TryGetValue("ContentIndexSettings", out var existingPartSettings) && - !partDefinition.Settings.ContainsKey(nameof(LuceneContentIndexSettings))) - { - var included = existingPartSettings["Included"]; - var analyzed = existingPartSettings["Analyzed"]; - - if (included != null) - { - if (analyzed != null) - { - if ((bool)included && !(bool)analyzed) - { - existingPartSettings["Keyword"] = true; - } - } - else - { - if ((bool)included) - { - existingPartSettings["Keyword"] = true; - } - } - } - - // We remove unecessary properties from old releases. - existingPartSettings["Analyzed"]?.Parent.Remove(); - existingPartSettings["Tokenized"]?.Parent.Remove(); - existingPartSettings["Template"]?.Parent.Remove(); - - partDefinition.Settings.Add(new JProperty(nameof(LuceneContentIndexSettings), existingPartSettings)); - } - - partDefinition.Settings.Remove("ContentIndexSettings"); - - foreach (var fieldDefinition in partDefinition.Fields) - { - if (fieldDefinition.Settings.TryGetValue("ContentIndexSettings", out var existingFieldSettings) - && !fieldDefinition.Settings.TryGetValue(nameof(LuceneContentIndexSettings), out var existingLuceneFieldSettings)) - { - var included = existingFieldSettings["Included"]; - var analyzed = existingFieldSettings["Analyzed"]; - - if (included != null) - { - if (analyzed != null) - { - if ((bool)included && !(bool)analyzed) - { - existingFieldSettings["Keyword"] = true; - } - } - else - { - if ((bool)included) - { - existingFieldSettings["Keyword"] = true; - } - } - } - - // We remove unecessary properties from old releases. - existingFieldSettings["Analyzed"]?.Parent.Remove(); - existingFieldSettings["Tokenized"]?.Parent.Remove(); - existingFieldSettings["Template"]?.Parent.Remove(); - - fieldDefinition.Settings.Add(new JProperty(nameof(LuceneContentIndexSettings), existingFieldSettings)); - } - - fieldDefinition.Settings.Remove("ContentIndexSettings"); - } - }); + await _contentDefinitionManager.AlterPartDefinitionAsync(partDefinition.Name, partBuilder => + { + if (partDefinition.Settings.TryGetValue("ContentIndexSettings", out var existingPartSettings) && + !partDefinition.Settings.ContainsKey(nameof(LuceneContentIndexSettings))) + { + var included = existingPartSettings["Included"]; + var analyzed = existingPartSettings["Analyzed"]; + + if (included != null) + { + if (analyzed != null) + { + if ((bool)included && !(bool)analyzed) + { + existingPartSettings["Keyword"] = true; + } + } + else + { + if ((bool)included) + { + existingPartSettings["Keyword"] = true; + } + } + } + + // We remove unnecessary properties from old releases. + existingPartSettings["Analyzed"]?.Parent.Remove(); + existingPartSettings["Tokenized"]?.Parent.Remove(); + existingPartSettings["Template"]?.Parent.Remove(); + + partDefinition.Settings.Add(new JProperty(nameof(LuceneContentIndexSettings), existingPartSettings)); + } + + partDefinition.Settings.Remove("ContentIndexSettings"); + + foreach (var fieldDefinition in partDefinition.Fields) + { + if (fieldDefinition.Settings.TryGetValue("ContentIndexSettings", out var existingFieldSettings) + && !fieldDefinition.Settings.TryGetValue(nameof(LuceneContentIndexSettings), out var existingLuceneFieldSettings)) + { + var included = existingFieldSettings["Included"]; + var analyzed = existingFieldSettings["Analyzed"]; + + if (included != null) + { + if (analyzed != null) + { + if ((bool)included && !(bool)analyzed) + { + existingFieldSettings["Keyword"] = true; + } + } + else + { + if ((bool)included) + { + existingFieldSettings["Keyword"] = true; + } + } + } + + // We remove unnecessary properties from old releases. + existingFieldSettings["Analyzed"]?.Parent.Remove(); + existingFieldSettings["Tokenized"]?.Parent.Remove(); + existingFieldSettings["Template"]?.Parent.Remove(); + + fieldDefinition.Settings.Add(new JProperty(nameof(LuceneContentIndexSettings), existingFieldSettings)); + } + + fieldDefinition.Settings.Remove("ContentIndexSettings"); + } + }); } // Defer this until after the subsequent migrations have succeeded as the schema has changed. diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Migrations/SearchMigrations.cs b/src/OrchardCore.Modules/OrchardCore.Search/Migrations/SearchMigrations.cs index 84eeb3b460d..b7b19588e2d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Migrations/SearchMigrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Migrations/SearchMigrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -11,14 +12,14 @@ public class SearchMigrations : DataMigration public SearchMigrations(IContentDefinitionManager contentDefinitionManager) => _contentDefinitionManager = contentDefinitionManager; - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("SearchFormPart", part => part + await _contentDefinitionManager.AlterPartDefinitionAsync("SearchFormPart", part => part .WithDisplayName("Search Form Part") .Attachable() ); - _contentDefinitionManager.AlterTypeDefinition("SearchForm", type => type + await _contentDefinitionManager.AlterTypeDefinitionAsync("SearchForm", type => type .Stereotype("Widget") .DisplayedAs("Search Form") .WithDescription("Provides a search form") diff --git a/src/OrchardCore.Modules/OrchardCore.Seo/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Seo/Migrations.cs index 97c6150b75a..cc64d43382f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Seo/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Seo/Migrations.cs @@ -1,13 +1,10 @@ using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; -using OrchardCore.ContentManagement.Records; using OrchardCore.Data.Migration; using OrchardCore.Media.Settings; using OrchardCore.Recipes; using OrchardCore.Recipes.Services; -using OrchardCore.Seo.Indexes; -using YesSql.Sql; namespace OrchardCore.Seo { @@ -24,7 +21,7 @@ public Migrations(IContentDefinitionManager contentDefinitionManager, IRecipeMig public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("SeoMetaPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("SeoMetaPart", builder => builder .Attachable() .WithDescription("Provides a part that allows SEO meta descriptions to be applied to a content item.") .WithField("DefaultSocialImage", field => field diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Migrations.cs index 0dcfe8cc1fc..0a788deaac7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -13,9 +14,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("SitemapPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("SitemapPart", builder => builder .Attachable() .WithDescription("Provides an optional part that allows content items to be excluded, or configured, on a content item.")); diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Services/DefaultRouteableContentTypeCoordinator.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Services/DefaultRouteableContentTypeCoordinator.cs index e06ff35bd08..74b0c557f1f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Services/DefaultRouteableContentTypeCoordinator.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Services/DefaultRouteableContentTypeCoordinator.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata.Models; @@ -30,9 +29,16 @@ public async Task GetRouteAsync(SitemapBuilderContext context, ContentIt return null; } - public IEnumerable ListRoutableTypeDefinitions() + public async Task> ListRoutableTypeDefinitionsAsync() { - return _routeableContentTypeProviders.SelectMany(rctd => rctd.ListRoutableTypeDefinitions()); + var results = new List(); + + foreach (var routeableContentTypeProvider in _routeableContentTypeProviders) + { + results.AddRange(await routeableContentTypeProvider.ListRoutableTypeDefinitionsAsync()); + } + + return results; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Services/RazorPagesContentTypeProvider.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Services/RazorPagesContentTypeProvider.cs index faab2a4abe5..5c6391758d0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Services/RazorPagesContentTypeProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Services/RazorPagesContentTypeProvider.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -45,11 +44,11 @@ public Task GetRouteAsync(SitemapBuilderContext context, ContentItem con return Task.FromResult(null); } - public IEnumerable ListRoutableTypeDefinitions() + public async Task> ListRoutableTypeDefinitionsAsync() { - var ctds = _contentDefinitionManager.ListTypeDefinitions(); - var rctds = ctds.Where(ctd => _options.ContentTypeOptions.Any(o => o.ContentType == ctd.Name)); - return rctds; + var definitions = await _contentDefinitionManager.ListTypeDefinitionsAsync(); + + return definitions.Where(definition => _options.ContentTypeOptions.Any(o => o.ContentType == definition.Name)); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs index 99ae1c61272..9845f840806 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; @@ -54,7 +53,7 @@ public async Task Create(string id, string taxonomyContentItemId, return NotFound(); } - if (_contentDefinitionManager.GetTypeDefinition(id) == null) + if (await _contentDefinitionManager.GetTypeDefinitionAsync(id) == null) { return NotFound(); } @@ -85,7 +84,7 @@ public async Task CreatePost(string id, string taxonomyContentIte return NotFound(); } - if (_contentDefinitionManager.GetTypeDefinition(id) == null) + if (await _contentDefinitionManager.GetTypeDefinitionAsync(id) == null) { return NotFound(); } @@ -97,7 +96,7 @@ public async Task CreatePost(string id, string taxonomyContentIte ContentItem taxonomy; - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition("Taxonomy"); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync("Taxonomy"); if (!contentTypeDefinition.IsDraftable()) { @@ -214,7 +213,7 @@ public async Task EditPost(string taxonomyContentItemId, string t ContentItem taxonomy; - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition("Taxonomy"); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync("Taxonomy"); if (!contentTypeDefinition.IsDraftable()) { @@ -288,7 +287,7 @@ public async Task Delete(string taxonomyContentItemId, string tax ContentItem taxonomy; - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition("Taxonomy"); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync("Taxonomy"); if (!contentTypeDefinition.IsDraftable()) { diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs index 4627cc5167e..e773537c380 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs @@ -52,7 +52,7 @@ public async Task CreatePost(string taxonomyContentItemId, string return Unauthorized(); } - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition("Taxonomy"); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync("Taxonomy"); var versionOption = VersionOptions.Latest; if (contentTypeDefinition.IsDraftable()) diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs index ae6d07f2b43..24c6a53cea8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs @@ -54,7 +54,7 @@ public override async Task EditAsync(ContentOptionsViewModel mod var taxonomyContentItemIds = settings.TaxonomyContentItemIds; if (!string.IsNullOrEmpty(model.SelectedContentType)) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.SelectedContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(model.SelectedContentType); var fieldDefinitions = contentTypeDefinition .Parts.SelectMany(x => x.PartDefinition.Fields.Where(f => f.FieldDefinition.Name == nameof(TaxonomyField))); var fieldTaxonomyContentItemIds = fieldDefinitions.Select(x => x.GetSettings().TaxonomyContentItemId); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs index c471585f9ce..77f0947e959 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs @@ -37,7 +37,7 @@ public TaxonomyIndexProvider(IServiceProvider serviceProvider) public override void Describe(DescribeContext context) { context.For() - .Map(contentItem => + .Map(async contentItem => { // Remove index records of soft deleted items. if (!contentItem.Published && !contentItem.Latest) @@ -55,7 +55,7 @@ public override void Describe(DescribeContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for Taxonomy fields - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished. if (contentTypeDefinition == null) diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs index fc013ffc5f9..40e7beae226 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.ContentManagement.Records; @@ -18,9 +19,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterTypeDefinition("Taxonomy", taxonomy => taxonomy + await _contentDefinitionManager.AlterTypeDefinitionAsync("Taxonomy", taxonomy => taxonomy .Draftable() .Versionable() .Creatable() @@ -81,16 +82,16 @@ public int Create() // Migrate FieldSettings. This only needs to run on old content definition schemas. // This code can be removed in a later version. - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - _contentDefinitionManager.MigrateFieldSettings(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(); return 2; } // This code can be removed in a later version. - public int UpdateFrom2() + public async Task UpdateFrom2Async() { - _contentDefinitionManager.AlterTypeDefinition("Taxonomy", taxonomy => taxonomy + await _contentDefinitionManager.AlterTypeDefinitionAsync("Taxonomy", taxonomy => taxonomy .WithPart("AutoroutePart", part => part .WithPosition("3") .WithSettings(new AutoroutePartSettings diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Admin/Create.cshtml b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Admin/Create.cshtml index d4a9a8a1051..4616ee0e466 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Admin/Create.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Admin/Create.cshtml @@ -6,7 +6,7 @@ @{ ContentItem contentItem = Model.ContentItem; - var contentTypeDefinition = ContentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await ContentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var typeDisplayName = contentTypeDefinition?.DisplayName ?? contentItem.ContentType.CamelFriendly(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Admin/Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Admin/Edit.cshtml index 9d444f5a0d5..efb2d4e5bec 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Admin/Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Admin/Edit.cshtml @@ -6,7 +6,7 @@ @{ ContentItem contentItem = Model.ContentItem; - var contentTypeDefinition = ContentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await ContentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); var typeDisplayName = contentTypeDefinition?.DisplayName ?? contentItem.ContentType.CamelFriendly(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/TaxonomyPart.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/TaxonomyPart.Edit.cshtml index 3660802a3d8..31c78e65b98 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/TaxonomyPart.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/TaxonomyPart.Edit.cshtml @@ -18,7 +18,7 @@ @{ var updater = ModelUpdaterAccessor.ModelUpdater; var canAddTerm = Model.TaxonomyPart.ContentItem.Id != 0; - var termContentTypes = ContentDefinitionManager.ListTypeDefinitions().Where(t => !t.HasStereotype()).OrderBy(x => x.DisplayName); + var termContentTypes = (await ContentDefinitionManager.ListTypeDefinitionsAsync()).Where(t => !t.HasStereotype()).OrderBy(x => x.DisplayName); var index = 0; }
    @@ -35,7 +35,7 @@
    @if (canAddTerm && Model.TermContentType != null) { - var termContentType = ContentDefinitionManager.GetTypeDefinition(Model.TermContentType); + var termContentType = await ContentDefinitionManager.GetTypeDefinitionAsync(Model.TermContentType); @if (termContentType != null) { GetSettingsAsync(TitlePart part) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(TitlePart))); return contentTypePartDefinition.GetSettings(); diff --git a/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs index 9e2dd860d2d..28c042ee545 100644 --- a/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs @@ -28,9 +28,9 @@ public Migrations( _logger = logger; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("TitlePart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("TitlePart", builder => builder .Attachable() .WithDescription("Provides a Title for your content item.") .WithDefaultPosition("0") diff --git a/src/OrchardCore.Modules/OrchardCore.Users/CustomUserSettingsPermissions.cs b/src/OrchardCore.Modules/OrchardCore.Users/CustomUserSettingsPermissions.cs index f10ee3b88c5..4ded3d1e83b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/CustomUserSettingsPermissions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/CustomUserSettingsPermissions.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -20,12 +19,13 @@ public CustomUserSettingsPermissions(IContentDefinitionManager contentDefinition _contentDefinitionManager = contentDefinitionManager; } - public Task> GetPermissionsAsync() - => Task.FromResult(_contentDefinitionManager.ListTypeDefinitions() + public async Task> GetPermissionsAsync() + => (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(x => x.GetStereotype() == "CustomUserSettings") - .Select(type => CreatePermissionForType(type))); + .Select(type => CreatePermissionForType(type)); - public IEnumerable GetDefaultStereotypes() => Enumerable.Empty(); + public IEnumerable GetDefaultStereotypes() + => Enumerable.Empty(); public static Permission CreatePermissionForType(ContentTypeDefinition type) => new( diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs index f1ac4aa07a9..318fbdfcbfa 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs @@ -28,8 +28,8 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan } var settingsTypes = customUserSettingsStep.IncludeAll - ? _customUserSettingsService.GetAllSettingsTypes().ToList() - : _customUserSettingsService.GetSettingsTypes(customUserSettingsStep.SettingsTypeNames).ToList(); + ? (await _customUserSettingsService.GetAllSettingsTypesAsync()).ToList() + : (await _customUserSettingsService.GetSettingsTypesAsync(customUserSettingsStep.SettingsTypeNames)).ToList(); // Todo: check permissions for each settings type var userData = new JArray(); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs index 31a532d7931..fbfa710220b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs @@ -28,11 +28,11 @@ public override IDisplayResult Display(CustomUserSettingsDeploymentStep step) public override IDisplayResult Edit(CustomUserSettingsDeploymentStep step) { - return Initialize("CustomUserSettingsDeploymentStep_Fields_Edit", model => + return Initialize("CustomUserSettingsDeploymentStep_Fields_Edit", async model => { model.IncludeAll = step.IncludeAll; model.SettingsTypeNames = step.SettingsTypeNames; - model.AllSettingsTypeNames = _customUserSettingsService.GetAllSettingsTypeNames().ToArray(); + model.AllSettingsTypeNames = (await _customUserSettingsService.GetAllSettingsTypeNamesAsync()).ToArray(); }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/CustomUserSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/CustomUserSettingsDisplayDriver.cs index 7d321e597f4..2e06cc93c6d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/CustomUserSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/CustomUserSettingsDisplayDriver.cs @@ -38,12 +38,12 @@ public CustomUserSettingsDisplayDriver( _httpContextAccessor = httpContextAccessor; } - public override Task EditAsync(User user, BuildEditorContext context) + public override async Task EditAsync(User user, BuildEditorContext context) { - var contentTypeDefinitions = GetContentTypeDefinitions(); + var contentTypeDefinitions = await GetContentTypeDefinitionsAsync(); if (!contentTypeDefinitions.Any()) { - return Task.FromResult(null); + return null; } var results = new List(); @@ -62,13 +62,15 @@ public override Task EditAsync(User user, BuildEditorContext con .RenderWhen(() => _authorizationService.AuthorizeAsync(userClaim, CustomUserSettingsPermissions.CreatePermissionForType(contentTypeDefinition)))); } - return Task.FromResult(Combine(results.ToArray())); + return Combine(results); } public override async Task UpdateAsync(User user, UpdateEditorContext context) { var userClaim = _httpContextAccessor.HttpContext.User; - foreach (var contentTypeDefinition in GetContentTypeDefinitions()) + var contentTypeDefinitions = await GetContentTypeDefinitionsAsync(); + + foreach (var contentTypeDefinition in contentTypeDefinitions) { if (!await _authorizationService.AuthorizeAsync(userClaim, CustomUserSettingsPermissions.CreatePermissionForType(contentTypeDefinition))) { @@ -84,9 +86,8 @@ public override async Task UpdateAsync(User user, UpdateEditorCo return await EditAsync(user, context); } - private IEnumerable GetContentTypeDefinitions() - => _contentDefinitionManager - .ListTypeDefinitions() + private async Task> GetContentTypeDefinitionsAsync() + => (await _contentDefinitionManager.ListTypeDefinitionsAsync()) .Where(x => x.GetStereotype() == "CustomUserSettings"); private async Task GetUserSettingsAsync(User user, ContentTypeDefinition settingsType, Action isNew = null) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs index f4b923f946b..0054d314bcb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs @@ -2,9 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; @@ -16,65 +13,76 @@ namespace OrchardCore.Users.Services; public class CustomUserSettingsService { private readonly IContentManager _contentManager; - private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IAuthorizationService _authorizationService; private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly Lazy> _settingsTypes; - private readonly YesSql.ISession _session; + private readonly Lazy>> _settingsTypes; + private readonly ISession _session; public CustomUserSettingsService( IContentManager contentManager, - IHttpContextAccessor httpContextAccessor, - IAuthorizationService authorizationService, IContentDefinitionManager contentDefinitionManager, - YesSql.ISession session) + ISession session) { _contentManager = contentManager; - _httpContextAccessor = httpContextAccessor; - _authorizationService = authorizationService; _contentDefinitionManager = contentDefinitionManager; - _settingsTypes = new Lazy>( - () => _contentDefinitionManager - .ListTypeDefinitions() - .Where(x => x.StereotypeEquals("CustomUserSettings")) - .ToDictionary(x => x.Name)); - + _settingsTypes = new Lazy>>(async () => await GetContentTypeAsync()); _session = session; } - public IEnumerable GetAllSettingsTypeNames() => _settingsTypes.Value.Keys; + [Obsolete($"Instead, utilize the {nameof(GetAllSettingsTypeNamesAsync)} method. This current method is slated for removal in upcoming releases.")] + public IEnumerable GetAllSettingsTypeNames() + => _settingsTypes.Value.GetAwaiter().GetResult().Keys; + [Obsolete($"Instead, utilize the {nameof(GetAllSettingsTypesAsync)} method. This current method is slated for removal in upcoming releases.")] public IEnumerable GetAllSettingsTypes() - { - return _settingsTypes.Value.Values; - } + => _settingsTypes.Value.GetAwaiter().GetResult().Values; + [Obsolete($"Instead, utilize the {nameof(GetSettingsTypesAsync)} method. This current method is slated for removal in upcoming releases.")] public IEnumerable GetSettingsTypes(params string[] settingsTypeNames) + => GetSettingsTypesAsync(settingsTypeNames).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(GetSettingsTypeAsync)} method. This current method is slated for removal in upcoming releases.")] + public ContentTypeDefinition GetSettingsType(string settingsTypeName) + => GetSettingsTypeAsync(settingsTypeName).GetAwaiter().GetResult(); + + public async Task> GetAllSettingsTypeNamesAsync() + => (await _settingsTypes.Value).Keys; + + public async Task> GetAllSettingsTypesAsync() + => (await _settingsTypes.Value).Values; + + public async Task> GetSettingsTypesAsync(params string[] settingsTypeNames) { + var types = await _settingsTypes.Value; + var definitions = new List(); + foreach (var settingsTypeName in settingsTypeNames) { - if (_settingsTypes.Value.TryGetValue(settingsTypeName, out ContentTypeDefinition settingsType)) + if (types.TryGetValue(settingsTypeName, out var settingsType)) { - yield return settingsType; + definitions.Add(settingsType); } } + + return definitions; } - public ContentTypeDefinition GetSettingsType(string settingsTypeName) + public async Task GetSettingsTypeAsync(string settingsTypeName) { - _settingsTypes.Value.TryGetValue(settingsTypeName, out ContentTypeDefinition settingsType); + var types = await _settingsTypes.Value; + + types.TryGetValue(settingsTypeName, out var settingsType); return settingsType; } - public Task> GetSettingsAsync(string settingsTypeName, Func factoryAsync = null) + public async Task> GetSettingsAsync(string settingsTypeName, Func factoryAsync = null) { - var settingsType = GetSettingsType(settingsTypeName); + var settingsType = await GetSettingsTypeAsync(settingsTypeName); if (settingsType == null) { - return Task.FromResult>(null); + return new Dictionary(); } - return GetSettingsAsync(settingsType, factoryAsync); + return await GetSettingsAsync(settingsType, factoryAsync); } public async Task> GetSettingsAsync(ContentTypeDefinition settingsType, Func factoryAsync = null) @@ -97,7 +105,7 @@ public async Task GetSettingsAsync(User user, ContentTypeDefinition { ContentItem contentItem; - if (user.Properties.TryGetValue(settingsType.Name, out JToken property)) + if (user.Properties.TryGetValue(settingsType.Name, out var property)) { var existing = property.ToObject(); @@ -113,4 +121,14 @@ public async Task GetSettingsAsync(User user, ContentTypeDefinition return contentItem; } + + private async Task> GetContentTypeAsync() + { + var contentTypes = await _contentDefinitionManager.ListTypeDefinitionsAsync(); + + var result = contentTypes.Where(x => x.StereotypeEquals("CustomUserSettings")) + .ToDictionary(x => x.Name); + + return result; + } } diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Drivers/WidgetsListPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Widgets/Drivers/WidgetsListPartDisplayDriver.cs index 049bfb301d9..64fcf2da487 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Drivers/WidgetsListPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Drivers/WidgetsListPartDisplayDriver.cs @@ -35,7 +35,7 @@ IServiceProvider serviceProvider public override async Task DisplayAsync(WidgetsListPart part, BuildPartDisplayContext context) { - if (context.DisplayType != "Detail" || !part.Widgets.Any()) + if (context.DisplayType != "Detail" || part.Widgets.Count == 0) { return null; } @@ -69,9 +69,9 @@ public override async Task DisplayAsync(WidgetsListPart part, Bu public override IDisplayResult Edit(WidgetsListPart widgetPart, BuildPartEditorContext context) { - return Initialize(GetEditorShapeType(context), m => + return Initialize(GetEditorShapeType(context), async m => { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(widgetPart.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(widgetPart.ContentItem.ContentType); var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == nameof(WidgetsListPart)); var settings = contentTypePartDefinition.GetSettings(); @@ -106,7 +106,7 @@ public override async Task UpdateAsync(WidgetsListPart part, Upd { var existingContentItem = widgets.FirstOrDefault(x => string.Equals(x.ContentItemId, model.ContentItems[i], StringComparison.OrdinalIgnoreCase)); - // When the content item already exists merge its elements to preverse nested content item ids. + // When the content item already exists merge its elements to reverse nested content item ids. // All of the data for these merged items is then replaced by the model values on update, while a nested content item id is maintained. // This prevents nested items which rely on the content item id, i.e. the media attached field, losing their reference point. if (existingContentItem != null) diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Widgets/Migrations.cs index e6ca92be47a..0ff22328dc8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Migrations.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -13,9 +14,9 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) _contentDefinitionManager = contentDefinitionManager; } - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition("WidgetsListPart", builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync("WidgetsListPart", builder => builder .Attachable() .WithDescription("Provides a way to add widgets to Layout zones for your content item.") ); diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard-WidgetsListPart.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard-WidgetsListPart.Edit.cshtml index 75b356bc241..090ba1378c7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard-WidgetsListPart.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard-WidgetsListPart.Edit.cshtml @@ -4,8 +4,8 @@ @inject OrchardCore.ContentManagement.Metadata.IContentDefinitionManager ContentDefinitionManager @{ - var contentType = ContentDefinitionManager.GetTypeDefinition((string)Model.ContentItem.ContentType).DisplayName; - var widgetContentTypes = ContentDefinitionManager.ListTypeDefinitions().Where(t => t.GetStereotype() == "Widget"); + var contentType = (await ContentDefinitionManager.GetTypeDefinitionAsync((string)Model.ContentItem.ContentType))?.DisplayName; + var widgetContentTypes = (await ContentDefinitionManager.ListTypeDefinitionsAsync()).Where(t => t.GetStereotype() == "Widget"); }
    @@ -29,17 +29,17 @@ {
  • @type.DisplayName + data-target-id="@Model.TargetId" + data-html-field-prefix="@Model.HtmlFieldPrefix" + data-prefixes-name="@Model.PrefixesName" + data-zones-name="@Model.ZonesName" + data-contenttypes-name="@Model.ContentTypesName" + data-contentitems-name="@Model.ContentItemsName" + data-widget-type="@type.Name" + data-parent-content-type="@Model.ParentContentType" + data-part-name="@Model.CollectionPartName" + data-zone="@Model.ZoneValue" + href="javascript:;">@type.DisplayName
  • } diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard.Preview.cshtml b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard.Preview.cshtml index b4c6542cdea..f43803bfa29 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard.Preview.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard.Preview.cshtml @@ -1,7 +1,7 @@ @inject OrchardCore.ContentManagement.Metadata.IContentDefinitionManager ContentDefinitionManager @{ var contentItem = (IContent)Model.ContentItem; - var contentTypeDisplayText = ContentDefinitionManager.GetTypeDefinition((string)Model.ContentItem.ContentType).DisplayName; + var contentTypeDisplayText = (await ContentDefinitionManager.GetTypeDefinitionAsync((string)Model.ContentItem.ContentType)).DisplayName; var contentItemDisplayText = contentItem.ContentItem.DisplayText; }
    diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard.cshtml b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard.cshtml index 958f38035b0..8f9eff72c52 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/ContentCard.cshtml @@ -2,7 +2,7 @@ @inject OrchardCore.ContentManagement.Metadata.IContentDefinitionManager ContentDefinitionManager @{ - var contentDefinitions = ContentDefinitionManager.ListTypeDefinitions(); + var contentDefinitions = await ContentDefinitionManager.ListTypeDefinitionsAsync(); //Set Model (Current Shape) as Child content of Outer Frame, Later this Model is used to render other shapes dynamic contentCardFrame = await New.ContentCard_Frame(); diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/WidgetsListPart.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/WidgetsListPart.Edit.cshtml index 4ac11c9cb7b..5d908f8dffe 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/WidgetsListPart.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/WidgetsListPart.Edit.cshtml @@ -12,7 +12,7 @@ @{ var htmlFieldPrefix = ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix; - var widgetContentTypes = ContentDefinitionManager.ListTypeDefinitions().Where(t => t.GetStereotype() == "Widget"); + var widgetContentTypes = (await ContentDefinitionManager.ListTypeDefinitionsAsync()).Where(t => t.GetStereotype() == "Widget"); var parentContentType = Model.WidgetsListPart.ContentItem.ContentType; string partName = ((dynamic)Model).Metadata.Name; } diff --git a/src/OrchardCore/OrchardCore.Abstractions/Modules/Extensions/StringExtensions.cs b/src/OrchardCore/OrchardCore.Abstractions/Modules/Extensions/StringExtensions.cs index a3fc8290377..d003cd57928 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Modules/Extensions/StringExtensions.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Modules/Extensions/StringExtensions.cs @@ -1,6 +1,8 @@ using System; using System.Linq; +#nullable enable + namespace OrchardCore.Modules { public static class StringExtensions @@ -17,5 +19,14 @@ public static byte[] ToByteArray(this string hex) Select(x => Convert.ToByte(hex.Substring(x, 2), 16)). ToArray(); } + + public static bool EqualsOrdinalIgnoreCase(this string? a, string? b) + => string.Equals(a, b, StringComparison.OrdinalIgnoreCase); + + public static bool StartsWithOrdinalIgnoreCase(this string? a, string? b) => + a is not null && b is not null && a.StartsWith(b, StringComparison.OrdinalIgnoreCase); + + public static bool EndsWithOrdinalIgnoreCase(this string? a, string? b) => + a is not null && b is not null && a.EndsWith(b, StringComparison.OrdinalIgnoreCase); } } diff --git a/src/OrchardCore/OrchardCore.Autoroute.Core/Indexes/AutoroutePartIndex.cs b/src/OrchardCore/OrchardCore.Autoroute.Core/Indexes/AutoroutePartIndex.cs index 726158c1c24..82942131068 100644 --- a/src/OrchardCore/OrchardCore.Autoroute.Core/Indexes/AutoroutePartIndex.cs +++ b/src/OrchardCore/OrchardCore.Autoroute.Core/Indexes/AutoroutePartIndex.cs @@ -92,8 +92,8 @@ public override async Task PublishedAsync(PublishContentContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for this part. - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); - if (contentTypeDefinition != null && !contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(AutoroutePart))) + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); + if (contentTypeDefinition != null && !contentTypeDefinition.Parts.Any(ctd => ctd.Name == nameof(AutoroutePart))) { context.ContentItem.Remove(); _partRemoved.Add(context.ContentItem.ContentItemId); diff --git a/src/OrchardCore/OrchardCore.ContentLocalization.Abstractions/Records/LocalizedContentItemIndex.cs b/src/OrchardCore/OrchardCore.ContentLocalization.Abstractions/Records/LocalizedContentItemIndex.cs index 5de14975db8..ba35141e519 100644 --- a/src/OrchardCore/OrchardCore.ContentLocalization.Abstractions/Records/LocalizedContentItemIndex.cs +++ b/src/OrchardCore/OrchardCore.ContentLocalization.Abstractions/Records/LocalizedContentItemIndex.cs @@ -49,7 +49,7 @@ public override Task RemovedAsync(RemoveContentContext context) return Task.CompletedTask; } - public override Task PublishedAsync(PublishContentContext context) + public override async Task PublishedAsync(PublishContentContext context) { var part = context.ContentItem.As(); @@ -61,15 +61,13 @@ public override Task PublishedAsync(PublishContentContext context) _contentDefinitionManager ??= _serviceProvider.GetRequiredService(); // Search for this part. - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); - if (!contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(LocalizationPart))) + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); + if (!contentTypeDefinition.Parts.Any(ctd => ctd.Name == nameof(LocalizationPart))) { context.ContentItem.Remove(); _partRemoved.Add(context.ContentItem.ContentItemId); } } - - return Task.CompletedTask; } public string CollectionName { get; set; } diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentDefinitionManagerExtensions.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentDefinitionManagerExtensions.cs new file mode 100644 index 00000000000..70ae39570e7 --- /dev/null +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentDefinitionManagerExtensions.cs @@ -0,0 +1,233 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using OrchardCore.ContentManagement.Metadata.Builders; +using OrchardCore.ContentManagement.Metadata.Models; +using OrchardCore.ContentManagement.Utilities; + +namespace OrchardCore.ContentManagement.Metadata +{ + public static class ContentDefinitionManagerExtensions + { + [Obsolete($"Instead, utilize the {nameof(AlterTypeDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + public static void AlterTypeDefinition(this IContentDefinitionManager manager, string name, Action alteration) + { + var typeDefinition = manager.LoadTypeDefinition(name) ?? new ContentTypeDefinition(name, name.CamelFriendly()); + var builder = new ContentTypeDefinitionBuilder(typeDefinition); + alteration(builder); + manager.StoreTypeDefinition(builder.Build()); + } + + public static async Task AlterTypeDefinitionAsync(this IContentDefinitionManager manager, string name, Func alterationAsync) + { + var typeDefinition = (await manager.LoadTypeDefinitionAsync(name)) ?? new ContentTypeDefinition(name, name.CamelFriendly()); + var builder = new ContentTypeDefinitionBuilder(typeDefinition); + await alterationAsync(builder); + await manager.StoreTypeDefinitionAsync(builder.Build()); + } + + public static async Task AlterTypeDefinitionAsync(this IContentDefinitionManager manager, string name, Action alteration) + { + var typeDefinition = (await manager.LoadTypeDefinitionAsync(name)) ?? new ContentTypeDefinition(name, name.CamelFriendly()); + var builder = new ContentTypeDefinitionBuilder(typeDefinition); + alteration(builder); + await manager.StoreTypeDefinitionAsync(builder.Build()); + } + + [Obsolete($"Instead, utilize the {nameof(AlterTypeDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + public static void AlterPartDefinition(this IContentDefinitionManager manager, string name, Action alteration) + { + var partDefinition = manager.LoadPartDefinition(name) ?? new ContentPartDefinition(name); + var builder = new ContentPartDefinitionBuilder(partDefinition); + alteration(builder); + manager.StorePartDefinition(builder.Build()); + } + + public static async Task AlterPartDefinitionAsync(this IContentDefinitionManager manager, string name, Func alterationAsync) + { + var partDefinition = (await manager.LoadPartDefinitionAsync(name)) ?? new ContentPartDefinition(name); + var builder = new ContentPartDefinitionBuilder(partDefinition); + await alterationAsync(builder); + await manager.StorePartDefinitionAsync(builder.Build()); + } + + public static async Task AlterPartDefinitionAsync(this IContentDefinitionManager manager, string name, Action alteration) + { + var partDefinition = (await manager.LoadPartDefinitionAsync(name)) ?? new ContentPartDefinition(name); + var builder = new ContentPartDefinitionBuilder(partDefinition); + alteration(builder); + await manager.StorePartDefinitionAsync(builder.Build()); + } + + /// + /// Migrate existing ContentPart settings to WithSettings + /// This method will be removed in a future release. + /// + /// + /// + /// + [Obsolete($"Instead, utilize the {nameof(MigratePartSettingsAsync)} method. This current method is slated for removal in upcoming releases.")] + public static void MigratePartSettings(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(); + + // 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 + manager.AlterTypeDefinition(contentType.Name, typeBuilder => + { + typeBuilder.WithPart(partDefinition.Name, partBuilder => + { + partBuilder.WithSettings(existingSettings); + }); + }); + } + } + } + + /// + /// Migrate existing ContentPart settings to WithSettings + /// This method will be removed in a future release. + /// + /// + /// + /// + public static async Task MigratePartSettingsAsync(this IContentDefinitionManager manager) + where TPart : ContentPart where TSettings : class + { + var contentTypes = await manager.LoadTypeDefinitionsAsync(); + + 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(); + + // 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 + await manager.AlterTypeDefinitionAsync(contentType.Name, typeBuilder => + { + typeBuilder.WithPart(partDefinition.Name, partBuilder => + { + partBuilder.WithSettings(existingSettings); + }); + + return Task.CompletedTask; + }); + } + } + } + + /// + /// Migrate existing ContentField settings to WithSettings + /// This method will be removed in a future release. + /// + /// + /// + /// + [Obsolete($"Instead, utilize the {nameof(MigrateFieldSettingsAsync)} method. This current method is slated for removal in upcoming releases.")] + public static void MigrateFieldSettings(this IContentDefinitionManager manager) + where TField : ContentField where TSettings : class + { + var partDefinitions = manager.LoadPartDefinitions(); + foreach (var partDefinition in partDefinitions) + { + manager.AlterPartDefinition(partDefinition.Name, partBuilder => + { + foreach (var fieldDefinition in partDefinition.Fields.Where(x => x.FieldDefinition.Name == typeof(TField).Name)) + { + var existingFieldSettings = fieldDefinition.Settings.ToObject(); + + // Do this before creating builder, so settings are removed from the builder settings object. + // Remove existing properties from JObject + var fieldSettingsProperties = existingFieldSettings.GetType().GetProperties(); + var hasSetting = false; + foreach (var property in fieldSettingsProperties) + { + if (fieldDefinition.Settings.ContainsKey(property.Name)) + { + hasSetting = true; + fieldDefinition.Settings.Remove(property.Name); + } + } + + // Only include settings if the definition already has at least one of these settings. + if (hasSetting) + { + partBuilder.WithField(fieldDefinition.Name, fieldBuilder => + { + fieldBuilder.WithSettings(existingFieldSettings); + }); + } + } + }); + } + } + + /// + /// Migrate existing ContentField settings to WithSettings + /// This method will be removed in a future release. + /// + /// + /// + /// + public static async Task MigrateFieldSettingsAsync(this IContentDefinitionManager manager) + where TField : ContentField where TSettings : class + { + var partDefinitions = await manager.LoadPartDefinitionsAsync(); + + foreach (var partDefinition in partDefinitions) + { + await manager.AlterPartDefinitionAsync(partDefinition.Name, partBuilder => + { + foreach (var fieldDefinition in partDefinition.Fields.Where(x => x.FieldDefinition.Name == typeof(TField).Name)) + { + var existingFieldSettings = fieldDefinition.Settings.ToObject(); + + // Do this before creating builder, so settings are removed from the builder settings object. + // Remove existing properties from JObject + var fieldSettingsProperties = existingFieldSettings.GetType().GetProperties(); + var hasSetting = false; + foreach (var property in fieldSettingsProperties) + { + if (fieldDefinition.Settings.ContainsKey(property.Name)) + { + hasSetting = true; + fieldDefinition.Settings.Remove(property.Name); + } + } + + // Only include settings if the definition already has at least one of these settings. + if (hasSetting) + { + partBuilder.WithField(fieldDefinition.Name, fieldBuilder => + { + fieldBuilder.WithSettings(existingFieldSettings); + }); + } + } + }); + } + } + } +} diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/IContentDefinitionManager.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/IContentDefinitionManager.cs index 738631cfcaa..1e42ca9873e 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/IContentDefinitionManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/IContentDefinitionManager.cs @@ -1,156 +1,91 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; -using OrchardCore.ContentManagement.Metadata.Builders; using OrchardCore.ContentManagement.Metadata.Models; -using OrchardCore.ContentManagement.Utilities; -namespace OrchardCore.ContentManagement.Metadata +namespace OrchardCore.ContentManagement.Metadata; + +/// +/// This interface provides each client with +/// a different copy of to work with in case +/// multiple clients do modifications. +/// +public interface IContentDefinitionManager { + Task> LoadTypeDefinitionsAsync(); + + Task> ListTypeDefinitionsAsync(); + + Task> LoadPartDefinitionsAsync(); + + Task> ListPartDefinitionsAsync(); + + Task LoadTypeDefinitionAsync(string name); + + Task GetTypeDefinitionAsync(string name); + + Task LoadPartDefinitionAsync(string name); + + Task GetPartDefinitionAsync(string name); + + Task DeleteTypeDefinitionAsync(string name); + + Task DeletePartDefinitionAsync(string name); + + Task StoreTypeDefinitionAsync(ContentTypeDefinition contentTypeDefinition); + + Task StorePartDefinitionAsync(ContentPartDefinition contentPartDefinition); + /// - /// This interface provides each client with - /// a different copy of to work with in case - /// multiple clients do modifications. + /// Returns an unique identifier that is updated when content definitions have changed. /// - public interface IContentDefinitionManager - { - IEnumerable LoadTypeDefinitions(); - IEnumerable ListTypeDefinitions(); - IEnumerable LoadPartDefinitions(); - IEnumerable ListPartDefinitions(); - - ContentTypeDefinition LoadTypeDefinition(string name); - ContentTypeDefinition GetTypeDefinition(string name); - ContentPartDefinition LoadPartDefinition(string name); - ContentPartDefinition GetPartDefinition(string name); - void DeleteTypeDefinition(string name); - void DeletePartDefinition(string name); - - void StoreTypeDefinition(ContentTypeDefinition contentTypeDefinition); - void StorePartDefinition(ContentPartDefinition contentPartDefinition); - - /// - /// Returns an unique identifier that is updated when content definitions have changed. - /// - Task GetIdentifierAsync(); - } - - public static class ContentDefinitionManagerExtensions - { - public static void AlterTypeDefinition(this IContentDefinitionManager manager, string name, Action alteration) - { - var typeDefinition = manager.LoadTypeDefinition(name) ?? new ContentTypeDefinition(name, name.CamelFriendly()); - var builder = new ContentTypeDefinitionBuilder(typeDefinition); - alteration(builder); - manager.StoreTypeDefinition(builder.Build()); - } - - public static async Task AlterTypeDefinitionAsync(this IContentDefinitionManager manager, string name, Func alterationAsync) - { - var typeDefinition = manager.LoadTypeDefinition(name) ?? new ContentTypeDefinition(name, name.CamelFriendly()); - var builder = new ContentTypeDefinitionBuilder(typeDefinition); - await alterationAsync(builder); - manager.StoreTypeDefinition(builder.Build()); - } - - public static void AlterPartDefinition(this IContentDefinitionManager manager, string name, Action alteration) - { - var partDefinition = manager.LoadPartDefinition(name) ?? new ContentPartDefinition(name); - var builder = new ContentPartDefinitionBuilder(partDefinition); - alteration(builder); - manager.StorePartDefinition(builder.Build()); - } - - public static async Task AlterPartDefinitionAsync(this IContentDefinitionManager manager, string name, Func alterationAsync) - { - var partDefinition = manager.LoadPartDefinition(name) ?? new ContentPartDefinition(name); - var builder = new ContentPartDefinitionBuilder(partDefinition); - await alterationAsync(builder); - manager.StorePartDefinition(builder.Build()); - } - - /// - /// Migrate existing ContentPart settings to WithSettings - /// This method will be removed in a future release. - /// - /// - /// - /// - public static void MigratePartSettings(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(); - - // 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 - manager.AlterTypeDefinition(contentType.Name, typeBuilder => - { - typeBuilder.WithPart(partDefinition.Name, partBuilder => - { - partBuilder.WithSettings(existingSettings); - }); - }); - } - } - } - - /// - /// Migrate existing ContentField settings to WithSettings - /// This method will be removed in a future release. - /// - /// - /// - /// - public static void MigrateFieldSettings(this IContentDefinitionManager manager) - where TField : ContentField where TSettings : class - { - var partDefinitions = manager.LoadPartDefinitions(); - foreach (var partDefinition in partDefinitions) - { - manager.AlterPartDefinition(partDefinition.Name, partBuilder => - { - foreach (var fieldDefinition in partDefinition.Fields.Where(x => x.FieldDefinition.Name == typeof(TField).Name)) - { - var existingFieldSettings = fieldDefinition.Settings.ToObject(); - - // Do this before creating builder, so settings are removed from the builder settings object. - // Remove existing properties from JObject - var fieldSettingsProperties = existingFieldSettings.GetType().GetProperties(); - var hasSetting = false; - foreach (var property in fieldSettingsProperties) - { - if (fieldDefinition.Settings.ContainsKey(property.Name)) - { - hasSetting = true; - fieldDefinition.Settings.Remove(property.Name); - } - } - - // Only include settings if the definition already has at least one of these settings. - if (hasSetting) - { - partBuilder.WithField(fieldDefinition.Name, fieldBuilder => - { - fieldBuilder.WithSettings(existingFieldSettings); - }); - } - } - }); - } - } - } + Task GetIdentifierAsync(); + + [Obsolete($"Instead, utilize the {nameof(LoadTypeDefinitionsAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable LoadTypeDefinitions() + => LoadTypeDefinitionsAsync().GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(ListTypeDefinitionsAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable ListTypeDefinitions() + => ListTypeDefinitionsAsync().GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(LoadPartDefinitionsAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable LoadPartDefinitions() + => LoadPartDefinitionsAsync().GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(ListPartDefinitionsAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable ListPartDefinitions() + => ListPartDefinitionsAsync().GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(LoadTypeDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + ContentTypeDefinition LoadTypeDefinition(string name) + => LoadTypeDefinitionAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(GetTypeDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + ContentTypeDefinition GetTypeDefinition(string name) + => GetTypeDefinitionAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(LoadPartDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + ContentPartDefinition LoadPartDefinition(string name) + => LoadPartDefinitionAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(GetPartDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + ContentPartDefinition GetPartDefinition(string name) + => GetPartDefinitionAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(DeleteTypeDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + void DeleteTypeDefinition(string name) + => DeleteTypeDefinitionAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(DeletePartDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + void DeletePartDefinition(string name) + => DeletePartDefinitionAsync(name).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(StoreTypeDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + void StoreTypeDefinition(ContentTypeDefinition contentTypeDefinition) + => StoreTypeDefinitionAsync(contentTypeDefinition).GetAwaiter().GetResult(); + + [Obsolete($"Instead, utilize the {nameof(StorePartDefinitionAsync)} method. This current method is slated for removal in upcoming releases.")] + void StorePartDefinition(ContentPartDefinition contentPartDefinition) + => StorePartDefinitionAsync(contentPartDefinition).GetAwaiter().GetResult(); } diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Models/ContentTypePartExtensions.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Models/ContentTypePartExtensions.cs index 72f6df4261f..c85dd3c0467 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Models/ContentTypePartExtensions.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Models/ContentTypePartExtensions.cs @@ -17,7 +17,9 @@ public static string DisplayName(this ContentTypePartDefinition typePart) displayName = typePart.ContentTypeDefinition.DisplayName; } else + { displayName = typePart.PartDefinition.DisplayName(); + } } return displayName; diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartDefinitionRecord.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartDefinitionRecord.cs index c6d792a8be9..3fd980e7a30 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartDefinitionRecord.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartDefinitionRecord.cs @@ -7,8 +7,8 @@ public class ContentPartDefinitionRecord { public ContentPartDefinitionRecord() { - ContentPartFieldDefinitionRecords = new List(); - Settings = new JObject(); + ContentPartFieldDefinitionRecords = []; + Settings = []; } public string Name { get; set; } diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypeDefinitionRecord.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypeDefinitionRecord.cs index d4988ce7e03..5d9787e1ebe 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypeDefinitionRecord.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypeDefinitionRecord.cs @@ -7,11 +7,13 @@ public class ContentTypeDefinitionRecord { public ContentTypeDefinitionRecord() { - ContentTypePartDefinitionRecords = new List(); + ContentTypePartDefinitionRecords = []; } public string Name { get; set; } + public string DisplayName { get; set; } + public JObject Settings { get; set; } public IList ContentTypePartDefinitionRecords { get; set; } diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentItemDisplayCoordinator.cs b/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentItemDisplayCoordinator.cs index d881cc232f3..7ba30e7d204 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentItemDisplayCoordinator.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentItemDisplayCoordinator.cs @@ -44,7 +44,7 @@ public ContentItemDisplayCoordinator( public async Task BuildDisplayAsync(ContentItem contentItem, BuildDisplayContext context) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); if (contentTypeDefinition == null) { @@ -194,7 +194,7 @@ public async Task BuildDisplayAsync(ContentItem contentItem, BuildDisplayContext public async Task BuildEditorAsync(ContentItem contentItem, BuildEditorContext context) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); if (contentTypeDefinition == null) { return; @@ -285,7 +285,7 @@ await fieldDisplayDrivers.InvokeAsync(async (driver, part, partFieldDefinition, public async Task UpdateEditorAsync(ContentItem contentItem, UpdateEditorContext context) { - var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.LoadTypeDefinitionAsync(contentItem.ContentType); if (contentTypeDefinition == null) return; diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentItemDisplayManager.cs b/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentItemDisplayManager.cs index 3919804c1fd..4e1b9e1bb4d 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentItemDisplayManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentItemDisplayManager.cs @@ -56,7 +56,7 @@ public async Task BuildDisplayAsync(ContentItem contentItem, IUpdateMode throw new ArgumentNullException(nameof(contentItem)); } - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType) + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType) ?? throw new NullReferenceException($"Content Type {contentItem.ContentType} does not exist."); var actualDisplayType = string.IsNullOrEmpty(displayType) ? "Detail" : displayType; @@ -128,7 +128,7 @@ public async Task BuildEditorAsync(ContentItem contentItem, IUpdateModel throw new ArgumentNullException(nameof(contentItem)); } - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType) + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType) ?? throw new NullReferenceException($"Content Type {contentItem.ContentType} does not exist."); var hasStereotype = contentTypeDefinition.TryGetStereotype(out var stereotype); @@ -179,7 +179,7 @@ public async Task UpdateEditorAsync(ContentItem contentItem, IUpdateMode throw new ArgumentNullException(nameof(contentItem)); } - var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(contentItem.ContentType) + var contentTypeDefinition = await _contentDefinitionManager.LoadTypeDefinitionAsync(contentItem.ContentType) ?? throw new NullReferenceException($"Content Type {contentItem.ContentType} does not exist."); var hasStereotype = contentTypeDefinition.TryGetStereotype(out var stereotype); diff --git a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/ContentItemFilters.cs b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/ContentItemFilters.cs index 8dd9ac8ab8f..ab0f80fc75b 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/ContentItemFilters.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/ContentItemFilters.cs @@ -33,11 +33,11 @@ public override async Task> PreQueryAsync(IQuery GetIdentifierAsync() return contentDefinitionManager.GetIdentifierAsync(); } - public Task BuildAsync(ISchema schema) + public async Task BuildAsync(ISchema schema) { var serviceProvider = _httpContextAccessor.HttpContext.RequestServices; var contentDefinitionManager = serviceProvider.GetService(); var contentTypeBuilders = serviceProvider.GetServices().ToList(); - foreach (var typeDefinition in contentDefinitionManager.ListTypeDefinitions()) + foreach (var typeDefinition in await contentDefinitionManager.ListTypeDefinitionsAsync()) { if (_contentOptionsAccessor.Value.ShouldHide(typeDefinition)) { @@ -91,8 +91,6 @@ public Task BuildAsync(ISchema schema) { builder.Clear(); } - - return Task.CompletedTask; } } } diff --git a/src/OrchardCore/OrchardCore.ContentManagement/ContentDefinitionManager.cs b/src/OrchardCore/OrchardCore.ContentManagement/ContentDefinitionManager.cs index 3370d15a02f..5374a105b02 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/ContentDefinitionManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/ContentDefinitionManager.cs @@ -4,11 +4,11 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Memory; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentManagement.Metadata.Records; using OrchardCore.Data.Documents; +using OrchardCore.Modules; namespace OrchardCore.ContentManagement { @@ -36,155 +36,212 @@ public ContentDefinitionManager( _cachedPartDefinitions = _memoryCache.GetOrCreate("PartDefinitions", entry => new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase)); } - public async Task GetIdentifierAsync() => (await _contentDefinitionStore.GetContentDefinitionAsync()).Identifier; - - public ContentTypeDefinition LoadTypeDefinition(string name) + public async Task> LoadTypeDefinitionsAsync() { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentException("Argument cannot be null or empty", nameof(name)); - } - - if (!_scopedTypeDefinitions.TryGetValue(name, out var typeDefinition)) - { - var contentTypeDefinitionRecord = LoadContentDefinitionRecord() - .ContentTypeDefinitionRecords - .FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)); + var document = await _contentDefinitionStore.LoadContentDefinitionAsync(); - _scopedTypeDefinitions[name] = typeDefinition = Build(contentTypeDefinitionRecord, LoadContentDefinitionRecord().ContentPartDefinitionRecords); - }; - - return typeDefinition; + return document.ContentTypeDefinitionRecords.Select(type => LoadTypeDefinition(document, type.Name)).ToList(); } - public ContentTypeDefinition GetTypeDefinition(string name) + public async Task> ListTypeDefinitionsAsync() { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentException("Argument cannot be null or empty", nameof(name)); - } + var document = await _contentDefinitionStore.GetContentDefinitionAsync(); - var document = GetContentDefinitionRecord(); CheckDocumentIdentifier(document); - return _cachedTypeDefinitions.GetOrAdd(name, n => - { - var contentTypeDefinitionRecord = document - .ContentTypeDefinitionRecords - .FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)); - - return Build(contentTypeDefinitionRecord, GetContentDefinitionRecord().ContentPartDefinitionRecords); - }); + return document.ContentTypeDefinitionRecords.Select(type => GetTypeDefinition(document, type.Name)).ToList(); } - public ContentPartDefinition LoadPartDefinition(string name) + public async Task> LoadPartDefinitionsAsync() { - if (!_scopedPartDefinitions.TryGetValue(name, out var partDefinition)) - { - _scopedPartDefinitions[name] = partDefinition = Build(LoadContentDefinitionRecord() - .ContentPartDefinitionRecords - .FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase))); - }; + var document = await _contentDefinitionStore.LoadContentDefinitionAsync(); - return partDefinition; + return document.ContentPartDefinitionRecords.Select(part => LoadPartDefinition(document, part.Name)).ToList(); } - public ContentPartDefinition GetPartDefinition(string name) + public async Task> ListPartDefinitionsAsync() { - var document = GetContentDefinitionRecord(); + var document = await _contentDefinitionStore.GetContentDefinitionAsync(); + CheckDocumentIdentifier(document); - return _cachedPartDefinitions.GetOrAdd(name, n => - { - return Build(document - .ContentPartDefinitionRecords - .FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase))); - }); + return document.ContentPartDefinitionRecords.Select(part => GetPartDefinition(document, part.Name)).ToList(); } - public IEnumerable LoadTypeDefinitions() + public async Task LoadTypeDefinitionAsync(string name) { - return LoadContentDefinitionRecord().ContentTypeDefinitionRecords.Select(x => LoadTypeDefinition(x.Name)).ToList(); - } + ArgumentException.ThrowIfNullOrEmpty(name, nameof(name)); - public IEnumerable ListTypeDefinitions() - { - return GetContentDefinitionRecord().ContentTypeDefinitionRecords.Select(x => GetTypeDefinition(x.Name)).ToList(); - } + if (_scopedTypeDefinitions.TryGetValue(name, out var typeDefinition)) + { + return typeDefinition; + } - public IEnumerable LoadPartDefinitions() - { - return LoadContentDefinitionRecord().ContentPartDefinitionRecords.Select(x => LoadPartDefinition(x.Name)).ToList(); + var document = await _contentDefinitionStore.LoadContentDefinitionAsync(); + + return LoadTypeDefinition(document, name); } - public IEnumerable ListPartDefinitions() + public async Task GetTypeDefinitionAsync(string name) { - return GetContentDefinitionRecord().ContentPartDefinitionRecords.Select(x => GetPartDefinition(x.Name)).ToList(); + ArgumentException.ThrowIfNullOrEmpty(name, nameof(name)); + + var document = await _contentDefinitionStore.GetContentDefinitionAsync(); + + CheckDocumentIdentifier(document); + + return GetTypeDefinition(document, name); } - public void StoreTypeDefinition(ContentTypeDefinition contentTypeDefinition) + public async Task LoadPartDefinitionAsync(string name) { - Apply(contentTypeDefinition, Acquire(contentTypeDefinition)); - UpdateContentDefinitionRecord(); + ArgumentException.ThrowIfNullOrEmpty(name, nameof(name)); + + if (_scopedPartDefinitions.TryGetValue(name, out var partDefinition)) + { + return partDefinition; + } + + var document = await _contentDefinitionStore.LoadContentDefinitionAsync(); + + return LoadPartDefinition(document, name); } - public void StorePartDefinition(ContentPartDefinition contentPartDefinition) + public async Task GetPartDefinitionAsync(string name) { - Apply(contentPartDefinition, Acquire(contentPartDefinition)); - UpdateContentDefinitionRecord(); + ArgumentException.ThrowIfNullOrEmpty(name, nameof(name)); + + var document = await _contentDefinitionStore.GetContentDefinitionAsync(); + + CheckDocumentIdentifier(document); + + return GetPartDefinition(document, name); } - public void DeleteTypeDefinition(string name) + public async Task DeleteTypeDefinitionAsync(string name) { - var record = LoadContentDefinitionRecord().ContentTypeDefinitionRecords.FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)); + ArgumentException.ThrowIfNullOrEmpty(name, nameof(name)); + + var document = await _contentDefinitionStore.LoadContentDefinitionAsync(); + + var record = document.ContentTypeDefinitionRecords.FirstOrDefault(record => record.Name.EqualsOrdinalIgnoreCase(name)); - // deletes the content type record associated - if (record != null) + // Deletes the content type record associated. + if (record is not null) { - LoadContentDefinitionRecord().ContentTypeDefinitionRecords.Remove(record); - UpdateContentDefinitionRecord(); + document.ContentTypeDefinitionRecords.Remove(record); + await UpdateContentDefinitionRecordAsync(document); } } - public void DeletePartDefinition(string name) + public async Task DeletePartDefinitionAsync(string name) { - // remove parts from current types - var typesWithPart = LoadTypeDefinitions().Where(typeDefinition => typeDefinition.Parts.Any(part => string.Equals(part.PartDefinition.Name, name, StringComparison.OrdinalIgnoreCase))); + ArgumentException.ThrowIfNullOrEmpty(name, nameof(name)); + + var document = await _contentDefinitionStore.LoadContentDefinitionAsync(); + + // Remove parts from current types. + var typeDefinitions = document.ContentTypeDefinitionRecords + .Select(type => LoadTypeDefinition(document, type.Name)).ToList(); + + var typesWithPart = typeDefinitions + .Where(typeDefinition => typeDefinition.Parts + .Any(part => part.PartDefinition.Name.EqualsOrdinalIgnoreCase(name))); foreach (var typeDefinition in typesWithPart) { - this.AlterTypeDefinition(typeDefinition.Name, builder => builder.RemovePart(name)); + await this.AlterTypeDefinitionAsync(typeDefinition.Name, builder => Task.FromResult(builder.RemovePart(name))); } - // delete part - var record = LoadContentDefinitionRecord().ContentPartDefinitionRecords.FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)); - - if (record != null) + // Delete part. + var record = document.ContentPartDefinitionRecords.FirstOrDefault(part => part.Name.EqualsOrdinalIgnoreCase(name)); + if (record is not null) { - LoadContentDefinitionRecord().ContentPartDefinitionRecords.Remove(record); - UpdateContentDefinitionRecord(); + document.ContentPartDefinitionRecords.Remove(record); + await UpdateContentDefinitionRecordAsync(document); } } - private ContentTypeDefinitionRecord Acquire(ContentTypeDefinition contentTypeDefinition) + public async Task StoreTypeDefinitionAsync(ContentTypeDefinition contentTypeDefinition) + { + var document = await _contentDefinitionStore.LoadContentDefinitionAsync(); + + Apply(contentTypeDefinition, Acquire(document, contentTypeDefinition)); + + await UpdateContentDefinitionRecordAsync(document); + } + + public async Task StorePartDefinitionAsync(ContentPartDefinition contentPartDefinition) + { + var document = await _contentDefinitionStore.LoadContentDefinitionAsync(); + + Apply(contentPartDefinition, Acquire(document, contentPartDefinition)); + + await UpdateContentDefinitionRecordAsync(document); + } + + public async Task GetIdentifierAsync() => (await _contentDefinitionStore.GetContentDefinitionAsync()).Identifier; + + private ContentTypeDefinition LoadTypeDefinition(ContentDefinitionRecord document, string name) => + !_scopedTypeDefinitions.TryGetValue(name, out var typeDefinition) + ? _scopedTypeDefinitions[name] = Build( + document.ContentTypeDefinitionRecords.FirstOrDefault(type => type.Name.EqualsOrdinalIgnoreCase(name)), + document.ContentPartDefinitionRecords) + : typeDefinition; + + private ContentTypeDefinition GetTypeDefinition(ContentDefinitionRecord document, string name) => + _cachedTypeDefinitions.GetOrAdd(name, name => Build( + document.ContentTypeDefinitionRecords.FirstOrDefault(type => type.Name.EqualsOrdinalIgnoreCase(name)), + document.ContentPartDefinitionRecords)); + + private ContentPartDefinition LoadPartDefinition(ContentDefinitionRecord document, string name) => + !_scopedPartDefinitions.TryGetValue(name, out var partDefinition) + ? _scopedPartDefinitions[name] = Build( + document.ContentPartDefinitionRecords.FirstOrDefault(part => part.Name.EqualsOrdinalIgnoreCase(name))) + : partDefinition; + + private ContentPartDefinition GetPartDefinition(ContentDefinitionRecord document, string name) => + _cachedPartDefinitions.GetOrAdd(name, name => Build( + document.ContentPartDefinitionRecords.FirstOrDefault(record => record.Name.EqualsOrdinalIgnoreCase(name)))); + + private static ContentTypeDefinitionRecord Acquire( + ContentDefinitionRecord document, + ContentTypeDefinition contentTypeDefinition) { - var result = LoadContentDefinitionRecord().ContentTypeDefinitionRecords.FirstOrDefault(x => string.Equals(x.Name, contentTypeDefinition.Name, StringComparison.OrdinalIgnoreCase)); - if (result == null) + var result = document.ContentTypeDefinitionRecords + .FirstOrDefault(type => type.Name.EqualsOrdinalIgnoreCase(contentTypeDefinition.Name)); + + if (result is null) { - result = new ContentTypeDefinitionRecord { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName }; - LoadContentDefinitionRecord().ContentTypeDefinitionRecords.Add(result); + result = new ContentTypeDefinitionRecord + { + Name = contentTypeDefinition.Name, + DisplayName = contentTypeDefinition.DisplayName, + }; + + document.ContentTypeDefinitionRecords.Add(result); } + return result; } - private ContentPartDefinitionRecord Acquire(ContentPartDefinition contentPartDefinition) + private static ContentPartDefinitionRecord Acquire( + ContentDefinitionRecord document, + ContentPartDefinition contentPartDefinition) { - var result = LoadContentDefinitionRecord().ContentPartDefinitionRecords.FirstOrDefault(x => string.Equals(x.Name, contentPartDefinition.Name, StringComparison.OrdinalIgnoreCase)); - if (result == null) + var result = document.ContentPartDefinitionRecords + .FirstOrDefault(part => part.Name.EqualsOrdinalIgnoreCase(contentPartDefinition.Name)); + + if (result is null) { - result = new ContentPartDefinitionRecord { Name = contentPartDefinition.Name, }; - LoadContentDefinitionRecord().ContentPartDefinitionRecords.Add(result); + result = new ContentPartDefinitionRecord + { + Name = contentPartDefinition.Name, + }; + + document.ContentPartDefinitionRecords.Add(result); } + return result; } @@ -194,7 +251,8 @@ private static void Apply(ContentTypeDefinition model, ContentTypeDefinitionReco record.Settings = model.Settings; var toRemove = record.ContentTypePartDefinitionRecords - .Where(typePartDefinitionRecord => !model.Parts.Any(part => string.Equals(typePartDefinitionRecord.Name, part.Name, StringComparison.OrdinalIgnoreCase))) + .Where(typePartDefinitionRecord => !model.Parts + .Any(typePart => typePart.Name.EqualsOrdinalIgnoreCase(typePartDefinitionRecord.Name))) .ToList(); foreach (var remove in toRemove) @@ -204,33 +262,35 @@ private static void Apply(ContentTypeDefinition model, ContentTypeDefinitionReco foreach (var part in model.Parts) { - var typePartRecord = record.ContentTypePartDefinitionRecords.FirstOrDefault(r => string.Equals(r.Name, part.Name, StringComparison.OrdinalIgnoreCase)); - if (typePartRecord == null) + var typePartRecord = record.ContentTypePartDefinitionRecords + .FirstOrDefault(typePart => typePart.Name.EqualsOrdinalIgnoreCase(part.Name)); + + if (typePartRecord is null) { typePartRecord = new ContentTypePartDefinitionRecord { PartName = part.PartDefinition.Name, Name = part.Name, - Settings = part.Settings + Settings = part.Settings, }; record.ContentTypePartDefinitionRecords.Add(typePartRecord); } + Apply(part, typePartRecord); } } private static void Apply(ContentTypePartDefinition model, ContentTypePartDefinitionRecord record) - { - record.Settings = model.Settings; - } + => record.Settings = model.Settings; private static void Apply(ContentPartDefinition model, ContentPartDefinitionRecord record) { record.Settings = model.Settings; var toRemove = record.ContentPartFieldDefinitionRecords - .Where(partFieldDefinitionRecord => !model.Fields.Any(partField => string.Equals(partFieldDefinitionRecord.Name, partField.Name, StringComparison.OrdinalIgnoreCase))) + .Where(partFieldDefinitionRecord => !model.Fields + .Any(partField => partField.Name.EqualsOrdinalIgnoreCase(partFieldDefinitionRecord.Name))) .ToList(); foreach (var remove in toRemove) @@ -240,92 +300,82 @@ private static void Apply(ContentPartDefinition model, ContentPartDefinitionReco foreach (var field in model.Fields) { - var fieldName = field.Name; - var partFieldRecord = record.ContentPartFieldDefinitionRecords.FirstOrDefault(r => string.Equals(r.Name, fieldName, StringComparison.OrdinalIgnoreCase)); - if (partFieldRecord == null) + var partFieldRecord = record.ContentPartFieldDefinitionRecords + .FirstOrDefault(partField => partField.Name.EqualsOrdinalIgnoreCase(field.Name)); + + if (partFieldRecord is null) { - if (field.FieldDefinition == null) + if (field.FieldDefinition is null) { - throw new InvalidOperationException($"The '{field.Name}' field in '{model.Name}' part was defined without a specified type. Please review the migration and explicitly specify the field type."); + throw new InvalidOperationException( + $"The '{field.Name}' field in '{model.Name}' part was defined without a specified type." + + " Please review the migration and explicitly specify the field type."); } partFieldRecord = new ContentPartFieldDefinitionRecord { FieldName = field.FieldDefinition.Name, - Name = field.Name + Name = field.Name, }; + record.ContentPartFieldDefinitionRecords.Add(partFieldRecord); } + Apply(field, partFieldRecord); } } private static void Apply(ContentPartFieldDefinition model, ContentPartFieldDefinitionRecord record) - { - record.Settings = model.Settings; - } - - private ContentTypeDefinition Build(ContentTypeDefinitionRecord source, IList partDefinitionRecords) - { - if (source == null) - { - return null; - } + => record.Settings = model.Settings; - var contentTypeDefinition = new ContentTypeDefinition( + private static ContentTypeDefinition Build( + ContentTypeDefinitionRecord source, + IList partDefinitionRecords) => + source is not null + ? new ContentTypeDefinition( source.Name, source.DisplayName, - source.ContentTypePartDefinitionRecords.Select(tp => Build(tp, partDefinitionRecords.FirstOrDefault(p => string.Equals(p.Name, tp.PartName, StringComparison.OrdinalIgnoreCase)))), - source.Settings); - - return contentTypeDefinition; - } - - private ContentTypePartDefinition Build(ContentTypePartDefinitionRecord source, ContentPartDefinitionRecord partDefinitionRecord) - { - return source == null ? null : new ContentTypePartDefinition( + source.ContentTypePartDefinitionRecords.Select(typePart => Build( + typePart, + partDefinitionRecords.FirstOrDefault(part => part.Name.EqualsOrdinalIgnoreCase(typePart.PartName)))), + source.Settings) + : null; + + private static ContentTypePartDefinition Build( + ContentTypePartDefinitionRecord source, + ContentPartDefinitionRecord partDefinitionRecord) => + source is not null + ? new ContentTypePartDefinition( source.Name, - Build(partDefinitionRecord) ?? new ContentPartDefinition(source.PartName, Enumerable.Empty(), new JObject()), - source.Settings); - } + Build(partDefinitionRecord) ?? new ContentPartDefinition(source.PartName, [], []), + source.Settings) + : null; - private ContentPartDefinition Build(ContentPartDefinitionRecord source) - { - return source == null ? null : new ContentPartDefinition( + private static ContentPartDefinition Build(ContentPartDefinitionRecord source) => + source is not null + ? new ContentPartDefinition( source.Name, source.ContentPartFieldDefinitionRecords.Select(Build), - source.Settings); - } + source.Settings) + : null; - private ContentPartFieldDefinition Build(ContentPartFieldDefinitionRecord source) - { - return source == null ? null : new ContentPartFieldDefinition( - Build(new ContentFieldDefinitionRecord { Name = source.FieldName }), + private static ContentPartFieldDefinition Build(ContentPartFieldDefinitionRecord source) => + source is not null + ? new ContentPartFieldDefinition( + Build(new ContentFieldDefinitionRecord + { + Name = source.FieldName, + }), source.Name, - source.Settings - ); - } + source.Settings) + : null; private static ContentFieldDefinition Build(ContentFieldDefinitionRecord source) - { - return source == null ? null : new ContentFieldDefinition(source.Name); - } - - /// - /// Loads the document from the store for updating and that should not be cached. - /// - private ContentDefinitionRecord LoadContentDefinitionRecord() => _contentDefinitionStore.LoadContentDefinitionAsync().GetAwaiter().GetResult(); - - /// - /// Gets the document from the cache for sharing and that should not be updated. - /// - private ContentDefinitionRecord GetContentDefinitionRecord() => _contentDefinitionStore.GetContentDefinitionAsync().GetAwaiter().GetResult(); + => source is null ? null : new ContentFieldDefinition(source.Name); - private void UpdateContentDefinitionRecord() + private async Task UpdateContentDefinitionRecordAsync(ContentDefinitionRecord document) { - var contentDefinitionRecord = LoadContentDefinitionRecord(); - - _contentDefinitionStore.SaveContentDefinitionAsync(contentDefinitionRecord).GetAwaiter().GetResult(); + await _contentDefinitionStore.SaveContentDefinitionAsync(document); // If multiple updates in the same scope, types and parts may need to be rebuilt. _scopedTypeDefinitions.Clear(); diff --git a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs index cacc8fde1e9..dcf4772a2c0 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs @@ -54,7 +54,7 @@ public DefaultContentManager( public async Task NewAsync(string contentType) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentType); contentTypeDefinition ??= new ContentTypeDefinitionBuilder().Named(contentType).Build(); // Create a new kernel for the model instance. @@ -222,7 +222,7 @@ public async Task GetAsync(string contentItemId, VersionOptions opt if (contentItem.Published) { // We save the previous version further because this call might do a session query. - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); // Check if not versionable, meaning we use only one version if (contentTypeDefinition != null && !contentTypeDefinition.IsVersionable()) @@ -315,7 +315,7 @@ public async Task> GetAsync(IEnumerable content // When draft is required and latest is published a new version is added. if (item.Published) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(item.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(item.ContentType); // Check if not versionable, meaning we use only one version. if (contentTypeDefinition != null && !contentTypeDefinition.IsVersionable()) diff --git a/src/OrchardCore/OrchardCore.ContentManagement/Handlers/ContentPartHandlerCoordinator.cs b/src/OrchardCore/OrchardCore.ContentManagement/Handlers/ContentPartHandlerCoordinator.cs index 9f96b834785..e87d803e331 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/Handlers/ContentPartHandlerCoordinator.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/Handlers/ContentPartHandlerCoordinator.cs @@ -259,7 +259,7 @@ public override Task VersionedAsync(VersionContentContext context) public override async Task GetContentItemAspectAsync(ContentItemAspectContext context) { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); if (contentTypeDefinition == null) { return; @@ -328,7 +328,7 @@ private async Task InvokeHandlers( where TContext : ContentContextBase where TFieldContext : ContentFieldContextBase { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); if (contentTypeDefinition == null) { return; @@ -397,7 +397,7 @@ private async Task InvokeHandlers( where TFieldContext : VersionContentFieldContext { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); if (contentTypeDefinition == null) { return; @@ -453,7 +453,7 @@ private async Task InvokeHandlers( Func fieldHandlerAction) where TContext : ValidateContentContext { - var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); + var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType); if (contentTypeDefinition == null) { return; diff --git a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs index fc457e35588..d60baba2bb4 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -98,9 +99,9 @@ public int UpdateFrom2() // 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() + public async Task UpdateFrom3Async() { - var contentTypeDefinitions = _contentDefinitionManager.LoadTypeDefinitions(); + var contentTypeDefinitions = await _contentDefinitionManager.LoadTypeDefinitionsAsync(); foreach (var contentTypeDefinition in contentTypeDefinitions) { var existingContentTypeSettings = contentTypeDefinition.Settings.ToObject(); @@ -113,7 +114,7 @@ public int UpdateFrom3() contentTypeDefinition.Settings.Remove(property.Name); } - _contentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, builder => + await _contentDefinitionManager.AlterTypeDefinitionAsync(contentTypeDefinition.Name, builder => { builder.WithSettings(existingContentTypeSettings); @@ -141,9 +142,9 @@ public int UpdateFrom3() // Migration content part definitions. // This code can be removed in a later version. - public int UpdateFrom4() + public async Task UpdateFrom4Async() { - var partDefinitions = _contentDefinitionManager.LoadPartDefinitions(); + var partDefinitions = await _contentDefinitionManager.LoadPartDefinitionsAsync(); foreach (var partDefinition in partDefinitions) { var existingPartSettings = partDefinition.Settings.ToObject(); @@ -156,7 +157,7 @@ public int UpdateFrom4() partDefinition.Settings.Remove(property.Name); } - _contentDefinitionManager.AlterPartDefinition(partDefinition.Name, partBuilder => + await _contentDefinitionManager.AlterPartDefinitionAsync(partDefinition.Name, partBuilder => { partBuilder.WithSettings(existingPartSettings); foreach (var fieldDefinition in partDefinition.Fields) diff --git a/src/OrchardCore/OrchardCore.Contents.TagHelpers/ContentLinkTagHelper.cs b/src/OrchardCore/OrchardCore.Contents.TagHelpers/ContentLinkTagHelper.cs index 6109a7eac97..1483b201653 100644 --- a/src/OrchardCore/OrchardCore.Contents.TagHelpers/ContentLinkTagHelper.cs +++ b/src/OrchardCore/OrchardCore.Contents.TagHelpers/ContentLinkTagHelper.cs @@ -182,7 +182,7 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe } else { - var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); output.Content.Append(typeDefinition.ToString()); } } diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs index a35722dc7d4..9294115325e 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs @@ -305,15 +305,15 @@ public async Task GetElasticSettingsAsync() /// /// Synchronizes Elasticsearch content index settings with Lucene ones. /// - public Task SyncSettings() + public async Task SyncSettings() { - var contentTypeDefinitions = _contentDefinitionManager.LoadTypeDefinitions(); + var contentTypeDefinitions = await _contentDefinitionManager.LoadTypeDefinitionsAsync(); foreach (var contentTypeDefinition in contentTypeDefinitions) { foreach (var partDefinition in contentTypeDefinition.Parts) { - _contentDefinitionManager.AlterPartDefinition(partDefinition.Name, partBuilder => + await _contentDefinitionManager.AlterPartDefinitionAsync(partDefinition.Name, partBuilder => { if (partDefinition.Settings.TryGetValue("LuceneContentIndexSettings", out var existingPartSettings)) { @@ -328,11 +328,11 @@ public Task SyncSettings() } } - var partDefinitions = _contentDefinitionManager.LoadPartDefinitions(); + var partDefinitions = await _contentDefinitionManager.LoadPartDefinitionsAsync(); foreach (var partDefinition in partDefinitions) { - _contentDefinitionManager.AlterPartDefinition(partDefinition.Name, partBuilder => + await _contentDefinitionManager.AlterPartDefinitionAsync(partDefinition.Name, partBuilder => { if (partDefinition.Settings.TryGetValue("LuceneContentIndexSettings", out var existingPartSettings)) { @@ -358,8 +358,6 @@ public Task SyncSettings() } }); } - - return Task.CompletedTask; } } } diff --git a/src/OrchardCore/OrchardCore.Sitemaps.Abstractions/Services/IRouteableContentTypeCoordinator.cs b/src/OrchardCore/OrchardCore.Sitemaps.Abstractions/Services/IRouteableContentTypeCoordinator.cs index c23f96c3a05..97f78bf245e 100644 --- a/src/OrchardCore/OrchardCore.Sitemaps.Abstractions/Services/IRouteableContentTypeCoordinator.cs +++ b/src/OrchardCore/OrchardCore.Sitemaps.Abstractions/Services/IRouteableContentTypeCoordinator.cs @@ -1,24 +1,31 @@ +using System; using System.Collections.Generic; using System.Threading.Tasks; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.Sitemaps.Builders; -namespace OrchardCore.Sitemaps.Services +namespace OrchardCore.Sitemaps.Services; + +/// +/// Coordinates content types that are routable. +/// +public interface IRouteableContentTypeCoordinator { /// - /// Coordinates content types that are routable. + /// Lists all routable content types. + /// + Task> ListRoutableTypeDefinitionsAsync(); + + /// + /// Gets the route for a content item, when building a sitemap. /// - public interface IRouteableContentTypeCoordinator - { - /// - /// Lists all routable content types. - /// - IEnumerable ListRoutableTypeDefinitions(); + Task GetRouteAsync(SitemapBuilderContext context, ContentItem contentItem); - /// - /// Gets the route for a content item, when building a sitemap. - /// - Task GetRouteAsync(SitemapBuilderContext context, ContentItem contentItem); - } + /// + /// Lists all routable content types. + /// + [Obsolete($"Instead, utilize the {nameof(ListRoutableTypeDefinitionsAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable ListRoutableTypeDefinitions() + => ListRoutableTypeDefinitionsAsync().GetAwaiter().GetResult(); } diff --git a/src/OrchardCore/OrchardCore.Sitemaps.Abstractions/Services/IRouteableContentTypeProvider.cs b/src/OrchardCore/OrchardCore.Sitemaps.Abstractions/Services/IRouteableContentTypeProvider.cs index 4719f8f03a1..1865de01911 100644 --- a/src/OrchardCore/OrchardCore.Sitemaps.Abstractions/Services/IRouteableContentTypeProvider.cs +++ b/src/OrchardCore/OrchardCore.Sitemaps.Abstractions/Services/IRouteableContentTypeProvider.cs @@ -1,24 +1,31 @@ +using System; using System.Collections.Generic; using System.Threading.Tasks; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.Sitemaps.Builders; -namespace OrchardCore.Sitemaps.Services +namespace OrchardCore.Sitemaps.Services; + +/// +/// Provides routable content types to the coordinator. +/// +public interface IRouteableContentTypeProvider { /// - /// Provides routable content types to the coordinator. + /// Provides routable content types. + /// + Task> ListRoutableTypeDefinitionsAsync(); + + /// + /// Gets the route for a content item, when building a sitemap. /// - public interface IRouteableContentTypeProvider - { - /// - /// Provides routable content types. - /// - IEnumerable ListRoutableTypeDefinitions(); + Task GetRouteAsync(SitemapBuilderContext context, ContentItem contentItem); - /// - /// Gets the route for a content item, when building a sitemap. - /// - Task GetRouteAsync(SitemapBuilderContext context, ContentItem contentItem); - } + /// + /// Provides routable content types. + /// + [Obsolete($"Instead, utilize the {nameof(ListRoutableTypeDefinitionsAsync)} method. This current method is slated for removal in upcoming releases.")] + IEnumerable ListRoutableTypeDefinitions() + => ListRoutableTypeDefinitionsAsync().GetAwaiter().GetResult(); } diff --git a/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs b/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs index 7b33b4e90c1..be465573aa3 100644 --- a/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs +++ b/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs @@ -1008,12 +1008,12 @@ public async Task RedeemCodeAsync(IUser user, string code, CancellationTok throw new ArgumentException($"{nameof(code)} cannot be null or empty."); } - var mergedCodes = await GetTokenAsync(user, InternalLoginProvider, RecoveryCodeTokenName, cancellationToken).ConfigureAwait(false) ?? string.Empty; + var mergedCodes = (await GetTokenAsync(user, InternalLoginProvider, RecoveryCodeTokenName, cancellationToken)) ?? string.Empty; var splitCodes = mergedCodes.Split(';'); if (splitCodes.Contains(code)) { var updatedCodes = new List(splitCodes.Where(s => s != code)); - await ReplaceCodesAsync(user, updatedCodes, cancellationToken).ConfigureAwait(false); + await ReplaceCodesAsync(user, updatedCodes, cancellationToken); return true; } @@ -1028,7 +1028,7 @@ public async Task CountCodesAsync(IUser user, CancellationToken cancellatio throw new ArgumentNullException(nameof(user)); } - var mergedCodes = await GetTokenAsync(user, InternalLoginProvider, RecoveryCodeTokenName, cancellationToken).ConfigureAwait(false) ?? ""; + var mergedCodes = (await GetTokenAsync(user, InternalLoginProvider, RecoveryCodeTokenName, cancellationToken)) ?? ""; if (mergedCodes.Length > 0) { // non-allocating version of mergedCodes.Split(';').Length diff --git a/src/docs/releases/1.8.0.md b/src/docs/releases/1.8.0.md index cea6ed2471a..f8ad5409e2b 100644 --- a/src/docs/releases/1.8.0.md +++ b/src/docs/releases/1.8.0.md @@ -42,6 +42,18 @@ The HTTP error views are now in the form of shapes. If you've made customization Additionally, if you've customized the `Error.cshtml` view, it should be renamed to `HttpError.cshtml` since it acts as the default template for error pages. +### Infrastructure Changes + +The following interfaces have been updated to incorporate new asynchronous methods, corresponding to each synchronous method. All synchronous methods have been deprecated and should no longer be utilized. + + - IStereotypeService + - IStereotypesProvider + - IRouteableContentTypeProvider + - IRouteableContentTypeCoordinator + - IContentDefinitionService + - IContentDefinitionManager + - IContentDefinitionService + ## Change Logs ### TheTheme Theme