Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add legacy migrators and type resolver to allow importing from Umbraco 7 #61

Merged
merged 22 commits into from Feb 26, 2024

Conversation

ronaldbarendse
Copy link
Contributor

@ronaldbarendse ronaldbarendse commented Feb 15, 2024

To allow importing the ZIP archived created by the Umbraco 7 export (see PR #60), additional artifact migrators and a type resolver need to be configured.

This PR adds an AddLegacyTypeResolver() extension method to add the artifact type resolver, which handles the namespace changes of artifact types that occurred between v2 and v4.

It also adds an AddLegacyMigrators() extension method that adds the artifact migrators to handle the large amount of changes between Umbraco 7 and 8:

  • Moving the pre-values of data types to the configuration property;
  • Moving the invariant release and expire dates of content to the (culture variant) schedule property;
  • Moving the 'allowed at root' and 'allowed child content types' of content/media/member types to the permissions property;
  • Migrating the data type configuration from pre-values to the correct configuration objects and new editor aliases for:
    • Umbraco.CheckBoxList (pre-values to value list)
    • Umbraco.ColorPickerAlias to Umbraco.ColorPicker (pre-values to value list)
    • Umbraco.ContentPicker2 to Umbraco.ContentPicker (removes invalid start node ID)
    • Umbraco.ContentPickerAlias to Umbraco.ContentPicker (removes invalid start node ID)
    • Umbraco.Date to Umbraco.DateTime
    • Umbraco.DropDown to Umbraco.DropDownListFlexible (pre-values to value list, single item select)
    • Umbraco.DropDownListFlexible (pre-values to value list, defaults to multiple item select)
    • Umbraco.DropdownlistMultiplePublishKeys to Umbraco.DropDownListFlexible (pre-values to value list, defaults to multiple item select)
    • Umbraco.DropdownlistPublishingKeys to Umbraco.DropDownListFlexible (pre-values to value list, defaults to single item select)
    • Umbraco.DropDownMultiple to Umbraco.DropDownListFlexible (pre-values to value list, defaults to multiple item select)
    • Umbraco.Grid (already handled by the pre-values data type migrator now)
    • Umbraco.ImageCropper (already handled by the pre-values data type migrator now)
    • Umbraco.ListView (already handled by the pre-values data type migrator now)
    • Umbraco.MediaPicker2 to Umbraco.MediaPicker (removes invalid start node ID, defaults to single item select)
    • Umbraco.MediaPicker (removes invalid start node ID)
    • Umbraco.MemberPicker2 to Umbraco.MemberPicker
    • Umbraco.MultiNodeTreePicker2 to Umbraco.MultiNodeTreePicker (removes invalid start node ID)
    • Umbraco.MultiNodeTreePicker (removes invalid start node ID)
    • Umbraco.MultipleMediaPicker to Umbraco.MediaPicker (removes invalid start node ID, defaults to multiple item select)
    • Umbraco.NestedContent (already handled by the pre-values data type migrator now)
    • Umbraco.NoEdit to Umbraco.Label
    • Umbraco.RadioButtonList (pre-values to value list, change database type from integer to nvarchar)
    • Umbraco.RelatedLinks2 to Umbraco.MultiUrlPicker
    • Umbraco.RelatedLinks to Umbraco.MultiUrlPicker
    • Umbraco.Textbox to Umbraco.TextBox
    • Umbraco.TextboxMultiple to Umbraco.TextArea
    • Umbraco.TinyMCEv3 to Umbraco.TinyMCE
  • Migrating pre-value property values for:
    • Umbraco.CheckBoxList
    • Umbraco.DropDown.Flexible
    • Umbraco.RadioButtonList

Some of these migrators use base classes that contain shared migration logic (and can be used to create your own migrators). I've also added an ElementTypeArtifactMigratorBase class that allows you to configure which document types need to be marked as element types (a concept added in Umbraco 8), so they can be used in Nested Content data types:

using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Deploy;
using Umbraco.Deploy.Contrib.Migrators.Legacy;
using Umbraco.Extensions;

[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
[ComposeAfter(typeof(DeployComposer))]
internal sealed class LegacyImportComposer : IComposer
{
    public void Compose(Composition composition)
    {
        composition.DeployArtifactTypeResolvers()
            .AddLegacyTypeResolver();

        composition.DeployArtifactMigrators()
            .AddLegacyMigrators()
            .Append<ElementTypeArtifactMigrator>();
    }

    private sealed class ElementTypeArtifactMigrator : ElementTypeArtifactMigratorBase
    {
        public ElementTypeArtifactMigrator()
            : base("testElement")
        { }
    }
}

@ronaldbarendse ronaldbarendse force-pushed the v4/feature/import-legacy-artifacts branch from 4f881de to 421ec50 Compare February 26, 2024 16:27
@ronaldbarendse ronaldbarendse merged commit 4a4cc3e into v4/dev Feb 26, 2024
4 checks passed
@ronaldbarendse ronaldbarendse deleted the v4/feature/import-legacy-artifacts branch February 26, 2024 23:00
@ronaldbarendse
Copy link
Contributor Author

To test the legacy migrators in v10 and up, you can use the following composer:

using Umbraco.Cms.Core.Composing;
using Umbraco.Deploy.Contrib.Migrators.Legacy;

internal class LegacyImportComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.DeployArtifactTypeResolvers()
            .AddLegacyTypeResolver();

        builder.DeployArtifactMigrators()
            .AddLegacyMigrators()
            .Append<ElementTypeArtifactMigrator>();
    }

    private class ElementTypeArtifactMigrator : ElementTypeArtifactMigratorBase
    {
        public ElementTypeArtifactMigrator()
            : base("testElement")
        { }
    }
}

I've created a very simple test site in v7 and used the export logic added in PR #60 to create the following ZIP archive: export-v7.zip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant