From 133d30791f1c2502b6ad6379a0cfb7a0003bb36f Mon Sep 17 00:00:00 2001 From: Benjamin Carleski Date: Wed, 8 Apr 2020 14:27:50 -0700 Subject: [PATCH] Handle invalid data type references --- .../Upgrade/V_8_7_0/StackedContentToBlockList.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_8_7_0/StackedContentToBlockList.cs b/src/Umbraco.Core/Migrations/Upgrade/V_8_7_0/StackedContentToBlockList.cs index c75998a66d..1c27f1c48a 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_8_7_0/StackedContentToBlockList.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_8_7_0/StackedContentToBlockList.cs @@ -109,9 +109,9 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_7_0 { Blocks = old.ContentTypes?.Select(t => new BlockListConfiguration.BlockConfiguration { - Alias = knownDocumentTypes[t.IcContentTypeGuid].Alias, + Alias = knownDocumentTypes.TryGetValue(t.IcContentTypeGuid, out var ct) ? ct.Alias : null, Label = t.NameTemplate - }).ToArray(), + }).Where(c => c.Alias != null).ToArray(), UseInlineEditingAsDefault = old.SingleItemMode == "1" || old.SingleItemMode == bool.TrueString }; @@ -247,9 +247,9 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_7_0 public void AddDataItem(JObject obj, Dictionary knownDocumentTypes) { - if (!Guid.TryParse(obj["key"].ToString(), out var key)) throw new ArgumentException("Could not find a valid key in the data item"); - if (!Guid.TryParse(obj["icContentTypeGuid"].ToString(), out var ctGuid)) throw new ArgumentException("Could not find a valid content type GUID in the data item"); - if (!knownDocumentTypes.TryGetValue(ctGuid, out var ct)) throw new ArgumentException($"Unknown content type GUID '{ctGuid}'"); + if (!Guid.TryParse(obj["key"].ToString(), out var key)) key = Guid.NewGuid(); + if (!Guid.TryParse(obj["icContentTypeGuid"].ToString(), out var ctGuid)) ctGuid = Guid.Empty; + if (!knownDocumentTypes.TryGetValue(ctGuid, out var ct)) ct = new KnownContentType { Alias = ctGuid.ToString() }; obj.Remove("key"); obj.Remove("icContentTypeGuid");