Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it so we can migrate variant properties, (for v8 -> v.x migrations. #257

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
vm.step = 'migrated';
vm.migrationResults = result.data;
vm.migrationStatus.migrated = true;
vm.migrationStatus.success = result.success;
vm.working = false;
}, function (error) {
vm.state = 'error';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,17 @@ <h2><localize key="usyncmigrate_convertTitle"></localize></h2>

({{vm.migrationResults.messages.length}} messages returned)
</umb-box-content>

</umb-box>

<div class="alert alert-danger" ng-if="vm.migrationResults.success == false">
There where one or more errors during the migration.
</div>

<usync-migration-results results="vm.migrationResults"
action="Migration"
is-valid="vm.resultValid"
show-all="true">
show-all="vm.migrationResults.success">
</usync-migration-results>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Extensions;
using uSync.Migrations.Core.Handlers.Shared;
using uSync.Migrations.Core.Migrators.Models;
using uSync.Migrations.Core.Services;

namespace uSync.Migrations.Core.Handlers.Eight;
Expand Down Expand Up @@ -61,4 +62,49 @@ protected override XElement GetBaseXml(XElement source, Guid parent, string cont
return target;
}

protected override IEnumerable<XElement> ConvertPropertyValue(string itemType, string contentType, XElement property, SyncMigrationContext context)
{
if (property.Elements("Value").Count() > 1)
{
// variant migration
// variant migration, doesn't support splitting, or variant migrators !
var editorAlias = context.ContentTypes.GetEditorAliasByTypeAndProperty(contentType, property.Name.LocalName)
?.OriginalEditorAlias ?? string.Empty;

try
{
var migrationProperty = new SyncMigrationContentProperty(
contentType, property.Name.LocalName, editorAlias, property.Value);

var migratedNodes = new XElement(property.Name.LocalName);

foreach (var node in property.Elements("Value"))
{

migrationProperty.Value = node.Value;
var migratedValue = MigrateContentValue(migrationProperty, context);

var migratedNode = new XElement(node.Name.LocalName, new XCData(migratedValue));
foreach (var attribute in node.Attributes())
{
migratedNode.Add(new XAttribute(attribute.Name.LocalName, attribute.Value));
}

migratedNodes.Add(migratedNode);

}

return migratedNodes.AsEnumerableOfOne();
}
catch(Exception ex)
{
_logger.LogError(ex, "Error trying to migrate variant node values {editor}", editorAlias);
throw;
}
}
else
{
return base.ConvertPropertyValue(itemType, contentType, property, context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public IEnumerable<MigrationMessage> Validate(SyncValidationContext validationCo
try
{
var source = XElement.Load(file);
// don't validate the empties
if (source.IsEmptyItem()) continue;

var alias = source.GetAlias();
var key = source.GetKey();
var editorAlias = GetEditorAlias(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SyncMigrationContentProperty(
PropertyAlias = propertyAlias;
}

public string? Value { get; private set; }
public string? Value { get; set; }

}

Expand Down
17 changes: 16 additions & 1 deletion uSync.Migrations.Migrators/BlockGrid/GridToBlockGridMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ private ILegacyGridEditorsConfig GetGridConfig(SyncMigrationContext context)
return contentProperty.Value;
}

var source = JsonConvert.DeserializeObject<GridValue>(contentProperty.Value);
var source = GetGridValueFromString(contentProperty.EditorAlias, contentProperty.Value);
if (source == null)
{
_logger.LogDebug(" Property {alias} is empty", contentProperty.EditorAlias);
return string.Empty;
}


// For some reason, DTGEs can sometimes end up without a view specified. This should fix it.
foreach (var section in source.Sections)
{
Expand Down Expand Up @@ -181,5 +182,19 @@ private ILegacyGridEditorsConfig GetGridConfig(SyncMigrationContext context)

return JsonConvert.SerializeObject(blockValue, Formatting.Indented);
}


private GridValue? GetGridValueFromString(string editorAlias, string value)
{
try
{
return JsonConvert.DeserializeObject<GridValue>(value);
}
catch(Exception ex)
{
_logger.LogError(ex, "Error getting grid {alias}", editorAlias);
throw;
}
}
}

Loading