Skip to content

Commit 4d55013

Browse files
Merge branch 'v14/dev' into v14/bugfix/legacy-artifact-migrators
2 parents a23480a + 2416b7e commit 4d55013

19 files changed

+413
-18
lines changed

Directory.Build.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
<!-- Package Validation -->
2828
<PropertyGroup>
2929
<GenerateCompatibilitySuppressionFile>false</GenerateCompatibilitySuppressionFile>
30-
<!-- TODO (V14): Re-enable when 14 is released. -->
31-
<EnablePackageValidation>false</EnablePackageValidation>
30+
<EnablePackageValidation>true</EnablePackageValidation>
3231
<PackageValidationBaselineVersion>14.0.0</PackageValidationBaselineVersion>
3332
<EnableStrictModeForCompatibleFrameworksInPackage>true</EnableStrictModeForCompatibleFrameworksInPackage>
3433
<EnableStrictModeForCompatibleTfms>true</EnableStrictModeForCompatibleTfms>

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
<!-- Umbraco packages -->
1414
<ItemGroup>
1515
<PackageVersion Include="Umbraco.Cms.Web.Common" Version="[14.0.0, 15)" />
16-
<PackageVersion Include="Umbraco.Deploy.Infrastructure" Version="[14.0.0, 15)" />
16+
<PackageVersion Include="Umbraco.Deploy.Infrastructure" Version="[14.1.0-rc1, 15)" />
1717
</ItemGroup>
1818
</Project>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Text.Json;
5+
using System.Text.Json.Nodes;
6+
using System.Text.Json.Serialization;
7+
using Microsoft.Extensions.Logging;
8+
using Newtonsoft.Json;
9+
using Umbraco.Cms.Core;
10+
using Umbraco.Cms.Core.Deploy;
11+
using Umbraco.Cms.Core.Models;
12+
using Umbraco.Cms.Core.Models.Blocks;
13+
using Umbraco.Cms.Core.PropertyEditors;
14+
using Umbraco.Cms.Core.Serialization;
15+
using Umbraco.Cms.Core.Services;
16+
using Umbraco.Cms.Core.Strings;
17+
using Umbraco.Deploy.Infrastructure.Migrators;
18+
using Umbraco.Extensions;
19+
20+
namespace Umbraco.Deploy.Contrib.Migrators;
21+
22+
/// <summary>
23+
/// Migrates the property value when the editor of a property type changed from <see cref="Constants.PropertyEditors.Aliases.Grid" /> to <see cref="Constants.PropertyEditors.Aliases.BlockGrid" /> and supports DocTypeGridEditor.
24+
/// </summary>
25+
public class DocTypeGridEditorPropertyTypeMigrator : GridPropertyTypeMigrator
26+
{
27+
private readonly IJsonSerializer _jsonSerializer;
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="DocTypeGridEditorPropertyTypeMigrator" /> class.
31+
/// </summary>
32+
/// <param name="logger">The logger.</param>
33+
/// <param name="jsonSerializer">The JSON serializer.</param>
34+
/// <param name="dataTypeService">The data type service.</param>
35+
/// <param name="shortStringHelper">The short string helper.</param>
36+
/// <param name="contentTypeService">The content type service.</param>
37+
/// <param name="mediaService">The media service.</param>
38+
public DocTypeGridEditorPropertyTypeMigrator(ILogger<GridPropertyTypeMigrator> logger, IJsonSerializer jsonSerializer, IDataTypeService dataTypeService, IShortStringHelper shortStringHelper, IContentTypeService contentTypeService, IMediaService mediaService)
39+
: base(logger, jsonSerializer, dataTypeService, shortStringHelper, contentTypeService, mediaService)
40+
=> _jsonSerializer = jsonSerializer;
41+
42+
/// <inheritdoc />
43+
protected override BlockItemData? MigrateGridControl(GridValue.GridControl gridControl, BlockGridConfiguration configuration, IContextCache contextCache)
44+
{
45+
if (TryDeserialize(gridControl.Value, out DocTypeGridEditorValue? value))
46+
{
47+
return MigrateGridControl(value, configuration, contextCache);
48+
}
49+
50+
return base.MigrateGridControl(gridControl, configuration, contextCache);
51+
}
52+
53+
/// <summary>
54+
/// Migrates the grid control.
55+
/// </summary>
56+
/// <param name="value">The DTGE value.</param>
57+
/// <param name="configuration">The configuration.</param>
58+
/// <param name="contextCache">The context cache.</param>
59+
/// <returns>
60+
/// The block item data, or <c>null</c> if migration should be skipped.
61+
/// </returns>
62+
protected virtual BlockItemData? MigrateGridControl(DocTypeGridEditorValue value, BlockGridConfiguration configuration, IContextCache contextCache)
63+
{
64+
IContentType contentType = GetContentType(value.ContentTypeAlias, configuration, contextCache)
65+
?? throw new InvalidOperationException($"Migrating legacy grid failed, because content type with alias '{value.ContentTypeAlias}' could not be found (in the Block Grid configuration).");
66+
67+
return new BlockItemData()
68+
{
69+
Udi = Udi.Create(Constants.UdiEntityType.Element, value.Id),
70+
ContentTypeKey = contentType.Key,
71+
RawPropertyValues = value.Value
72+
};
73+
}
74+
75+
private bool TryDeserialize(JsonNode? value, [NotNullWhen(true)] out DocTypeGridEditorValue? docTypeGridEditorValue)
76+
{
77+
try
78+
{
79+
docTypeGridEditorValue = value switch
80+
{
81+
JsonObject jsonObject => jsonObject.Deserialize<DocTypeGridEditorValue>(),
82+
JsonNode jsonNode when jsonNode.GetValue<string>() is string json && json.DetectIsJson() => _jsonSerializer.Deserialize<DocTypeGridEditorValue>(json),
83+
_ => null
84+
};
85+
86+
return !string.IsNullOrEmpty(docTypeGridEditorValue?.ContentTypeAlias);
87+
}
88+
catch (JsonSerializationException)
89+
{
90+
docTypeGridEditorValue = null;
91+
return false;
92+
}
93+
}
94+
95+
/// <summary>
96+
/// The DTGE grid editor value.
97+
/// </summary>
98+
protected sealed class DocTypeGridEditorValue
99+
{
100+
/// <summary>
101+
/// Gets or sets the value.
102+
/// </summary>
103+
/// <value>
104+
/// The value.
105+
/// </value>
106+
[JsonPropertyName("value")]
107+
public Dictionary<string, object?> Value { get; set; } = new();
108+
109+
/// <summary>
110+
/// Gets or sets the content type alias.
111+
/// </summary>
112+
/// <value>
113+
/// The content type alias.
114+
/// </value>
115+
[JsonPropertyName("dtgeContentTypeAlias")]
116+
public string ContentTypeAlias { get; set; } = string.Empty;
117+
118+
/// <summary>
119+
/// Gets or sets the identifier.
120+
/// </summary>
121+
/// <value>
122+
/// The identifier.
123+
/// </value>
124+
[JsonPropertyName("id")]
125+
public Guid Id { get; set; } = Guid.NewGuid();
126+
}
127+
}

