spicywebau / craft-neo

A Matrix-like field type for Craft CMS that uses existing fields
Other
403 stars 63 forks source link

Upgrade to 4.x breaking content #867

Closed chrisrowe closed 3 months ago

chrisrowe commented 3 months ago

Bug Description

After upgrading to 4.x some blocks are disappearing in the CP. I've diff'd the DB and the content is the same, migrations appear to have run so not sure whats happening. When trying to run resave/neo-blocks I get a bunch of errors

3833/4804] Resaving 7865 (7865) ... error: Skipped resaving 7865 (7865) due to an error obtaining its root element: Invalid owner ID: 7687

I suspect this is at play but unsure how to work around this, everything else is up to date and we don't have preparse or any other weird fields here.

Steps to reproduce

run craft update all

Expected behaviour

No response

Neo version

4.x

Craft CMS version

4.8.4

What is the affected Neo field's propagation method?

Save blocks to all sites the owner element is saved in

Does this issue involve templating, and if so, is eager-loading used?

This is not a templating issue

ttempleton commented 3 months ago

I haven't had this happen when upgrading Neo installs to 4.x - if possible, could you please send your composer files and database backup to plugins@spicyweb.com.au and we'll have a look at it.

chrisrowe commented 3 months ago

Cheers, followed up via email.

ttempleton commented 3 months ago

Thanks for sending those files. It turned out that at least one row in the neoblockstructures table had a siteId that was set to null, which is how we used to set site IDs on block structures on single-site Craft installs. I'm not really sure why that hadn't been re-set to the primary site ID, but I've added a console command for the next release (php craft neo/fields/fix-block-structure-site-ids) to make that change for any affected block structures. If you'd like to apply that fix before the next release, set your composer.json file's spicyweb/craft-neo requirement to 4.x-dev as 4.0.8 and run composer update.

Regarding the invalid owner ID errors - the owner IDs in the errors corresponded to rows in the elements table where the type was craft\models\EntryDraft, which was removed in Craft 4. Follow the solution given in https://github.com/craftcms/cms/issues/11816 to fix those rows.

chrisrowe commented 3 months ago

Thanks so much! I'll take it for a spin soon.