uSyncMigrations: Convert RTE Grid Editor to custom...
# help-with-umbraco
p
I'm trying to wrap my head around how to achieve this in my migration plan. I want to replace the
GridRTEBlockMigrator
from the package with my own. I've added a composer to try and replace it but that doesn't seem to do the trick:
Copy code
[ComposeAfter(typeof(BlockGridMigratorComposer))]
public class MigrationComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        // Replace the original RTE Block Migrator with our own
        builder.SyncBlockMigrators().Exclude<GridRTEBlockMigrator>().Add<MyGridRTEBlockMigrator>();
    }
}
Any ideas?
builder.SyncPropertyMigrators().Replace<GridMigrator, DTGEMigrator.DTGEMigrator>();
p
I saw that but that is for
SyncPropertyMigrators
this is not one of those it inherits from
ISyncBlockMigrator
m
another thought if it's a custom migrationprofile.. use prefered migrator?
p
I thought that too, but unfortunately that targets data editors by their alias so also wouldn't work
maybe this goes back to your original? how the ISyncBlockMigrators are added...
p
Yes, I saw them being added there but I need to replace the one in the package with my own and at the moment I think will end up with 2 migrators targeting the same grid editor hence the need to try and remove the other one before I add my own.
m
Copy code
builder            .WithCollectionBuilder<SyncBlockMigratorCollectionBuilder>()
            .Exclude()
seems to be a thing?
but maybe that's just what you were doing earlier.. sorry I couldnt be of help
(could you replace the BlockGridMigratorComposer entirely and do your own thing??)
p
To the first part of your response, yes, that is what I am doing above but the collection is empty when I hit my breakpoint there so nothing to exclude. I'm hoping I don't have to go as far as implementing my own Grid migrator to do this. I will keep trying - thanks for the help.
Looks like I could have been chasing a problem that wasn't there! I've created a new migrator that inherits from
GridToBlockGridMigrator
and on breaking into the contructor I can view the
SyncBlockMigratorCollection
passed into it and sure enough
MyGridRTEBlockMigrator
is present and the default one isn't which is the result I was hoping for. Thanks @Mike Chambers for your input.
m
Not sure I was of any help.. but I'll take it.. 🙂
p
Ah, I've also now found out why the collection was empty when I was inspecting it 🤦‍♂️ It's a lazy collection.
SyncBlockMigratorCollectionBuilder
inherits from
LazyCollectionBuilderBase<SyncBlockMigratorCollectionBuilder
It's always helpful to talk about it especially when you've had your head in it for too long as discussing it can often highlight something previously being overlooked.
In case it is of any use to others here is my migrator which essentially takes the original grid RTE content and adds it to an RTE property on another existing content type we are using in the new BlockGrid
Copy code
public class MyGridRTEBlockMigrator : GridBlockMigratorSimpleBase, ISyncBlockMigrator
{
    public MyGridRTEBlockMigrator (IShortStringHelper shortStringHelper)
        : base(shortStringHelper) { }

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

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

    public override string GetContentTypeAlias(LegacyGridValue.LegacyGridControl control) =>
        RichTextContentBlock.ModelTypeAlias;

    public override Dictionary<string, object> GetPropertyValues(LegacyGridValue.LegacyGridControl control, SyncMigrationContext context)
    {
        var rtePropertyTypeAlias = ModelHelpers.GetElementPropertyTypeAlias<RichTextContentBlock>(m => m.BodyText);
        
        return new Dictionary<string, object>
        {
            { rtePropertyTypeAlias, control.Value ?? string.Empty }
        };
    }
}
t
You need a custom Migrator for uSync Migrations, this way when you are migrating it is lookign for a
GridRTEBlockMigrator
and then you can turn it into your custom type
oh i didnt read, sorry, essentially 👆 above my comment is what i meant
p
I have it working as I need in the example I posted before your comment 👍
t
👍
36 Views