src/Umbraco.Deploy.Contrib/Migrators/Legacy/DataType/ColorPickerAliasDataTypeArtifactMigrator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Umbraco.Cms.Core.PropertyEditors;
55
using Umbraco.Cms.Core.Semver;
66
using Umbraco.Cms.Core.Serialization;
7+
using Umbraco.Deploy.Core;
78
using Umbraco.Deploy.Infrastructure.Artifacts;
89
using Umbraco.Deploy.Infrastructure.Migrators;
910

@@ -23,7 +24,7 @@ public class ColorPickerAliasDataTypeArtifactMigrator : ReplaceDataTypeArtifactM
2324
/// <param name="propertyEditors">The property editors.</param>
2425
/// <param name="configurationEditorJsonSerializer">The configuration editor JSON serializer.</param>
2526
public ColorPickerAliasDataTypeArtifactMigrator(PropertyEditorCollection propertyEditors, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
26-
: base(FromEditorAlias, Constants.PropertyEditors.Aliases.ColorPicker, propertyEditors, configurationEditorJsonSerializer)
27+
: base(FromEditorAlias, Constants.PropertyEditors.Aliases.ColorPicker, DeployConstants.PropertyEditors.UiAliases.ColorPicker, propertyEditors, configurationEditorJsonSerializer)
2728
=> MaxVersion = new SemVersion(3, 0, 0);
2829

2930
/// <inheritdoc />

src/Umbraco.Deploy.Contrib/Migrators/Legacy/DataType/ContentPickerReplaceDataTypeArtifactMigratorBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Umbraco.Cms.Core.PropertyEditors;
44
using Umbraco.Cms.Core.Semver;
55
using Umbraco.Cms.Core.Serialization;
6+
using Umbraco.Deploy.Core;
67
using Umbraco.Deploy.Infrastructure.Artifacts;
78

89
namespace Umbraco.Deploy.Contrib.Migrators.Legacy;
@@ -19,7 +20,7 @@ public abstract class ContentPickerReplaceDataTypeArtifactMigratorBase : LegacyR
1920
/// <param name="propertyEditors">The property editors.</param>
2021
/// <param name="configurationEditorJsonSerializer">The configuration editor JSON serializer.</param>
2122
protected ContentPickerReplaceDataTypeArtifactMigratorBase(string fromEditorAlias, PropertyEditorCollection propertyEditors, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
22-
: base(fromEditorAlias, Constants.PropertyEditors.Aliases.ContentPicker, propertyEditors, configurationEditorJsonSerializer)
23+
: base(fromEditorAlias, Constants.PropertyEditors.Aliases.ContentPicker, DeployConstants.PropertyEditors.UiAliases.DocumentPicker, propertyEditors, configurationEditorJsonSerializer)
2324
=> MaxVersion = new SemVersion(3, 0, 0);
2425

2526
/// <inheritdoc />

src/Umbraco.Deploy.Contrib/Migrators/Legacy/DataType/DateDataTypeArtifactMigrator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Umbraco.Cms.Core.PropertyEditors;
44
using Umbraco.Cms.Core.Semver;
55
using Umbraco.Cms.Core.Serialization;
6+
using Umbraco.Deploy.Core;
67
using Umbraco.Deploy.Infrastructure.Artifacts;
78

89
namespace Umbraco.Deploy.Contrib.Migrators.Legacy;
@@ -20,7 +21,7 @@ public class DateDataTypeArtifactMigrator : LegacyReplaceDataTypeArtifactMigrato
2021
/// <param name="propertyEditors">The property editors.</param>
2122
/// <param name="configurationEditorJsonSerializer">The configuration editor JSON serializer.</param>
2223
public DateDataTypeArtifactMigrator(PropertyEditorCollection propertyEditors, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
23-
: base(FromEditorAlias, Constants.PropertyEditors.Aliases.DateTime, propertyEditors, configurationEditorJsonSerializer)
24+
: base(FromEditorAlias, Constants.PropertyEditors.Aliases.DateTime, DeployConstants.PropertyEditors.UiAliases.DatePicker, propertyEditors, configurationEditorJsonSerializer)
2425
=> MaxVersion = new SemVersion(3, 0, 0);
2526

2627
/// <inheritdoc />

src/Umbraco.Deploy.Contrib/Migrators/Legacy/DataType/DropDownReplaceDataTypeArtifactMigratorBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Umbraco.Cms.Core.PropertyEditors;
44
using Umbraco.Cms.Core.Semver;
55
using Umbraco.Cms.Core.Serialization;
6+
using Umbraco.Deploy.Core;
67
using Umbraco.Deploy.Infrastructure.Artifacts;
78
using Umbraco.Deploy.Infrastructure.Migrators;
89

@@ -30,7 +31,7 @@ public abstract class DropDownReplaceDataTypeArtifactMigratorBase : ReplaceDataT
3031
/// <param name="propertyEditors">The property editors.</param>
3132
/// <param name="configurationEditorJsonSerializer">The configuration editor JSON serializer.</param>
3233
protected DropDownReplaceDataTypeArtifactMigratorBase(string fromEditorAlias, PropertyEditorCollection propertyEditors, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
33-
: base(fromEditorAlias, Constants.PropertyEditors.Aliases.DropDownListFlexible, propertyEditors, configurationEditorJsonSerializer)
34+
: base(fromEditorAlias, Constants.PropertyEditors.Aliases.DropDownListFlexible, DeployConstants.PropertyEditors.UiAliases.Dropdown, propertyEditors, configurationEditorJsonSerializer)
3435
=> MaxVersion = new SemVersion(3, 0, 0);
3536

3637
/// <inheritdoc />

src/Umbraco.Deploy.Contrib/Migrators/Legacy/DataType/LegacyReplaceDataTypeArtifactMigratorBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ public abstract class LegacyReplaceDataTypeArtifactMigratorBase : ReplaceDataTyp
2020
/// </summary>
2121
/// <param name="fromEditorAlias">The editor alias to migrate from.</param>
2222
/// <param name="toEditorAlias">The editor alias to migrate to.</param>
23+
/// <param name="toEditorUiAlias">The editor UI alias to migrate to.</param>
2324
/// <param name="propertyEditors">The property editors.</param>
2425
/// <param name="configurationEditorJsonSerializer">The configuration editor JSON serializer.</param>
25-
protected LegacyReplaceDataTypeArtifactMigratorBase(string fromEditorAlias, string toEditorAlias, PropertyEditorCollection propertyEditors, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
26-
: base(fromEditorAlias, toEditorAlias, propertyEditors, configurationEditorJsonSerializer)
26+
protected LegacyReplaceDataTypeArtifactMigratorBase(string fromEditorAlias, string toEditorAlias, string toEditorUiAlias, PropertyEditorCollection propertyEditors, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
27+
: base(fromEditorAlias, toEditorAlias, toEditorUiAlias, propertyEditors, configurationEditorJsonSerializer)
2728
=> _configurationEditorJsonSerializer = configurationEditorJsonSerializer;
2829

2930
/// <summary>

src/Umbraco.Deploy.Contrib/Migrators/Legacy/DataType/MediaPickerReplaceDataTypeArtifactMigratorBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Umbraco.Cms.Core.PropertyEditors;
44
using Umbraco.Cms.Core.Semver;
55
using Umbraco.Cms.Core.Serialization;
6+
using Umbraco.Deploy.Core;
67
using Umbraco.Deploy.Infrastructure.Artifacts;
78

89
namespace Umbraco.Deploy.Contrib.Migrators.Legacy;
@@ -27,7 +28,7 @@ public abstract class MediaPickerReplaceDataTypeArtifactMigratorBase : LegacyRep
2728
/// <param name="propertyEditors">The property editors.</param>
2829
/// <param name="configurationEditorJsonSerializer">The configuration editor JSON serializer.</param>
2930
protected MediaPickerReplaceDataTypeArtifactMigratorBase(string fromEditorAlias, PropertyEditorCollection propertyEditors, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
30-
: base(fromEditorAlias, Constants.PropertyEditors.Aliases.MediaPicker3, propertyEditors, configurationEditorJsonSerializer)
31+
: base(fromEditorAlias, Constants.PropertyEditors.Aliases.MediaPicker3, DeployConstants.PropertyEditors.UiAliases.MediaPicker, propertyEditors, configurationEditorJsonSerializer)
3132
=> MaxVersion = new SemVersion(3, 0, 0);
3233

3334
/// <inheritdoc />

src/Umbraco.Deploy.Contrib/Migrators/Legacy/DataType/MemberPicker2DataTypeArtifactMigrator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Umbraco.Cms.Core.PropertyEditors;
44
using Umbraco.Cms.Core.Semver;
55
using Umbraco.Cms.Core.Serialization;
6+
using Umbraco.Deploy.Core;
67
using Umbraco.Deploy.Infrastructure.Artifacts;
78
using Umbraco.Deploy.Infrastructure.Migrators;
89

@@ -21,7 +22,7 @@ public class MemberPicker2DataTypeArtifactMigrator : ReplaceDataTypeArtifactMigr
2122
/// <param name="propertyEditors">The property editors.</param>
2223
/// <param name="configurationEditorJsonSerializer">The configuration editor JSON serializer.</param>
2324
public MemberPicker2DataTypeArtifactMigrator(PropertyEditorCollection propertyEditors, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
24-
: base(FromEditorAlias, Constants.PropertyEditors.Aliases.MemberPicker, propertyEditors, configurationEditorJsonSerializer)
25+
: base(FromEditorAlias, Constants.PropertyEditors.Aliases.MemberPicker, DeployConstants.PropertyEditors.UiAliases.MemberPicker, propertyEditors, configurationEditorJsonSerializer)
2526
=> MaxVersion = new SemVersion(3, 0, 0);
2627

2728
/// <inheritdoc />

0 commit comments

Comments
 (0)