From c28161cc2f6881efcb2c15f43138c3feb68d5d21 Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Sat, 14 Sep 2024 08:26:11 +0100 Subject: [PATCH] fix: media picker 3 dependency checker. --- .../Mapping/Mappers/MediaPicker3Mapper.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) 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; - } }