From 12281a73ea35cce51df232dd827c19db0aae8a25 Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Thu, 9 Nov 2023 11:55:29 +0000 Subject: [PATCH] fix - date formatting inslide nested items, doesn't parse correctly. --- .../Mappers/BentoItemMapper.cs | 6 ++-- .../Mappers/BentoStackMapper.cs | 6 ++-- .../Mappers/ContentmentContentBlocks.cs | 6 ++-- .../Mappers/DocTypeGridMapper.cs | 14 ++++------ .../Mapping/Mappers/BlockListMapper.cs | 6 ++-- .../Mapping/Mappers/NestedContentMapper.cs | 7 +++-- .../Mapping/SyncNestedValueMapperBase.cs | 28 +++++++++++++++++-- 7 files changed, 51 insertions(+), 22 deletions(-) diff --git a/uSync8.Community.Contrib/Mappers/BentoItemMapper.cs b/uSync8.Community.Contrib/Mappers/BentoItemMapper.cs index 592965fe..23186b86 100644 --- a/uSync8.Community.Contrib/Mappers/BentoItemMapper.cs +++ b/uSync8.Community.Contrib/Mappers/BentoItemMapper.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Services; using uSync8.ContentEdition.Mapping; @@ -20,8 +21,9 @@ public class BentoItemMapper : SyncNestedValueMapperBase, ISyncMapper public BentoItemMapper(IEntityService entityService, IContentTypeService contentTypeService, - IDataTypeService dataTypeService) - : base(entityService, contentTypeService, dataTypeService) + IDataTypeService dataTypeService, + IProfilingLogger logger) + : base(entityService, contentTypeService, dataTypeService, logger) { } public override string Name => "Bento Item Mapper"; diff --git a/uSync8.Community.Contrib/Mappers/BentoStackMapper.cs b/uSync8.Community.Contrib/Mappers/BentoStackMapper.cs index 9f37921b..75a2c188 100644 --- a/uSync8.Community.Contrib/Mappers/BentoStackMapper.cs +++ b/uSync8.Community.Contrib/Mappers/BentoStackMapper.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Umbraco.Core.Logging; using Umbraco.Core.Services; using uSync8.ContentEdition.Mapping; @@ -17,8 +18,9 @@ public class BentoStackMapper : BentoItemMapper, ISyncMapper public BentoStackMapper(IEntityService entityService, IContentTypeService contentTypeService, - IDataTypeService dataTypeService) - : base(entityService, contentTypeService, dataTypeService) + IDataTypeService dataTypeService, + IProfilingLogger logger) + : base(entityService, contentTypeService, dataTypeService, logger) { } public override string Name => "Bento Stack Mapper"; diff --git a/uSync8.Community.Contrib/Mappers/ContentmentContentBlocks.cs b/uSync8.Community.Contrib/Mappers/ContentmentContentBlocks.cs index ab9203f4..8641e3a2 100644 --- a/uSync8.Community.Contrib/Mappers/ContentmentContentBlocks.cs +++ b/uSync8.Community.Contrib/Mappers/ContentmentContentBlocks.cs @@ -12,6 +12,7 @@ using uSync8.Core.Dependency; using Umbraco.Core; +using Umbraco.Core.Logging; namespace uSync8.Community.Contrib.Mappers { @@ -20,8 +21,9 @@ namespace uSync8.Community.Contrib.Mappers /// public class ContentmentContentBlocks : SyncNestedValueMapperBase, ISyncMapper { - public ContentmentContentBlocks(IEntityService entityService, IContentTypeService contentTypeService, IDataTypeService dataTypeService) - : base(entityService, contentTypeService, dataTypeService) + public ContentmentContentBlocks(IEntityService entityService, IContentTypeService contentTypeService, IDataTypeService dataTypeService, + IProfilingLogger logger) + : base(entityService, contentTypeService, dataTypeService, logger) { } public override string Name => "Contentment content block mapper"; diff --git a/uSync8.Community.Contrib/Mappers/DocTypeGridMapper.cs b/uSync8.Community.Contrib/Mappers/DocTypeGridMapper.cs index 0722f082..6832140a 100644 --- a/uSync8.Community.Contrib/Mappers/DocTypeGridMapper.cs +++ b/uSync8.Community.Contrib/Mappers/DocTypeGridMapper.cs @@ -42,16 +42,12 @@ public class DocTypeGridMapper : SyncNestedValueMapperBase, ISyncMapper { private readonly string docTypeAliasValue = "dtgeContentTypeAlias"; - private readonly ILogger logger; - public DocTypeGridMapper(IEntityService entityService, IContentTypeService contentTypeService, IDataTypeService dataTypeService, - ILogger logger) - : base(entityService, contentTypeService, dataTypeService) - { - this.logger = logger; - } + IProfilingLogger logger) + : base(entityService, contentTypeService, dataTypeService, logger) + { } public override string Name => "DocType Grid Mapper"; @@ -133,8 +129,8 @@ public override string GetImportValue(string value, string editorAlias) catch(Exception ex) { // we want to be quite non-destructive on an import, - logger.Warn(ex, "Failed to sanitize the import value for property (turn on debugging for full property value)"); - logger.Debug("Failed DocTypeValue: {value}", value ?? String.Empty); + _logger.Warn(ex, "Failed to sanitize the import value for property (turn on debugging for full property value)"); + _logger.Debug("Failed DocTypeValue: {value}", value ?? String.Empty); return value; } diff --git a/uSync8.ContentEdition/Mapping/Mappers/BlockListMapper.cs b/uSync8.ContentEdition/Mapping/Mappers/BlockListMapper.cs index f7b8dc80..8f905b88 100644 --- a/uSync8.ContentEdition/Mapping/Mappers/BlockListMapper.cs +++ b/uSync8.ContentEdition/Mapping/Mappers/BlockListMapper.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Umbraco.Core.Logging; using Umbraco.Core.Services; using uSync8.Core; @@ -21,8 +22,9 @@ public class BlockListMapper : SyncNestedValueMapperBase, ISyncMapper public BlockListMapper(IEntityService entityService, IContentTypeService contentTypeService, - IDataTypeService dataTypeService) - : base(entityService, contentTypeService, dataTypeService) + IDataTypeService dataTypeService, + ILogger logger) + : base(entityService, contentTypeService, dataTypeService, logger) { } public override string Name => "Block List Mapper"; diff --git a/uSync8.ContentEdition/Mapping/Mappers/NestedContentMapper.cs b/uSync8.ContentEdition/Mapping/Mappers/NestedContentMapper.cs index 9a31c02c..9f5470bc 100644 --- a/uSync8.ContentEdition/Mapping/Mappers/NestedContentMapper.cs +++ b/uSync8.ContentEdition/Mapping/Mappers/NestedContentMapper.cs @@ -5,8 +5,10 @@ using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Services; +using uSync8.Core; using uSync8.Core.Dependency; namespace uSync8.ContentEdition.Mapping.Mappers @@ -17,8 +19,9 @@ public class NestedContentMapper : SyncNestedValueMapperBase, ISyncMapper public NestedContentMapper( IEntityService entityService, IContentTypeService contentTypeService, - IDataTypeService dataTypeService) - : base(entityService, contentTypeService, dataTypeService) + IDataTypeService dataTypeService, + ILogger logger) + : base(entityService, contentTypeService, dataTypeService, logger) { } public override string Name => "Nested Content Mapper"; diff --git a/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs b/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs index fea9fe20..280c704b 100644 --- a/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs +++ b/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs @@ -6,10 +6,10 @@ using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Services; -using uSync8.Core; using uSync8.Core.Dependency; namespace uSync8.ContentEdition.Mapping @@ -25,14 +25,17 @@ public abstract class SyncNestedValueMapperBase : SyncValueMapperBase { protected readonly IContentTypeService contentTypeService; protected readonly IDataTypeService dataTypeService; + protected readonly ILogger _logger; public SyncNestedValueMapperBase(IEntityService entityService, IContentTypeService contentTypeService, - IDataTypeService dataTypeService) + IDataTypeService dataTypeService, + ILogger logger) : base(entityService) { this.contentTypeService = contentTypeService; this.dataTypeService = dataTypeService; + _logger = logger; } protected JObject GetImportProperties(JObject item, IContentType docType) @@ -50,7 +53,7 @@ protected JObject GetImportProperties(JObject item, IContentType docType) item[property.Alias] = mappedVal?.ToString(); // .GetJsonTokenValue(); } else { - var mappedVal = SyncValueMapperFactory.GetImportValue((string)value, property.PropertyEditorAlias); + var mappedVal = SyncValueMapperFactory.GetImportValue(GetStringValue(value), property.PropertyEditorAlias); item[property.Alias] = mappedVal?.ToString(); // .GetJsonTokenValue(); } } @@ -205,5 +208,24 @@ protected IContentType GetDocType(string alias) } + protected string GetStringValue(JToken value) + { + var stringValue = value.ToString(); + try + { + if (value.Type is JTokenType.Date) + { + var date = value.Value(); + stringValue = date.ToString("s"); + } + } + catch(Exception ex) + { + // something might have gone wrong + _logger.Warn(ex, "Error getting formatted value"); + } + + return stringValue; + } } }