Skip to content

Commit

Permalink
fix: media picker 3 dependency checker.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Sep 14, 2024
1 parent 3acf135 commit c28161c
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions uSync.Core/Mapping/Mappers/MediaPicker3Mapper.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,8 +15,14 @@ namespace uSync.Core.Mapping.Mappers;

public class MediaPicker3Mapper : SyncValueMapperBase, ISyncMapper
{
public MediaPicker3Mapper(IEntityService entityService) : base(entityService)
{ }
private readonly ILogger<MediaPicker3Mapper> _logger;

public MediaPicker3Mapper(
IEntityService entityService,
ILogger<MediaPicker3Mapper> logger) : base(entityService)
{
_logger = logger;
}

public override string Name => "MediaPicker3 Mapper";

Expand Down Expand Up @@ -50,7 +58,10 @@ public override IEnumerable<uSyncDependency> 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<uSyncDependency>();

Expand All @@ -59,12 +70,9 @@ public override IEnumerable<uSyncDependency> 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);
}
Expand All @@ -76,12 +84,11 @@ private static Guid GetGuidValue(JsonObject obj, string key)
{
if (obj != null && obj.ContainsKey(key))
{
var attempt = obj[key].TryConvertTo<Guid>();
if (attempt.Success)
return attempt.Result;
var attempt = obj[key]?.ToString().TryConvertTo<Guid>();
if (attempt?.Success is true)
return attempt?.Result ?? Guid.Empty;
}

return Guid.Empty;

}
}

0 comments on commit c28161c

Please sign in to comment.