diff --git a/uSync.Core/Mapping/Mappers/MediaPicker3Mapper.cs b/uSync.Core/Mapping/Mappers/MediaPicker3Mapper.cs index 8118037b..2fda89bd 100644 --- a/uSync.Core/Mapping/Mappers/MediaPicker3Mapper.cs +++ b/uSync.Core/Mapping/Mappers/MediaPicker3Mapper.cs @@ -1,4 +1,6 @@ -using System.Text.Json.Nodes; +using Microsoft.Extensions.Logging; + +using System.Text.Json.Nodes; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Services; @@ -13,8 +15,14 @@ namespace uSync.Core.Mapping.Mappers; public class MediaPicker3Mapper : SyncValueMapperBase, ISyncMapper { - public MediaPicker3Mapper(IEntityService entityService) : base(entityService) - { } + private readonly ILogger _logger; + + public MediaPicker3Mapper( + IEntityService entityService, + ILogger logger) : base(entityService) + { + _logger = logger; + } public override string Name => "MediaPicker3 Mapper"; @@ -50,7 +58,10 @@ public override IEnumerable GetDependencies(object value, strin var stringValue = value?.ToString(); if (stringValue.TryParseToJsonArray(out var images) is false || images == null || images.Count == 0) + { + _logger.LogWarning("no json images found for {value}", stringValue); return []; + } var dependencies = new List(); @@ -59,12 +70,9 @@ public override IEnumerable GetDependencies(object value, strin if (image == null) continue; var key = GetGuidValue(image, "mediaKey"); - if (key == Guid.Empty) continue; var udi = GuidUdi.Create(UdiEntityType.Media, key); - if (udi is null) continue; - var dependency = CreateDependency(udi as GuidUdi, flags); if (dependency is not null) dependencies.Add(dependency); } @@ -76,12 +84,11 @@ private static Guid GetGuidValue(JsonObject obj, string key) { if (obj != null && obj.ContainsKey(key)) { - var attempt = obj[key].TryConvertTo(); - if (attempt.Success) - return attempt.Result; + var attempt = obj[key]?.ToString().TryConvertTo(); + if (attempt?.Success is true) + return attempt?.Result ?? Guid.Empty; } return Guid.Empty; - } }