Skip to content

Commit

Permalink
Prevent AutoroutePartIndex from throwing exception when content defin…
Browse files Browse the repository at this point in the history
…ition is not found (#12567)
  • Loading branch information
MikeAlhayek authored Oct 6, 2022
1 parent c72fb69 commit a097705
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class AutoroutePartIndex : MapIndex
public class AutoroutePartIndexProvider : ContentHandlerBase, IIndexProvider, IScopedIndexProvider
{
private readonly IServiceProvider _serviceProvider;
private readonly HashSet<ContentItem> _itemRemoved = new HashSet<ContentItem>();
private readonly HashSet<string> _partRemoved = new HashSet<string>();
private readonly HashSet<ContentItem> _itemRemoved = new();
private readonly HashSet<string> _partRemoved = new();
private IContentDefinitionManager _contentDefinitionManager;
private IContentManager _contentManager;

Expand Down Expand Up @@ -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<AutoroutePart>();
_partRemoved.Add(context.ContentItem.ContentItemId);
Expand Down Expand Up @@ -125,7 +125,7 @@ public void Describe(DescribeContext<ContentItem> context)
var partRemoved = _partRemoved.Contains(contentItem.ContentItemId);

var part = contentItem.As<AutoroutePart>();
if (!partRemoved && (part == null || String.IsNullOrEmpty(part.Path)))
if (!partRemoved && String.IsNullOrEmpty(part?.Path))
{
return null;
}
Expand Down

0 comments on commit a097705

Please sign in to comment.