From 7b971f4ce49b35dd83f57bb8fc7f9b50041486d3 Mon Sep 17 00:00:00 2001 From: Xceno Date: Thu, 18 Jan 2018 21:37:17 +0100 Subject: [PATCH] Workaround for possible NRE while indexing ContentItemRecords. (#7937) (#7938) --- .../Orchard.Indexing/Services/IndexingTaskExecutor.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskExecutor.cs b/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskExecutor.cs index e97b62b27..846e20f33 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskExecutor.cs +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskExecutor.cs @@ -160,6 +160,9 @@ namespace Orchard.Indexing.Services { .OrderBy(versionRecord => versionRecord.Id) .Take(ContentItemsPerLoop) .ToList() + // In some rare cases a ContentItemRecord without a ContentType can end up in the DB. + // We need to filter out such records, otherwise they will crash the ContentManager. + .Where(x => x.ContentItemRecord != null && x.ContentItemRecord.ContentType != null) .Select(versionRecord => _contentManager.Get(versionRecord.ContentItemRecord.Id, VersionOptions.VersionRecord(versionRecord.Id))) .Distinct() .ToList(); @@ -220,6 +223,9 @@ namespace Orchard.Indexing.Services { .OrderBy(x => x.Id) .Take(ContentItemsPerLoop) .ToList() + // In some rare cases a ContentItemRecord without a ContentType can end up in the DB. + // We need to filter out such records, otherwise they will crash the ContentManager. + .Where(x => x.ContentItemRecord != null && x.ContentItemRecord.ContentType != null) .GroupBy(x => x.ContentItemRecord.Id) .Select(group => new { TaskId = group.Max(task => task.Id), Delete = group.Last().Action == IndexingTaskRecord.Delete, Id = group.Key, ContentItem = _contentManager.Get(group.Key, VersionOptions.Latest) }) .OrderBy(x => x.TaskId)