Skip to content

Commit

Permalink
Merge pull request #262 from CodingDK/feature/contentType-property-ty…
Browse files Browse the repository at this point in the history
…pe-fix

Fixes that PropertyType is not updated on contentTypes
  • Loading branch information
KevinJump authored Apr 20, 2024
2 parents c4562c7 + 1f24938 commit 42c2a38
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
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; }
}

0 comments on commit 42c2a38

Please sign in to comment.