Usync migrations custom migrator

I am upgrading a site from v8 to v13. I am trying to build a migrator to migrate old grid editors to block grid with the code below. The content type is being created correctly with the values i provide when running the import but the properties are not. Any ideas why the properties are not being created?

public class PromotedMigrator : GridBlockMigratorSimpleBase, ISyncBlockMigrator
 {
     public PromotedMigrator(IShortStringHelper shortStringHelper)
         : base(shortStringHelper) { }

     public string[] Aliases => new[] { "promoted" };

     public override string GetEditorAlias(ILegacyGridEditorConfig editor) => "Promoted";



     public IEnumerable<NewContentTypeInfo> AdditionalContentTypes(ILegacyGridEditorConfig editor)
     {
         var alias = this.GetContentTypeAlias(editor);

         return new NewContentTypeInfo(
             alias.ToGuid(),
             alias,
             editor.Name ?? editor.Alias!,
             $"{editor.Icon ?? "icon-book"} color-purple",
             "BlockGrid/Elements")
         {
             Description = $"Converted from Grid {editor.Name} element using custom migrator ",
             IsElement = true,
             Properties = new List<NewContentTypeProperty>
             {
                 new NewContentTypeProperty(
                     alias: "title",
                     name: "Title",
                     dataTypeAlias: "Umbraco.TextBox"
                     )
             }
         }.AsEnumerableOfOne();
     }



     public Dictionary<string, object> GetPropertyValues(GridValue.GridControl control, SyncMigrationContext context)
     {
         var val = new Dictionary<string, object>();
         var data = control.Value; // this is the JSON input value from the U8 grid

         var title = data?.Value<string>("title");

         val.Add("title", title);

         return val;
     }
 }

Hi,

The code that runs though the property values looks for the “GridEditorAlias”, in the “View” or “Editor” value from the grid.

this will be in the source content, but there should be a Warning in the logs when it can’t be found that should help.

If you look for something in the logs starting “No Block Migrator for” then hopefully you should see what uSync.Migrations thinks the GridEditorAlias is


the code (below - first tries to get it via the view name, and if not via the editor name. So if your editor name doesn’t change i would use that, but views can sometimes be the thing that is needed

public ISyncBlockMigrator? GetMigrator(GridValue.GridEditor gridEditor)
{

    ISyncBlockMigrator? migrator;

    var viewName = Path.GetFileNameWithoutExtension(gridEditor?.View ?? "");
    if (!string.IsNullOrWhiteSpace(viewName))
    {
        migrator = GetMigrator(viewName);
        if (migrator != null) return migrator;
    }

    migrator = GetMigrator(gridEditor?.Alias);
    if (migrator != null) return migrator;

    return GetDefaultMigrator();
}

Thx for replying @KevinJump!

Creating the blockgrid element when running the Usync import is not a problem. It gets created correctly as you can see in the image below, it gets the correct description etc.

What i am confused about is the part where the properties is defined. I have defined a property named “Title” that should be created but are not.

         return new NewContentTypeInfo(
             alias.ToGuid(),
             alias,
             editor.Name ?? editor.Alias!,
             $"{editor.Icon ?? "icon-book"} color-purple",
             "BlockGrid/Elements")
         {
             Description = $"Converted from Grid {editor.Name} element using custom migrator 2",
             IsElement = true,
             Properties = new List<NewContentTypeProperty>
             {
                 new NewContentTypeProperty(
                     alias: "title",
                     name: "Title",
                     dataTypeAlias: "Umbraco.TextBox"
                     )
             }
         }.AsEnumerableOfOne();

Hi,

done a little testing, i think you are missing a ‘new’ keyword on the AdditionalContentTypes method and probably an override on GetPropertyValues, so

public class PromotedMigrator : GridBlockMigratorSimpleBase, ISyncBlockMigrator
{
    public PromotedMigrator(IShortStringHelper shortStringHelper)
        : base(shortStringHelper) { }

    public string[] Aliases => new[] { "promoted" };

    public override string GetEditorAlias(ILegacyGridEditorConfig editor) => "Promoted";

    public new IEnumerable<NewContentTypeInfo> AdditionalContentTypes(ILegacyGridEditorConfig editor)
    {
        var alias = this.GetContentTypeAlias(editor);

        return new NewContentTypeInfo(
            alias.ToGuid(),
            alias,
            editor.Name ?? editor.Alias!,
            $"{editor.Icon ?? "icon-book"} color-purple",
            "BlockGrid/Elements")
        {
            Description = $"Converted from Grid {editor.Name} element using custom migrator ",
            IsElement = true,
            Properties = new List<NewContentTypeProperty>
             {
                 new NewContentTypeProperty(
                     alias: "title",
                     name: "Title",
                     dataTypeAlias: "Umbraco.TextBox"
                     )
             }
        }.AsEnumerableOfOne();
    }

    public override Dictionary<string, object> GetPropertyValues(GridValue.GridControl control, SyncMigrationContext context)
    {
        var val = new Dictionary<string, object>();
        var data = control.Value; // this is the JSON input value from the U8 grid

        var title = data?.Value<string>("title");

        val.Add("title", title);

        return val;
    }
}

I think what was happening is the base AdditionalContentTypes method was running so creating a new document type but not with your new property.

Oh, i found the issue. I should use the name of the datatype i want, not the alias. so it should be Textstring and not Umbraco.TextBox.

                    new NewContentTypeProperty(
                        alias: "title",
                        name: "Title",
                        dataTypeAlias: "Textstring"
                    )

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.