Skip to content

Commit 1f24938

Browse files
committed
Fixes that PropertyType is not updated on contentTypes
1 parent c074840 commit 1f24938

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

uSync.Migrations.Core/Context/ContentTypeMigrationContext.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using uSync.Migrations.Core.Configuration.Models;
1+
using Umbraco.Extensions;
2+
using uSync.Migrations.Core.Configuration.Models;
23
using uSync.Migrations.Core.Models;
34

45
namespace uSync.Migrations.Core.Context;
@@ -319,4 +320,21 @@ public void AddReplacementAlias(string original, string replacement)
319320
public string GetReplacementAlias(string alias)
320321
=> _replacementAliases.TryGetValue(alias, out var replacement)
321322
? replacement : alias;
323+
324+
325+
public void UpdatePropertyEditorTargets(DataTypeMigrationContext dataTypeContext)
326+
{
327+
foreach (var property in _propertyTypes.Values)
328+
{
329+
var editorAlias = property.UpdatedEditorAlias;
330+
331+
var newEditorName = dataTypeContext.GetPropertyEditorReplacementName(editorAlias);
332+
333+
if (newEditorName.IsNullOrWhiteSpace() == true)
334+
{
335+
continue;
336+
}
337+
property.UpdatedEditorAlias = newEditorName;
338+
}
339+
}
322340
}

uSync.Migrations.Core/Context/DataTypeMigrationContext.cs

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class DataTypeMigrationContext
2222
/// </summary>
2323
private Dictionary<Guid, string> _dataTypeVariations { get; set; } = new();
2424

25+
private Dictionary<string, string> _dataTypePropertyEditorsReplacements = new();
26+
2527

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

102+
public void AddPropertyEditorsReplacementNames(string editorAlias, string newEditorAlias)
103+
{
104+
if (editorAlias != newEditorAlias)
105+
_dataTypePropertyEditorsReplacements.TryAdd(editorAlias, newEditorAlias);
106+
}
107+
108+
public string? GetPropertyEditorReplacementName(string editorAlias)
109+
{
110+
if (_dataTypePropertyEditorsReplacements.TryGetValue(editorAlias, out var value))
111+
return value;
112+
113+
return null;
114+
}
100115
}

uSync.Migrations.Core/Handlers/Shared/SharedContentTypeBaseHandler.cs

+9
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ protected override IEnumerable<MigrationMessage> PreDoMigration(SyncMigrationCon
259259
var messages = new List<MigrationMessage>();
260260
messages.AddRange(base.PreDoMigration(context));
261261
messages.AddRange(CreateAdditional(context));
262+
messages.AddRange(UpdateDataTypePropertyReplacedEditors(context));
262263
return messages;
263264
}
264265

@@ -324,4 +325,12 @@ private void AddAdditionaProperties(NewContentTypeInfo contentType, SyncMigratio
324325
}
325326
}
326327

328+
private IEnumerable<MigrationMessage> UpdateDataTypePropertyReplacedEditors(SyncMigrationContext context)
329+
{
330+
var messages = new List<MigrationMessage>();
331+
332+
context.ContentTypes.UpdatePropertyEditorTargets(context.DataTypes);
333+
334+
return messages;
335+
}
327336
}

uSync.Migrations.Core/Handlers/Shared/SharedDataTypeHandler.cs

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ protected abstract SyncMigrationDataTypeProperty GetMigrationDataTypeProperty(
161161
var newDatabaseType = GetNewDatabaseType(migrator, dataTypeProperty, context);
162162
var newConfig = GetDataTypeConfig(migrator, dataTypeProperty, context) ?? MakeEmptyLabelConfig(dataTypeProperty);
163163

164+
context.DataTypes.AddPropertyEditorsReplacementNames(editorAlias, newEditorAlias);
165+
164166
return MakeMigratedXml(key, name, GetLevel(source, level), newEditorAlias, newDatabaseType, folder, newConfig);
165167
}
166168

uSync.Migrations.Core/Models/EditorAliasInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public EditorAliasInfo(string orginalEditorAlias, string updatedEditorAlias, Gui
1111

1212
public string OriginalEditorAlias { get; }
1313

14-
public string UpdatedEditorAlias { get; }
14+
public string UpdatedEditorAlias { get; set; }
1515

1616
public Guid? DataTypeDefinition { get; set; }
1717
}

0 commit comments

Comments
 (0)