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

Fixes that PropertyType is not updated on contentTypes #262

Merged
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
20 changes: 19 additions & 1 deletion uSync.Migrations.Core/Context/ContentTypeMigrationContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using uSync.Migrations.Core.Configuration.Models;
using Umbraco.Extensions;
using uSync.Migrations.Core.Configuration.Models;
using uSync.Migrations.Core.Models;

namespace uSync.Migrations.Core.Context;
Expand Down Expand Up @@ -319,4 +320,21 @@ public void AddReplacementAlias(string original, string replacement)
public string GetReplacementAlias(string alias)
=> _replacementAliases.TryGetValue(alias, out var replacement)
? replacement : alias;


public void UpdatePropertyEditorTargets(DataTypeMigrationContext dataTypeContext)
{
foreach (var property in _propertyTypes.Values)
{
var editorAlias = property.UpdatedEditorAlias;

var newEditorName = dataTypeContext.GetPropertyEditorReplacementName(editorAlias);

if (newEditorName.IsNullOrWhiteSpace() == true)
{
continue;
}
property.UpdatedEditorAlias = newEditorName;
}
}
}
15 changes: 15 additions & 0 deletions uSync.Migrations.Core/Context/DataTypeMigrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class DataTypeMigrationContext
/// </summary>
private Dictionary<Guid, string> _dataTypeVariations { get; set; } = new();

private Dictionary<string, string> _dataTypePropertyEditorsReplacements = new();


/// <summary>
/// contains a lookup from defition (guid) to alias, so we can pass that along.
Expand Down Expand Up @@ -97,4 +99,17 @@ public string GetVariation(Guid guid, string defaultValue)
return dataTypeDefinition?.Key ?? null;
}

public void AddPropertyEditorsReplacementNames(string editorAlias, string newEditorAlias)
{
if (editorAlias != newEditorAlias)
_dataTypePropertyEditorsReplacements.TryAdd(editorAlias, newEditorAlias);
}

public string? GetPropertyEditorReplacementName(string editorAlias)
{
if (_dataTypePropertyEditorsReplacements.TryGetValue(editorAlias, out var value))
return value;

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ protected override IEnumerable<MigrationMessage> PreDoMigration(SyncMigrationCon
var messages = new List<MigrationMessage>();
messages.AddRange(base.PreDoMigration(context));
messages.AddRange(CreateAdditional(context));
messages.AddRange(UpdateDataTypePropertyReplacedEditors(context));
return messages;
}

Expand Down Expand Up @@ -324,4 +325,12 @@ private void AddAdditionaProperties(NewContentTypeInfo contentType, SyncMigratio
}
}

private IEnumerable<MigrationMessage> UpdateDataTypePropertyReplacedEditors(SyncMigrationContext context)
{
var messages = new List<MigrationMessage>();

context.ContentTypes.UpdatePropertyEditorTargets(context.DataTypes);

return messages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ protected abstract SyncMigrationDataTypeProperty GetMigrationDataTypeProperty(
var newDatabaseType = GetNewDatabaseType(migrator, dataTypeProperty, context);
var newConfig = GetDataTypeConfig(migrator, dataTypeProperty, context) ?? MakeEmptyLabelConfig(dataTypeProperty);

context.DataTypes.AddPropertyEditorsReplacementNames(editorAlias, newEditorAlias);

return MakeMigratedXml(key, name, GetLevel(source, level), newEditorAlias, newDatabaseType, folder, newConfig);
}

Expand Down
2 changes: 1 addition & 1 deletion uSync.Migrations.Core/Models/EditorAliasInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public EditorAliasInfo(string orginalEditorAlias, string updatedEditorAlias, Gui

public string OriginalEditorAlias { get; }

public string UpdatedEditorAlias { get; }
public string UpdatedEditorAlias { get; set; }

public Guid? DataTypeDefinition { get; set; }
}
Loading