Skip to content

Commit 421ec50

Browse files
Parse pre-value serialized JSON to simplify data type configuration migration
1 parent e1b82af commit 421ec50

File tree

45 files changed

+276
-680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+276
-680
lines changed

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="UmbracoCms.Web" Version="[8.1.0, 9)" IncludeAssets="compile" />
16-
<PackageVersion Include="UmbracoDeploy.Core" Version="[4.10.0-alpha11785, 5)" IncludeAssets="compile" />
16+
<PackageVersion Include="UmbracoDeploy.Core" Version="[4.10.0-alpha11787, 5)" IncludeAssets="compile" />
1717
</ItemGroup>
1818
</Project>

nuget.config

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@
33
<packageSources>
44
<clear />
55
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
6-
<add key="Umbraco Cloud" value="https://www.myget.org/F/uaas/api/v3/index.json" />
76
<add key="Umbraco Prereleases" value="https://www.myget.org/F/umbracoprereleases/api/v3/index.json" />
87
<add key="Umbraco Nightly" value="https://www.myget.org/F/umbraconightly/api/v3/index.json" />
98
</packageSources>
9+
<packageSourceMapping>
10+
<!-- Ensure all packages are pulled from NuGet by default -->
11+
<packageSource key="nuget">
12+
<package pattern="*" />
13+
<package pattern="UmbracoCms" />
14+
<package pattern="UmbracoCms.*" />
15+
<package pattern="UmbracoDeploy.*" />
16+
</packageSource>
17+
<!-- Only allow CMS and Deploy packages to be pulled from MyGet -->
18+
<packageSource key="Umbraco Prereleases">
19+
<package pattern="UmbracoCms" />
20+
<package pattern="UmbracoCms.*" />
21+
<package pattern="UmbracoDeploy.*" />
22+
</packageSource>
23+
<packageSource key="Umbraco Nightly">
24+
<package pattern="UmbracoCms" />
25+
<package pattern="UmbracoCms.*" />
26+
<package pattern="UmbracoDeploy.*" />
27+
</packageSource>
28+
</packageSourceMapping>
1029
</configuration>

src/Umbraco.Deploy.Contrib/Extensions/ArtifactMigratorCollectionBuilderExtensions.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Umbraco.Deploy.Contrib.Migrators.Legacy;
1+
using Umbraco.Deploy.Contrib.Migrators.Legacy;
22
using Umbraco.Deploy.Migrators;
33

