From 06afab98935493eacdfa63b4baff96ea9894a219 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 23 Jul 2020 23:04:11 +1000 Subject: [PATCH] Adds some warning logs for when data is removed --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 9 +-- .../BlockEditorPropertyEditor.cs | 67 +++++++++++-------- .../NestedContentPropertyEditor.cs | 20 ++++-- 3 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 87b47a55c3..477fb942be 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -126,10 +126,6 @@ {52ac0ba8-a60e-4e36-897b-e8b97a54ed1c} Umbraco.ModelsBuilder.Embedded - - {fb5676ed-7a69-492c-b802-e7b24144c0fc} - Umbraco.TestData - {651e1350-91b6-44b7-bd60-7207006d7003} Umbraco.Web @@ -352,10 +348,7 @@ True 8700 / - http://localhost:8700 - 8640 - / - http://localhost:8640 + http://localhost:8700 False False diff --git a/src/Umbraco.Web/PropertyEditors/BlockEditorPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/BlockEditorPropertyEditor.cs index c20bd08204..8bf45e5313 100644 --- a/src/Umbraco.Web/PropertyEditors/BlockEditorPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/BlockEditorPropertyEditor.cs @@ -42,20 +42,22 @@ namespace Umbraco.Web.PropertyEditors #region Value Editor - protected override IDataValueEditor CreateValueEditor() => new BlockEditorPropertyValueEditor(Attribute, PropertyEditors, _dataTypeService, _contentTypeService, _localizedTextService); + protected override IDataValueEditor CreateValueEditor() => new BlockEditorPropertyValueEditor(Attribute, PropertyEditors, _dataTypeService, _contentTypeService, _localizedTextService, Logger); internal class BlockEditorPropertyValueEditor : DataValueEditor, IDataValueReference { private readonly PropertyEditorCollection _propertyEditors; private readonly IDataTypeService _dataTypeService; // TODO: Not used yet but we'll need it to fill in the FromEditor/ToEditor + private readonly ILogger _logger; private readonly BlockEditorValues _blockEditorValues; - public BlockEditorPropertyValueEditor(DataEditorAttribute attribute, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IContentTypeService contentTypeService, ILocalizedTextService textService) + public BlockEditorPropertyValueEditor(DataEditorAttribute attribute, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IContentTypeService contentTypeService, ILocalizedTextService textService, ILogger logger) : base(attribute) { _propertyEditors = propertyEditors; _dataTypeService = dataTypeService; - _blockEditorValues = new BlockEditorValues(new BlockListEditorDataConverter(), contentTypeService); + _logger = logger; + _blockEditorValues = new BlockEditorValues(new BlockListEditorDataConverter(), contentTypeService, _logger); Validators.Add(new BlockEditorValidator(_blockEditorValues, propertyEditors, dataTypeService, textService)); } @@ -123,38 +125,41 @@ namespace Umbraco.Web.PropertyEditors { foreach (var prop in row.PropertyValues) { - try + // create a temp property with the value + // - force it to be culture invariant as the block editor can't handle culture variant element properties + prop.Value.PropertyType.Variations = ContentVariation.Nothing; + var tempProp = new Property(prop.Value.PropertyType); + + tempProp.SetValue(prop.Value.Value); + + // convert that temp property, and store the converted value + var propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias]; + if (propEditor == null) { - // create a temp property with the value - // - force it to be culture invariant as the block editor can't handle culture variant element properties - prop.Value.PropertyType.Variations = ContentVariation.Nothing; - var tempProp = new Property(prop.Value.PropertyType); - - tempProp.SetValue(prop.Value.Value); - - // convert that temp property, and store the converted value - var propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias]; - if (propEditor == null) - { - // NOTE: This logic was borrowed from Nested Content and I'm unsure why it exists. - // if the property editor doesn't exist I think everything will break anyways? - // update the raw value since this is what will get serialized out - row.RawPropertyValues[prop.Key] = tempProp.GetValue()?.ToString(); - continue; - } - - var tempConfig = dataTypeService.GetDataType(prop.Value.PropertyType.DataTypeId).Configuration; - var valEditor = propEditor.GetValueEditor(tempConfig); - var convValue = valEditor.ToEditor(tempProp, dataTypeService); - + // NOTE: This logic was borrowed from Nested Content and I'm unsure why it exists. + // if the property editor doesn't exist I think everything will break anyways? // update the raw value since this is what will get serialized out - row.RawPropertyValues[prop.Key] = convValue; + row.RawPropertyValues[prop.Key] = tempProp.GetValue()?.ToString(); + continue; } - catch (InvalidOperationException) + + var dataType = dataTypeService.GetDataType(prop.Value.PropertyType.DataTypeId); + if (dataType == null) { // deal with weird situations by ignoring them (no comment) row.PropertyValues.Remove(prop.Key); + _logger.Warn( + "ToEditor removed property value {PropertyKey} in row {RowId} for property type {PropertyTypeAlias}", + prop.Key, row.Key, property.PropertyType.Alias); + continue; } + + var tempConfig = dataType.Configuration; + var valEditor = propEditor.GetValueEditor(tempConfig); + var convValue = valEditor.ToEditor(tempProp, dataTypeService); + + // update the raw value since this is what will get serialized out + row.RawPropertyValues[prop.Key] = convValue; } } @@ -251,11 +256,13 @@ namespace Umbraco.Web.PropertyEditors { private readonly Lazy> _contentTypes; private readonly BlockEditorDataConverter _dataConverter; + private readonly ILogger _logger; - public BlockEditorValues(BlockEditorDataConverter dataConverter, IContentTypeService contentTypeService) + public BlockEditorValues(BlockEditorDataConverter dataConverter, IContentTypeService contentTypeService, ILogger logger) { _contentTypes = new Lazy>(() => contentTypeService.GetAll().ToDictionary(c => c.Key)); _dataConverter = dataConverter; + _logger = logger; } private IContentType GetElementType(BlockItemData item) @@ -318,6 +325,8 @@ namespace Umbraco.Web.PropertyEditors if (!propertyTypes.TryGetValue(prop.Key, out var propType)) { block.RawPropertyValues.Remove(prop.Key); + _logger.Warn("The property {PropertyKey} for block {BlockKey} was removed because the property type {PropertyTypeAlias} was not found on {ContentTypeAlias}", + prop.Key, block.Key, prop.Key, contentType.Alias); } else { diff --git a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs index ac9e0624bb..97a2948626 100644 --- a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs @@ -25,7 +25,7 @@ namespace Umbraco.Web.PropertyEditors [DataEditor( Constants.PropertyEditors.Aliases.NestedContent, "Nested Content", - "nestedcontent", + "nestedcontent", ValueType = ValueTypes.Json, Group = Constants.PropertyEditors.Groups.Lists, Icon = "icon-thumbnail-list")] @@ -61,19 +61,21 @@ namespace Umbraco.Web.PropertyEditors #region Value Editor - protected override IDataValueEditor CreateValueEditor() => new NestedContentPropertyValueEditor(Attribute, PropertyEditors, _dataTypeService, _contentTypeService, _localizedTextService); + protected override IDataValueEditor CreateValueEditor() => new NestedContentPropertyValueEditor(Attribute, PropertyEditors, _dataTypeService, _contentTypeService, _localizedTextService, Logger); internal class NestedContentPropertyValueEditor : DataValueEditor, IDataValueReference { private readonly PropertyEditorCollection _propertyEditors; private readonly IDataTypeService _dataTypeService; + private readonly ILogger _logger; private readonly NestedContentValues _nestedContentValues; - public NestedContentPropertyValueEditor(DataEditorAttribute attribute, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IContentTypeService contentTypeService, ILocalizedTextService textService) + public NestedContentPropertyValueEditor(DataEditorAttribute attribute, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IContentTypeService contentTypeService, ILocalizedTextService textService, ILogger logger) : base(attribute) { _propertyEditors = propertyEditors; _dataTypeService = dataTypeService; + _logger = logger; _nestedContentValues = new NestedContentValues(contentTypeService); Validators.Add(new NestedContentValidator(_nestedContentValues, propertyEditors, dataTypeService, textService)); } @@ -120,10 +122,14 @@ namespace Umbraco.Web.PropertyEditors // update the raw value since this is what will get serialized out row.RawPropertyValues[prop.Key] = convValue; } - catch (InvalidOperationException) + catch (InvalidOperationException ex) { // deal with weird situations by ignoring them (no comment) row.RawPropertyValues.Remove(prop.Key); + _logger.Warn( + ex, + "ConvertDbToString removed property value {PropertyKey} in row {RowId} for property type {PropertyTypeAlias}", + prop.Key, row.Id, propertyType.Alias); } } } @@ -185,10 +191,14 @@ namespace Umbraco.Web.PropertyEditors // update the raw value since this is what will get serialized out row.RawPropertyValues[prop.Key] = convValue == null ? null : JToken.FromObject(convValue); } - catch (InvalidOperationException) + catch (InvalidOperationException ex) { // deal with weird situations by ignoring them (no comment) row.RawPropertyValues.Remove(prop.Key); + _logger.Warn( + ex, + "ToEditor removed property value {PropertyKey} in row {RowId} for property type {PropertyTypeAlias}", + prop.Key, row.Id, property.PropertyType.Alias); } } }