Migration to blocks - Clarification/issues moving from 3.6 to 3.8 (or latest)?

I wrote previously about updating a site from 3.4 to latest and know I had to, in the interim, use 3.6 for migration.

However, I’m unsure what is meant to happen or needs to be done? I’ve updated all my blueprints accordingly and everything works and appears correctly.

Once this is done and I further update to 3.8.x, all the blocks fields are broken and appear like so:

Am I meant to do something to adjust/migrate the actual contents or what am I missing? Reverting back to 3.6.x fixes everything.

In case it is helpful, the actual content is like so:

Content:

[
    {
        "attrs": {
            "guid": "/pages/example+image.jpg",
            "id": "example/example+image.jpg",
            "filename": "example=image.jpg",
            "ratio": 0.7128309572301426,
            "caption": "Example Caption"
        },
        "content": "",
        "id": "_71r70b1z7",
        "type": "image"
    },
    {
        "attrs": [],
        "content": "<strong>Example Text</strong>",
        "id": "_l853qpckw",
        "type": "paragraph"
    },
    ...

The values in the content file looks somehow wrong, where are those attrs coming from? And the content shouldn’t be simple strings, have a look at a starterkit what the structure should look like for blocks (note pages) or layout (see about page). You might want to add pretty: true to the field definitions and save some changes to get nicer output in the content files.

These were previously built with the editor plugin like so:

  content:
    label: Content
    type: editor

Thank you for the tip regarding pretty!

Hi again @texnixe - I added the pretty: true declaration to the blueprint and it seems to have updated everything, but primarily what I realized is that unless the page is modified then saved, it is stuck in the old format posted above.

So I suppose my question is: does all legacy content need to be modified then re-saved to be migrated properly?

The new content appears like so:

Content:

[
    {
        "content": {
            "location": "kirby",
            "image": [
                "example-.jpg"
            ],
            "src": "",
            "alt": "",
            "caption": "Example Caption",
            "link": "",
            "ratio": "",
            "crop": "false"
        },
        "id": "8e17b37c-e354-498b-ae46-ff5281f81692",
        "isHidden": false,
        "type": "image"
    },
    {
        "content": {
            "text": "<p><strong>Example Text</strong></p>"
        },
        "id": "5b44dfe2-9901-435b-a113-23b4ca615da3",
        "isHidden": false,
        "type": "text"
    },

That looks good.

Yes, I think you need to update the pages, but it should be possible to do this programmatically. But since the migration script has been removed, you need to do this with 3.6, or use the same code as in 3.6 or wait until the feature comes back.

I see, I am on 3.6.6.2 but don’t see a migration script, would you mind pointing me in the right direction? Is it something built in to core or do I need to use this custom script from here? Bulk Builder field to Kirby Block 3.7 conversion - #8 by mactux

Hm, I tried using the script I linked, but ran into issues… in the end I just wrote something incredibly simple that just updates each page with a random field which seemed to work fine although it feels a bit janky:

<?php
require 'kirby/bootstrap.php';
$kirby = new Kirby();
$pages = site()->index(true);
$kirby->impersonate('kirby');

foreach ($pages as $page) {
  $page->update(['migration_test' => true]);
}
echo "Done";

After this, all the content was updated as hoped. I’ve now updated to 3.8.x and it is working.

1 Like

Great, didn’t have time to look for the migration code. The good news is that we are planning to bring back that feature in one of the next releases.

Great that’s good to hear I think a lot of the confusion lies in not knowing how the process is supposed to work. Hopefully that can be clarified in the reintroduction as well.

Thanks as always for your help @texnixe