Skip to content

Commit

Permalink
Merge branch 'pr/252'
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Nov 27, 2023
2 parents 3bea70d + 128864f commit d5c242e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
17 changes: 17 additions & 0 deletions uSync.Migrations.Core/Context/SyncMigrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public SyncMigrationContext(Guid migrationId, string sourceFolder, string siteFo

private HashSet<string> _blockedTypes = new(StringComparer.OrdinalIgnoreCase);
private Dictionary<int, Guid> _idKeyMap { get; set; } = new();
private Dictionary<Guid, string> _keyToUdiEntityTypeMap { get; set; } = new();

/// <summary>
/// is this item blocked based on alias and type.
Expand Down Expand Up @@ -85,6 +86,22 @@ public Guid GetKey(int id)
public int GetId(Guid key)
=> _idKeyMap?.FirstOrDefault(x => x.Value == key).Key ?? 0;

/// <summary>
/// Adds the reference from a guid key to find the entity type
/// </summary>
public void AddEntityMap(Guid key, string entityType)
=> _keyToUdiEntityTypeMap.TryAdd(key, entityType);

/// <summary>
/// Get the entity type for the guid
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public string GetEntityType(Guid key)
{
return _keyToUdiEntityTypeMap.TryGetValue(key, out var entityType) == true ? entityType : UmbConstants.UdiEntityType.Document;
}

public void Dispose()
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ protected override string GetPath(string alias, Guid parent, SyncMigrationContex
protected override IEnumerable<XElement>? GetProperties(XElement source)
=> source.Element("Properties")?.Elements() ?? Enumerable.Empty<XElement>();

protected override string? GetEntityType()
=> null;

protected override XElement GetBaseXml(XElement source, Guid parent, string contentType, int level, SyncMigrationContext context)
{
var target = new XElement(source.Name.LocalName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public ContentMigrationHandler(
ILogger<ContentMigrationHandler> logger)
: base(eventAggregator, migrationFileService, shortStringHelper, logger)
{ }

protected override string? GetEntityType()
{
return UmbConstants.UdiEntityType.Document;
}
}
5 changes: 5 additions & 0 deletions uSync.Migrations.Core/Handlers/Seven/MediaMigrationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public MediaMigrationHandler(
{ "webm", UmbConstants.Conventions.MediaTypes.VideoAlias },
});
}

protected override string? GetEntityType()
{
return UmbConstants.UdiEntityType.Media;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using uSync.Core;
using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Extensions;
using uSync.Migrations.Core.Handlers.Seven;
using uSync.Migrations.Core.Migrators;
using uSync.Migrations.Core.Migrators.Models;
using uSync.Migrations.Core.Models;
Expand Down Expand Up @@ -42,6 +43,12 @@ protected override void PrepareFile(XElement source, SyncMigrationContext contex

if (key != Guid.Empty)
{
var entityType = this.GetEntityType();
if (entityType != null)
{
context.AddEntityMap(key, entityType);
}

var id = GetId(source);
if (id > 0)
{
Expand All @@ -55,6 +62,8 @@ protected override void PrepareFile(XElement source, SyncMigrationContext contex
}
}

protected abstract string? GetEntityType();

protected abstract XElement GetBaseXml(XElement source, Guid parent, string contentType, int level, SyncMigrationContext context);

protected abstract Guid GetParent(XElement source);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Extensions;
Expand Down Expand Up @@ -49,8 +49,7 @@ public override string GetDatabaseType(SyncMigrationDataTypeProperty dataTypePro
{
if (Guid.TryParse(item, out var guid) == true)
{
// TODO: Eeek! This might possibly be content, media or member! [LK]
values.Add(Udi.Create(UmbConstants.UdiEntityType.Document, guid));
values.Add(Udi.Create(context.GetEntityType(guid), guid));
}
else if (UdiParser.TryParse<GuidUdi>(item, out var udi) == true)
{
Expand All @@ -62,8 +61,7 @@ public override string GetDatabaseType(SyncMigrationDataTypeProperty dataTypePro
var possibleGuid = context.GetKey(id);
if (possibleGuid != Guid.Empty)
{
// TODO: Eeek! This might possibly be content, media or member! [LK]
values.Add(Udi.Create(UmbConstants.UdiEntityType.Document, possibleGuid));
values.Add(Udi.Create(context.GetEntityType(possibleGuid), possibleGuid));
}
}
}
Expand Down

0 comments on commit d5c242e

Please sign in to comment.