Skip to content

Commit 99cf5b1

Browse files
Add legacy migrators and type resolver to allow importing from Umbraco 7
1 parent 643c4bc commit 99cf5b1

File tree

51 files changed

+1793
-13
lines changed

Some content is hidden

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

51 files changed

+1793
-13
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Umbraco.Deploy.Contrib.Migrators.Legacy;
2+
using Umbraco.Deploy.Migrators;
3+
4+
namespace Umbraco.Extensions
5+
{
6+
public static class ArtifactMigratorCollectionBuilderExtensions
7+
{
8+
/// <summary>
9+
/// Adds the legacy artifact migrators to allow importing from Umbraco 7.
10+
/// </summary>
11+
/// <param name="artifactMigratorCollectionBuilder">The artifact migrator collection builder.</param>
12+
/// <returns>
13+
/// The artifact migrator collection builder.
14+
/// </returns>
15+
public static ArtifactMigratorCollectionBuilder AddLegacyMigrators(this ArtifactMigratorCollectionBuilder artifactMigratorCollectionBuilder)
16+
=> artifactMigratorCollectionBuilder
17+
// Pre-values to configuration
18+
.Append<PreValuesDataTypeArtifactJsonMigrator>()
19+
// Release/expire dates to schedule
20+
.Append<DocumentArtifactJsonMigrator>()
21+
// Allowed at root and child content types to permissions
22+
.Append<DocumentTypeArtifactJsonMigrator>()
23+
.Append<MediaTypeArtifactJsonMigrator>()
24+
.Append<MemberTypeArtifactJsonMigrator>()
25+
// Data types
26+
.Append<CheckBoxListDataTypeArtifactMigrator>()
27+
.Append<ColorPickerAliasDataTypeArtifactMigrator>()
28+
.Append<ContentPicker2DataTypeArtifactMigrator>()
29+
.Append<ContentPickerAliasDataTypeArtifactMigrator>()
30+
.Append<DateDataTypeArtifactMigrator>()
31+
.Append<DropDownDataTypeArtifactMigrator>()
32+
.Append<DropDownFlexibleDataTypeArtifactMigrator>()
33+
.Append<DropdownlistMultiplePublishKeysDataTypeArtifactMigrator>()
34+
.Append<DropdownlistPublishingKeysDataTypeArtifactMigrator>()
35+
.Append<DropDownMultipleDataTypeArtifactMigrator>()
36+
.Append<GridDataTypeArtifactMigrator>()
37+
.Append<ImageCropperDataTypeArtifactMigrator>()
38+
.Append<ListViewDataTypeArtifactMigrator>()
39+
.Append<MediaPicker2DataTypeArtifactMigrator>()
40+
.Append<MediaPickerDataTypeArtifactMigrator>()
41+
.Append<MemberPicker2DataTypeArtifactMigrator>()
42+
.Append<MultiNodeTreePicker2DataTypeArtifactMigrator>()
43+
.Append<MultiNodeTreePickerDataTypeArtifactMigrator>()
44+
.Append<MultipleMediaPickerDataTypeArtifactMigrator>()
45+
.Append<NestedContentDataTypeArtifactMigrator>()
46+
.Append<NoEditDataTypeArtifactMigrator>()
47+
.Append<RadioButtonListDataTypeArtifactMigrator>()
48+
.Append<RelatedLinks2DataTypeArtifactMigrator>()
49+
.Append<RelatedLinksDataTypeArtifactMigrator>()
50+
.Append<TextboxDataTypeArtifactMigrator>()
51+
.Append<TextboxMultipleDataTypeArtifactMigrator>()
52+
.Append<TinyMCEv3DataTypeArtifactMigrator>()
53+
// Property values
54+
.Append<CheckBoxListPropertyValueArtifactMigrator>()
55+
.Append<DropDownListFlexiblePropertyValueArtifactMigrator>()
56+
.Append<RadioButtonListPropertyValueArtifactMigrator>();
57+
}
58+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Umbraco.Deploy.Contrib.Connectors.Serialization;
2+
using Umbraco.Deploy.Serialization;
3+
4+
namespace Umbraco.Extensions
5+
{
6+
public static class ArtifactTypeResolverCollectionBuilderExtensions
7+
{
8+
/// <summary>
9+
/// Adds the legacy artifact type resolver to allow importing from Umbraco 7.
10+
/// </summary>
11+
/// <param name="artifactTypeResolverCollectionBuilder">The artifact type resolver collection builder.</param>
12+
/// <returns>
13+
/// The artifact type resolver collection builder.
14+
/// </returns>
15+
public static ArtifactTypeResolverCollectionBuilder AddLegacyTypeResolver(this ArtifactTypeResolverCollectionBuilder artifactTypeResolverCollectionBuilder)
16+
=> artifactTypeResolverCollectionBuilder.Append<LegacyArtifactTypeResolver>();
17+
}
18+
}

src/Umbraco.Deploy.Contrib.Connectors/GridCellValueConnectors/DocTypeGridEditorCellValueConnector.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public sealed override bool IsConnector(string view)
3636
public sealed override string GetValue(GridValue.GridControl gridControl, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)
3737
{
3838
// cancel if there's no values
39-
if (gridControl.Value == null || gridControl.Value.HasValues == false) return null;
39+
if (gridControl.Value == null || gridControl.Value.HasValues == false)
40+
{
41+
return null;
42+
}
4043

4144
_logger.Debug<DocTypeGridEditorCellValueConnector>($"GetValue - Grid Values: {gridControl.Value}");
4245

@@ -116,7 +119,6 @@ public sealed override void SetValue(GridValue.GridControl gridControl, IContext
116119
_logger.Debug<DocTypeGridEditorCellValueConnector>($"SetValue - GridControlValue - {gridControl.Value}");
117120

118121
var docTypeGridEditorContent = JsonConvert.DeserializeObject<DocTypeGridEditorValue>(gridControl.Value.ToString());
119-
120122
if (docTypeGridEditorContent == null)
121123
{
122124
return;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Umbraco.Core;
2+
using Umbraco.Core.Services;
3+
4+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
5+
{
6+
/// <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.
8+
/// </summary>
9+
public class CheckBoxListPropertyValueArtifactMigrator : PrevaluePropertyValueArtifactMigratorBase
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="CheckBoxListPropertyValueArtifactMigrator" /> class.
13+
/// </summary>
14+
/// <param name="contentTypeService">The content type service.</param>
15+
/// <param name="mediaTypeService">The media type service.</param>
16+
/// <param name="memberTypeService">The member type service.</param>
17+
public CheckBoxListPropertyValueArtifactMigrator(IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService)
18+
: base(Constants.PropertyEditors.Aliases.CheckBoxList, contentTypeService, mediaTypeService, memberTypeService)
19+
{ }
20+
}
21+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using Newtonsoft.Json.Linq;
3+
using Semver;
4+
using Umbraco.Core.Models;
5+
using Umbraco.Deploy.Artifacts.Content;
6+
using Umbraco.Deploy.Migrators;
7+
8+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
9+
{
10+
/// <summary>
11+
/// Migrates the <see cref="DocumentArtifact" /> JSON from Umbraco 7 release/expire date to schedule.
12+
/// </summary>
13+
public class DocumentArtifactJsonMigrator : ArtifactJsonMigratorBase<DocumentArtifact>
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="DocumentArtifactJsonMigrator" /> class.
17+
/// </summary>
18+
public DocumentArtifactJsonMigrator()
19+
=> MaxVersion = new SemVersion(3, 0, 0);
20+
21+
/// <inheritdoc />
22+
public override JToken Migrate(JToken artifactJson)
23+
{
24+
var schedule = new JArray();
25+
26+
var releaseDate = artifactJson["ReleaseDate"];
27+
if (releaseDate != null)
28+
{
29+
if (DateTime.TryParse(releaseDate.Value<string>(), out var releaseDateValue))
30+
{
31+
schedule.Add(new JObject()
32+
{
33+
["Date"] = releaseDateValue,
34+
["Culture"] = string.Empty,
35+
["Action"] = nameof(ContentScheduleAction.Release)
36+
});
37+
}
38+
39+
releaseDate.Remove();
40+
}
41+
42+
var expireDate = artifactJson["ExpireDate"];
43+
if (expireDate != null)
44+
{
45+
if (DateTime.TryParse(expireDate.Value<string>(), out var expireDateValue))
46+
{
47+
schedule.Add(new JObject()
48+
{
49+
["Date"] = expireDateValue,
50+
["Culture"] = string.Empty,
51+
["Action"] = nameof(ContentScheduleAction.Expire)
52+
});
53+
}
54+
55+
expireDate.Remove();
56+
}
57+
58+
artifactJson["Schedule"] = schedule;
59+
60+
return artifactJson;
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Umbraco.Core;
2+
using Umbraco.Core.Services;
3+
4+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
5+
{
6+
/// <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.
8+
/// </summary>
9+
public class DropDownListFlexiblePropertyValueArtifactMigrator : PrevaluePropertyValueArtifactMigratorBase
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="DropDownListFlexiblePropertyValueArtifactMigrator" /> class.
13+
/// </summary>
14+
/// <param name="contentTypeService">The content type service.</param>
15+
/// <param name="mediaTypeService">The media type service.</param>
16+
/// <param name="memberTypeService">The member type service.</param>
17+
public DropDownListFlexiblePropertyValueArtifactMigrator(IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService)
18+
: base(Constants.PropertyEditors.Aliases.DropDownListFlexible, contentTypeService, mediaTypeService, memberTypeService)
19+
{ }
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
using Semver;
4+
using Umbraco.Core.Services;
5+
using Umbraco.Deploy.Migrators;
6+
7+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
8+
{
9+
/// <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.
11+
/// </summary>
12+
public abstract class PrevaluePropertyValueArtifactMigratorBase : PropertyValueArtifactMigratorBase
13+
{
14+
private const string Delimiter = ";;";
15+
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="PrevaluePropertyValueArtifactMigratorBase" /> class.
18+
/// </summary>
19+
/// <param name="editorAlias">The editor alias.</param>
20+
/// <param name="contentTypeService">The content type service.</param>
21+
/// <param name="mediaTypeService">The media type service.</param>
22+
/// <param name="memberTypeService">The member type service.</param>
23+
public PrevaluePropertyValueArtifactMigratorBase(string editorAlias, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService)
24+
: base(editorAlias, contentTypeService, mediaTypeService, memberTypeService)
25+
=> MaxVersion = new SemVersion(3, 0, 0);
26+
27+
/// <inheritdoc />
28+
protected override string Migrate(string value)
29+
=> JsonConvert.SerializeObject(value.Split(new[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries));
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Umbraco.Core;
2+
using Umbraco.Core.Services;
3+
4+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
5+
{
6+
/// <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.
8+
/// </summary>
9+
public class RadioButtonListPropertyValueArtifactMigrator : PrevaluePropertyValueArtifactMigratorBase
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="RadioButtonListPropertyValueArtifactMigrator" /> class.
13+
/// </summary>
14+
/// <param name="contentTypeService">The content type service.</param>
15+
/// <param name="mediaTypeService">The media type service.</param>
16+
/// <param name="memberTypeService">The member type service.</param>
17+
public RadioButtonListPropertyValueArtifactMigrator(IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService)
18+
: base(Constants.PropertyEditors.Aliases.RadioButtonList, contentTypeService, mediaTypeService, memberTypeService)
19+
{ }
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Newtonsoft.Json.Linq;
2+
using Semver;
3+
using Umbraco.Deploy.Artifacts.ContentType;
4+
using Umbraco.Deploy.Migrators;
5+
6+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
7+
{
8+
/// <summary>
9+
/// Migrates the <typeparamref name="T"/> JSON from Umbraco 7 allowed at root and child content types to permissions.
10+
/// </summary>
11+
/// <typeparam name="T">The content type artifact.</typeparam>
12+
public abstract class ContentTypeArtifactJsonMigratorBase<T> : ArtifactJsonMigratorBase<T>
13+
where T : ContentTypeArtifactBase
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="ContentTypeArtifactJsonMigratorBase{T}" /> class.
17+
/// </summary>
18+
public ContentTypeArtifactJsonMigratorBase()
19+
=> MaxVersion = new SemVersion(3, 0, 0);
20+
21+
/// <inheritdoc />
22+
public override JToken Migrate(JToken artifactJson)
23+
{
24+
var permissions = new JObject();
25+
26+
var allowedAtRoot = artifactJson["AllowedAtRoot"];
27+
if (allowedAtRoot != null)
28+
{
29+
permissions["AllowedAtRoot"] = allowedAtRoot.Value<bool>();
30+
31+
allowedAtRoot.Remove();
32+
}
33+
34+
var allowedChildContentTypes = artifactJson["AllowedChildContentTypes"];
35+
if (allowedChildContentTypes != null)
36+
{
37+
permissions["AllowedChildContentTypes"] = allowedChildContentTypes;
38+
39+
allowedChildContentTypes.Remove();
40+
}
41+
42+
artifactJson["Permissions"] = permissions;
43+
44+
return artifactJson;
45+
}
46+
}
47+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Umbraco.Deploy.Artifacts.ContentType;
2+
3+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy
4+
{
5+
/// <summary>
6+
/// Migrates the <see cref="DocumentTypeArtifact" /> JSON from Umbraco 7 allowed at root and child content types to permissions.
7+
/// </summary>
8+
public class DocumentTypeArtifactJsonMigrator : ContentTypeArtifactJsonMigratorBase<DocumentTypeArtifact>
9+
{ }
10+
}

0 commit comments

Comments
 (0)