Ensures everything doesn't explode if a non-found property editor alias exists in the db

This commit is contained in:
Shannon
2019-02-08 16:00:02 +11:00
parent b08218240c
commit ccaaa9ab93
2 changed files with 9 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos;
using Umbraco.Core.PropertyEditors;
@@ -10,10 +11,14 @@ namespace Umbraco.Core.Persistence.Factories
{
internal static class DataTypeFactory
{
public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors)
public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger logger)
{
if (!editors.TryGet(dto.EditorAlias, out var editor))
throw new InvalidOperationException($"Could not find an editor with alias \"{dto.EditorAlias}\".");
{
logger.Warn(typeof(DataTypeFactory), "Could not find an editor with alias {dto.EditorAlias}, converting to label", dto.EditorAlias);
//convert to label
editor = new LabelPropertyEditor(logger);
}
var dataType = new DataType(editor);

View File

@@ -54,7 +54,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
}
var dtos = Database.Fetch<DataTypeDto>(dataTypeSql);
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value)).ToArray();
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger)).ToArray();
}
protected override IEnumerable<IDataType> PerformGetByQuery(IQuery<IDataType> query)
@@ -65,7 +65,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
var dtos = Database.Fetch<DataTypeDto>(sql);
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value)).ToArray();
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger)).ToArray();
}
#endregion