Workaround for possible NRE while indexing ContentItemRecords. (#7937) (#7938)

This commit is contained in:
Xceno
2018-01-18 21:37:17 +01:00
committed by Sébastien Ros
parent 5753a7cacc
commit 7b971f4ce4

View File

@@ -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)