44
namespace Umbraco.Extensions
@@ -19,9 +19,7 @@ public static ArtifactMigratorCollectionBuilder AddLegacyMigrators(this Artifact
1919
// Release/expire dates to schedule
2020
.Append<DocumentArtifactJsonMigrator>()
2121
// Allowed at root and child content types to permissions
22-
.Append<DocumentTypeArtifactJsonMigrator>()
23-
.Append<MediaTypeArtifactJsonMigrator>()
24-
.Append<MemberTypeArtifactJsonMigrator>()
22+
.Append<ContentTypeArtifactJsonMigrator>()
2523
// Data types
2624
.Append<CheckBoxListDataTypeArtifactMigrator>()
2725
.Append<ColorPickerAliasDataTypeArtifactMigrator>()
@@ -33,16 +31,12 @@ public static ArtifactMigratorCollectionBuilder AddLegacyMigrators(this Artifact
3331
.Append<DropdownlistMultiplePublishKeysDataTypeArtifactMigrator>()
3432
.Append<DropdownlistPublishingKeysDataTypeArtifactMigrator>()
3533
.Append<DropDownMultipleDataTypeArtifactMigrator>()
36-
.Append<GridDataTypeArtifactMigrator>()
37-
.Append<ImageCropperDataTypeArtifactMigrator>()
38-
.Append<ListViewDataTypeArtifactMigrator>()
3934
.Append<MediaPicker2DataTypeArtifactMigrator>()
4035
.Append<MediaPickerDataTypeArtifactMigrator>()
4136
.Append<MemberPicker2DataTypeArtifactMigrator>()
4237
.Append<MultiNodeTreePicker2DataTypeArtifactMigrator>()
4338
.Append<MultiNodeTreePickerDataTypeArtifactMigrator>()
4439
.Append<MultipleMediaPickerDataTypeArtifactMigrator>()
45-
.Append<NestedContentDataTypeArtifactMigrator>()
4640
.Append<NoEditDataTypeArtifactMigrator>()
4741
.Append<RadioButtonListDataTypeArtifactMigrator>()
4842
.Append<RelatedLinks2DataTypeArtifactMigrator>()

src/Umbraco.Deploy.Contrib/Migrators/Legacy/Content/CheckBoxListPropertyValueArtifactMigrator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
using Umbraco.Core;
1+
using Umbraco.Core;
22
using Umbraco.Core.Services;
3+
using Umbraco.Deploy.Artifacts.Content;
4+
using Umbraco.Deploy.Connectors.ServiceConnectors.Wrappers;
35

46
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
57
{
68
/// <summary>
7-
/// Migrates the <see cref="PropertyValueWithSegments" /> using the <see cref="Constants.PropertyEditors.Aliases.CheckBoxList" /> editor from the <see cref="ContentArtifactBase" /> containing prevalues (seperated by <see cref="Delimiter" />) from Umbraco 7 to a JSON array.
9+
/// Migrates the <see cref="PropertyValueWithSegments" /> using the <see cref="Constants.PropertyEditors.Aliases.CheckBoxList" /> editor from the <see cref="ContentArtifactBase" /> containing prevalues (seperated by <see cref="PrevaluePropertyValueArtifactMigratorBase.Delimiter" />) from Umbraco 7 to a JSON array.
810
/// </summary>
911
public class CheckBoxListPropertyValueArtifactMigrator : PrevaluePropertyValueArtifactMigratorBase
1012
{
13+
/// <inheritdoc />
14+
protected override bool Multiple => true;
15+
1116
/// <summary>
1217
/// Initializes a new instance of the <see cref="CheckBoxListPropertyValueArtifactMigrator" /> class.
1318
/// </summary>

src/Umbraco.Deploy.Contrib/Migrators/Legacy/Content/DocumentArtifactJsonMigrator.cs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using Newtonsoft.Json.Linq;
32
using Semver;
43
using Umbraco.Core.Models;
@@ -23,36 +22,26 @@ public override JToken Migrate(JToken artifactJson)
2322
{
2423
var schedule = new JArray();
2524

26-
var releaseDate = artifactJson["ReleaseDate"];
27-
if (releaseDate != null)
25+
if (artifactJson["ReleaseDate"] is JValue releaseDate &&
26+
releaseDate.Value != null)
2827
{
29-
if (DateTime.TryParse(releaseDate.Value<string>(), out var releaseDateValue))
28+
schedule.Add(new JObject()
3029
{
31-
schedule.Add(new JObject()
32-
{
33-
["Date"] = releaseDateValue,
34-
["Culture"] = string.Empty,
35-
["Action"] = nameof(ContentScheduleAction.Release)
36-
});
37-
}
38-
39-
releaseDate.Remove();
30+
["Date"] = releaseDate.Value<string>(),
31+
["Culture"] = string.Empty,
32+
["Action"] = nameof(ContentScheduleAction.Release)
33+
});
4034
}
4135

42-
var expireDate = artifactJson["ExpireDate"];
43-
if (expireDate != null)
36+
if (artifactJson["ExpireDate"] is JValue expireDate &&
37+
expireDate.Value != null)
4438
{
45-
if (DateTime.TryParse(expireDate.Value<string>(), out var expireDateValue))
39+
schedule.Add(new JObject()
4640
{
47-
schedule.Add(new JObject()
48-
{
49-
["Date"] = expireDateValue,
50-
["Culture"] = string.Empty,
51-
["Action"] = nameof(ContentScheduleAction.Expire)
52-
});
53-
}
54-
55-
expireDate.Remove();
41+
["Date"] = expireDate,
42+
["Culture"] = string.Empty,
43+
["Action"] = nameof(ContentScheduleAction.Expire)
44+
});
5645
}
5746

5847
artifactJson["Schedule"] = schedule;

src/Umbraco.Deploy.Contrib/Migrators/Legacy/Content/DropDownListFlexiblePropertyValueArtifactMigrator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
using Umbraco.Core;
1+
using Umbraco.Core;
22
using Umbraco.Core.Services;
3+
using Umbraco.Deploy.Artifacts.Content;
4+
using Umbraco.Deploy.Connectors.ServiceConnectors.Wrappers;
35

46
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
57
{
68
/// <summary>
7-
/// Migrates the <see cref="PropertyValueWithSegments" /> using the <see cref="Constants.PropertyEditors.Aliases.DropDownListFlexible" /> editor from the <see cref="ContentArtifactBase" /> containing prevalues (seperated by <see cref="Delimiter" />) from Umbraco 7 to a JSON array.
9+
/// Migrates the <see cref="PropertyValueWithSegments" /> using the <see cref="Constants.PropertyEditors.Aliases.DropDownListFlexible" /> editor from the <see cref="ContentArtifactBase" /> containing prevalues (seperated by <see cref="PrevaluePropertyValueArtifactMigratorBase.Delimiter" />) from Umbraco 7 to a JSON array.
810
/// </summary>
911
public class DropDownListFlexiblePropertyValueArtifactMigrator : PrevaluePropertyValueArtifactMigratorBase
1012
{
13+
/// <inheritdoc />
14+
protected override bool Multiple => true;
15+
1116
/// <summary>
1217
/// Initializes a new instance of the <see cref="DropDownListFlexiblePropertyValueArtifactMigrator" /> class.
1318
/// </summary>
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
using System;
1+
using System;
22
using Newtonsoft.Json;
33
using Semver;
44
using Umbraco.Core.Services;
5+
using Umbraco.Deploy.Artifacts.Content;
6+
using Umbraco.Deploy.Connectors.ServiceConnectors.Wrappers;
57
using Umbraco.Deploy.Migrators;
68

79
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
810
{
911
/// <summary>
10-
/// Migrates the <see cref="PropertyValueWithSegments" /> using the specified editor alias from the <see cref="ContentArtifactBase" /> containing prevalues (seperated by <see cref="Delimiter" />) from Umbraco 7 to a JSON array.
12+
/// Migrates the <see cref="PropertyValueWithSegments" /> using the specified editor alias from the <see cref="ContentArtifactBase" /> containing prevalues (seperated by <see cref="Delimiter" />) from Umbraco 7 to a single value or JSON array.
1113
/// </summary>
1214
public abstract class PrevaluePropertyValueArtifactMigratorBase : PropertyValueArtifactMigratorBase
1315
{
1416
private const string Delimiter = ";;";
1517

18+
/// <summary>
19+
/// Gets a value indicating whether the property stored multiple prevalues as a JSON array or single value.
20+
/// </summary>
21+
/// <value>
22+
/// <c>true</c> if multiple prevalues are stored as a JSON array; otherwise, <c>false</c>.
23+
/// </value>
24+
protected abstract bool Multiple { get; }
25+
1626
/// <summary>
1727
/// Initializes a new instance of the <see cref="PrevaluePropertyValueArtifactMigratorBase" /> class.
1828
/// </summary>
@@ -21,11 +31,21 @@ public abstract class PrevaluePropertyValueArtifactMigratorBase : PropertyValueA
2131
/// <param name="mediaTypeService">The media type service.</param>
2232
/// <param name="memberTypeService">The member type service.</param>
2333
public PrevaluePropertyValueArtifactMigratorBase(string editorAlias, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService)
24-
: base(editorAlias, contentTypeService, mediaTypeService, memberTypeService)
25-
=> MaxVersion = new SemVersion(3, 0, 0);
34+
: base(editorAlias, contentTypeService, mediaTypeService, memberTypeService)
35+
=> MaxVersion = new SemVersion(3, 0, 0);
2636

2737
/// <inheritdoc />
2838
protected override string Migrate(string value)
29-
=> JsonConvert.SerializeObject(value.Split(new[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries));
39+
{
40+
var values = value?.Split(new[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries);
41+
if (values == null || values.Length == 0)
42+
{
43+
return null;
44+
}
45+
46+
return Multiple
47+
? JsonConvert.SerializeObject(values)
48+
: values[0];
49+
}
3050
}
3151
}

src/Umbraco.Deploy.Contrib/Migrators/Legacy/Content/RadioButtonListPropertyValueArtifactMigrator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
using Umbraco.Core;
1+
using Umbraco.Core;
22
using Umbraco.Core.Services;
3+
using Umbraco.Deploy.Artifacts.Content;
4+
using Umbraco.Deploy.Connectors.ServiceConnectors.Wrappers;
35

46
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
57
{
68
/// <summary>
7-
/// Migrates the <see cref="PropertyValueWithSegments" /> using the <see cref="Constants.PropertyEditors.Aliases.RadioButtonList" /> editor from the <see cref="ContentArtifactBase" /> containing prevalues (seperated by <see cref="Delimiter" />) from Umbraco 7 to a JSON array.
9+
/// Migrates the <see cref="PropertyValueWithSegments" /> using the <see cref="Constants.PropertyEditors.Aliases.RadioButtonList" /> editor from the <see cref="ContentArtifactBase" /> containing prevalues (seperated by <see cref="PrevaluePropertyValueArtifactMigratorBase.Delimiter" />) from Umbraco 7 to a JSON array.
810
/// </summary>
911
public class RadioButtonListPropertyValueArtifactMigrator : PrevaluePropertyValueArtifactMigratorBase
1012
{
13+
/// <inheritdoc />
14+
protected override bool Multiple => false;
15+
1116
/// <summary>
1217
/// Initializes a new instance of the <see cref="RadioButtonListPropertyValueArtifactMigrator" /> class.
1318
/// </summary>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using Newtonsoft.Json.Linq;
3+
using Semver;
4+
using Umbraco.Core;
5+
using Umbraco.Deploy.Artifacts.ContentType;
6+
using Umbraco.Deploy.Migrators;
7+
8+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
9+
{
10+
/// <summary>
11+
/// Migrates the <see cref="ContentTypeArtifactBase" /> JSON from Umbraco 7 allowed at root and child content types to permissions.
12+
/// </summary>
13+
public class ContentTypeArtifactJsonMigrator : ArtifactJsonMigratorBase<ContentTypeArtifactBase>
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="ContentTypeArtifactJsonMigrator" /> class.
17+
/// </summary>
18+
public ContentTypeArtifactJsonMigrator()
19+
=> MaxVersion = new SemVersion(3, 0, 0);
20+
21+
protected override bool CanMigrateType(Type type)
22+
=> type.Inherits<ContentTypeArtifactBase>();
23+
24+
/// <inheritdoc />
25+
public override JToken Migrate(JToken artifactJson)
26+
{
27+
var permissions = new JObject();
28+
29+
if (artifactJson["AllowedAtRoot"] is JValue allowedAtRootValue &&
30+
allowedAtRootValue.Value != null)
31+
{
32+
permissions["AllowedAtRoot"] = allowedAtRootValue;
33+
}
34+
35+
if (artifactJson["AllowedChildContentTypes"] is JArray allowedChildContentTypesToken)
36+
{
37+
permissions["AllowedChildContentTypes"] = allowedChildContentTypesToken;
38+
}
39+
40+
artifactJson["Permissions"] = permissions;
41+
42+
return artifactJson;
43+
}
44+
}
45+
}

src/Umbraco.Deploy.Contrib/Migrators/Legacy/ContentType/ContentTypeArtifactJsonMigratorBase.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)