Skip to content

Commit

Permalink
fix - date formatting inslide nested items, doesn't parse correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Nov 9, 2023
1 parent 69307f1 commit 12281a7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 22 deletions.
6 changes: 4 additions & 2 deletions uSync8.Community.Contrib/Mappers/BentoItemMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Newtonsoft.Json.Linq;

using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;

using uSync8.ContentEdition.Mapping;
Expand All @@ -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";
Expand Down
6 changes: 4 additions & 2 deletions uSync8.Community.Contrib/Mappers/BentoStackMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using Umbraco.Core.Logging;
using Umbraco.Core.Services;

using uSync8.ContentEdition.Mapping;
Expand All @@ -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";
Expand Down
6 changes: 4 additions & 2 deletions uSync8.Community.Contrib/Mappers/ContentmentContentBlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

using uSync8.Core.Dependency;
using Umbraco.Core;
using Umbraco.Core.Logging;

namespace uSync8.Community.Contrib.Mappers
{
Expand All @@ -20,8 +21,9 @@ namespace uSync8.Community.Contrib.Mappers
/// </summary>
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";
Expand Down
14 changes: 5 additions & 9 deletions uSync8.Community.Contrib/Mappers/DocTypeGridMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<DocTypeGridMapper>(ex, "Failed to sanitize the import value for property (turn on debugging for full property value)");
logger.Debug<DocTypeGridMapper>("Failed DocTypeValue: {value}", value ?? String.Empty);
_logger.Warn<DocTypeGridMapper>(ex, "Failed to sanitize the import value for property (turn on debugging for full property value)");
_logger.Debug<DocTypeGridMapper>("Failed DocTypeValue: {value}", value ?? String.Empty);

return value;
}
Expand Down
6 changes: 4 additions & 2 deletions uSync8.ContentEdition/Mapping/Mappers/BlockListMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using Umbraco.Core.Logging;
using Umbraco.Core.Services;

using uSync8.Core;
Expand All @@ -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";
Expand Down
7 changes: 5 additions & 2 deletions uSync8.ContentEdition/Mapping/Mappers/NestedContentMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down
28 changes: 25 additions & 3 deletions uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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<DateTime>();
stringValue = date.ToString("s");
}
}
catch(Exception ex)
{
// something might have gone wrong
_logger.Warn<SyncNestedValueMapperBase>(ex, "Error getting formatted value");
}

return stringValue;
}
}
}

0 comments on commit 12281a7

Please sign in to comment.