Skip to content

Commit

Permalink
Merge pull request #134 from Jumoo/wip/propertymigrators
Browse files Browse the repository at this point in the history
Nested content - Catching errors - reporting them back meaningfully.
  • Loading branch information
KevinJump authored Jun 5, 2023
2 parents 9a0b2c4 + d2645fe commit 5b9e544
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
21 changes: 14 additions & 7 deletions uSync.Migrations/Migrators/Core/NestedContentMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@ public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProp
{
var editorAlias = context.ContentTypes.GetEditorAliasByTypeAndProperty(row.ContentTypeAlias, property.Key);
if (editorAlias == null) continue;

var migrator = context.Migrators.TryGetMigrator(editorAlias.OriginalEditorAlias);
if (migrator != null)

try
{
var migrator = context.Migrators.TryGetMigrator(editorAlias.OriginalEditorAlias);
if (migrator != null)
{
row.RawPropertyValues[property.Key] = migrator.GetContentValue(
new SyncMigrationContentProperty(
row.ContentTypeAlias, property.Key, row.ContentTypeAlias, property.Value?.ToString()),
context);
}
}
catch(Exception ex)
{
row.RawPropertyValues[property.Key] = migrator.GetContentValue(
new SyncMigrationContentProperty(
row.ContentTypeAlias, property.Key, row.ContentTypeAlias, property.Value?.ToString()),
context);
throw new Exception($"Nested Error: [{editorAlias.OriginalEditorAlias} -{property.Key}] : {ex.Message}", ex);
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions uSync.Migrations/Migrators/Optional/NestedToBlockListMigrator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Newtonsoft.Json;
using Microsoft.Extensions.Logging;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using Umbraco.Cms.Core;
Expand All @@ -17,8 +19,12 @@ namespace uSync.Migrations.Migrators.Optional;
[SyncMigratorVersion(7,8)]
public class NestedToBlockListMigrator : SyncPropertyMigratorBase
{
public NestedToBlockListMigrator()
{ }
private readonly ILogger<NestedToBlockListMigrator> _logger;

public NestedToBlockListMigrator(ILogger<NestedToBlockListMigrator> logger)
{
_logger = logger;
}

public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
=> UmbConstants.PropertyEditors.Aliases.BlockList;
Expand Down Expand Up @@ -127,12 +133,18 @@ private object GetBlockListConfigFromNestedConfig(NestedContentConfiguration nes

foreach (var property in row.RawPropertyValues)
{
_logger.LogDebug("NestedToBlockList: {ContentType} {key}", row.ContentTypeAlias, property.Key);

var editorAlias = context.ContentTypes.GetEditorAliasByTypeAndProperty(row.ContentTypeAlias, property.Key);
if (editorAlias == null) continue;

_logger.LogDebug("NestedToBlockList: Property: {editorAlias}", editorAlias);

var migrator = context.Migrators.TryGetMigrator(editorAlias.OriginalEditorAlias);
if (migrator != null)
{
_logger.LogDebug("NestedToBlockList: Found Migrator: {migrator}", migrator.GetType().Name);

block.RawPropertyValues[property.Key] = migrator.GetContentValue(
new SyncMigrationContentProperty(
row.ContentTypeAlias,
Expand All @@ -141,6 +153,7 @@ private object GetBlockListConfigFromNestedConfig(NestedContentConfiguration nes
}
else
{
_logger.LogDebug("NestedToBlockList: No Migrator found");
block.RawPropertyValues[property.Key] = property.Value;
}
}
Expand Down

0 comments on commit 5b9e544

Please sign in to comment.