From e9719670ecf30b8f3d30021d9151ed267ed6da3b Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Tue, 4 Oct 2022 12:32:37 -0700 Subject: [PATCH] Prevent AutoroutePartIndex from throwing exception when content definition is not found --- .../OrchardCore.Autoroute/Indexes/AutoroutePartIndex.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Indexes/AutoroutePartIndex.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Indexes/AutoroutePartIndex.cs index a4836592845..5c4e005d95b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Indexes/AutoroutePartIndex.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Indexes/AutoroutePartIndex.cs @@ -54,8 +54,8 @@ public class AutoroutePartIndex : MapIndex public class AutoroutePartIndexProvider : ContentHandlerBase, IIndexProvider, IScopedIndexProvider { private readonly IServiceProvider _serviceProvider; - private readonly HashSet _itemRemoved = new HashSet(); - private readonly HashSet _partRemoved = new HashSet(); + private readonly HashSet _itemRemoved = new(); + private readonly HashSet _partRemoved = new(); private IContentDefinitionManager _contentDefinitionManager; private IContentManager _contentManager; @@ -92,7 +92,7 @@ public override async Task PublishedAsync(PublishContentContext context) // Search for this part. var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); - if (!contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(AutoroutePart))) + if (contentTypeDefinition != null && !contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(AutoroutePart))) { context.ContentItem.Remove(); _partRemoved.Add(context.ContentItem.ContentItemId); @@ -125,7 +125,7 @@ public void Describe(DescribeContext context) var partRemoved = _partRemoved.Contains(contentItem.ContentItemId); var part = contentItem.As(); - if (!partRemoved && (part == null || String.IsNullOrEmpty(part.Path))) + if (!partRemoved && String.IsNullOrEmpty(part?.Path)) { return null; }