Jump to content

Repeater fields in block migrations and duplicate template generation


FireWire
 Share

Recommended Posts

Found something that may be of help to others. I have a RPB block that has a basic repeater field and uses a block migration. Rather than writing the migrations by hand, I've been copying RockMigrations code from fields to help make short work of writing migrations in block files. Example:

345316377_Screenshotfrom2024-08-1209-39-08.thumb.png.7a1d93cd34cdf7ea5e89b48ae8a4187e.png

Running migrations ended up causing a system template to be created every time modules were refreshed:

1988918432_Screenshotfrom2024-08-1209-42-30.png.537dc7c15e86c10e1d77061710472320.png

I found the culprit in the block migration:

<?php 

$rm->migrate([
  'fields' => [
    'listItems' => [
        'label' => 'List Items',
        'type' => 'FieldtypeRepeater',
        'fields' => [
            0 => 'text',
        ],
        'template_id' => 0, // Potentially causes duplicate template creation
        'parent_id' => 0,   // Potentially causes duplicate template creation
        // ...
    ],
  ],
  // ...
]);

Removing those two migration properties for that field resolved the issue.

I'm not sure if this has any effect on other block migration field types since I haven't created too many in this project yet, but something to keep in mind when using the migration code output from an edit field page.

@bernhard Is this something that an update in blocks where migration arrays could be "sanitized" to remove any properties that would conflict with how RPB needs fields to be created?

Thanks for your work as always @bernhard!

Link to comment
Share on other sites

2 minutes ago, FireWire said:

@bernhard Is this something that an update in blocks where migration arrays could be "sanitized" to remove any properties that would conflict with how RPB needs fields to be created?

That would be nice to have for sure. If anybody wants to add it I'm happy to merge ? 

  • Like 1
Link to comment
Share on other sites

1 minute ago, bernhard said:

I'm happy to merge

Can I get access to the repo? Can't guarantee I can tackle this right now, but when I can I'd be happy to work on it!

  • Thanks 1
Link to comment
Share on other sites

@bernhard I've only experienced this when creating migrations inside block PHP files for RPB. I haven't looked but would there be something inside RockPageBuilder that filters block migrations before they're handled by RockMigrations?

Link to comment
Share on other sites

I don't think that it is related to RPB, but not sure. I can't give you access to RPB on github, but that's not necessary anyhow. If you find something just send me the files and I'll merge them manually. I have to admit though that it's not a priority for me to keep these migrations code sections 100% accurate. It's there to get help when writing migrations but it's definitely nothing that should be copied 1:1

There are many inconsistencies in PW api / migrations API like for example RM using field and template names all over and PW using ids, which is not readable/maintainable in migrations. So I'm not sure how much work the problem you have found justifies ? 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...