dgrigg / craft-migration-assistant

Migration Manager for Craft CMS
Other
27 stars 10 forks source link

LinkField fields are no longer migrated correctly #37

Closed timbertens closed 3 years ago

timbertens commented 3 years ago

The import of LinkField migration is no longer working correctly, not sure since what version exactly but in the previous versions it definitely worked as expected. This is the json string that is created upon creating a migration

private $json = <<<'JSON' {"content":{"entries":[{"slug":"test","section":"nieuwsItems","sites":{"default":{"slug":"test","section":"nieuwsItems","enabled":true,"site":"default","enabledForSite":true,"postDate":{"date":"2021-05-05 09:45:00.000000","timezone_type":3,"timezone":"Europe/Brussels"},"expiryDate":null,"title":"Test","entryType":"nieuws","uid":"389d6d37-6c91-43da-8862-5d99a094d5d9","author":"admin","fields":{"nieuwsIcoon":[],"introTekst":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.","contentBuilder":{"new1":{"type":"tekst","enabled":true,"sortOrder":"1","fields":{"tekst":"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec ullamcorper nulla non metus auctor fringilla. Donec sed odio dui. Maecenas faucibus mollis interdum.</p>"}},"new2":{"type":"ctaButton","enabled":true,"sortOrder":"2","fields":{"button":{"ariaLabel":null,"customQuery":null,"customText":"","target":"","title":null,"type":"entry","value":[{"elementType":"craft\\elements\\Entry","slug":"contacteer","section":"contact","site":"default"}],"elementType":"typedlinkfield\\fields\\LinkField"}}}},"keywords":null,"metaDescription":null,"seoImage":[],"importId":null}},"kbcAgentFrans":{"slug":"test","section":"nieuwsItems","enabled":true,"site":"kbcAgentFrans","enabledForSite":true,"postDate":{"date":"2021-05-05 09:45:00.000000","timezone_type":3,"timezone":"Europe/Brussels"},"expiryDate":null,"title":"Test","entryType":"nieuws","uid":"389d6d37-6c91-43da-8862-5d99a094d5d9","author":"admin","fields":{"nieuwsIcoon":[],"introTekst":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.","contentBuilder":{"new1":{"type":"tekst","enabled":true,"sortOrder":"1","fields":{"tekst":"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec ullamcorper nulla non metus auctor fringilla. Donec sed odio dui. Maecenas faucibus mollis interdum.</p>"}},"new2":{"type":"ctaButton","enabled":true,"sortOrder":"2","fields":{"button":{"ariaLabel":null,"customQuery":null,"customText":"","target":"","title":null,"type":"entry","value":[{"elementType":"craft\\elements\\Entry","slug":"contacteer","section":"contact","site":"default"}],"elementType":"typedlinkfield\\fields\\LinkField"}}}},"keywords":null,"metaDescription":null,"seoImage":[],"importId":null}},"kbcAgentEngels":{"slug":"test","section":"nieuwsItems","enabled":true,"site":"kbcAgentEngels","enabledForSite":true,"postDate":{"date":"2021-05-05 09:45:00.000000","timezone_type":3,"timezone":"Europe/Brussels"},"expiryDate":null,"title":"Test","entryType":"nieuws","uid":"389d6d37-6c91-43da-8862-5d99a094d5d9","author":"admin","fields":{"nieuwsIcoon":[],"introTekst":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.","contentBuilder":{"new1":{"type":"tekst","enabled":true,"sortOrder":"1","fields":{"tekst":"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec ullamcorper nulla non metus auctor fringilla. Donec sed odio dui. Maecenas faucibus mollis interdum.</p>"}},"new2":{"type":"ctaButton","enabled":true,"sortOrder":"2","fields":{"button":{"ariaLabel":null,"customQuery":null,"customText":"","target":"","title":null,"type":"entry","value":[{"elementType":"craft\\elements\\Entry","slug":"contacteer","section":"contact","site":"default"}],"elementType":"typedlinkfield\\fields\\LinkField"}}}},"keywords":null,"metaDescription":null,"seoImage":[],"importId":null}}}}]}} JSON;

When you look at the specific part of the LinkField, all info looks correct and complete

"new2":{"type":"ctaButton","enabled":true,"sortOrder":"2","fields":{"button":{"ariaLabel":null,"customQuery":null,"customText":"","target":"","title":null,"type":"entry","value":[{"elementType":"craft\\elements\\Entry","slug":"contacteer","section":"contact","site":"default"}],"elementType":"typedlinkfield\\fields\\LinkField"}}}}

As you can see in this example, the LinkField is supposed to link to the section 'contact' However, upon running this migration, the LinkField is not populated with that entry, but left blank

Screenshot 2021-05-05 at 10 02 39

The LinkField is part of a matrix field called 'ContentBuilder'

dgrigg commented 3 years ago

Are you using the latest version of Craft and Migration Assistant? Also, please confirm that the entry with slug 'contacteer' in section 'contact' exists. Tested locally in Matrix blocks with Entry links and it is working correctly.

timbertens commented 3 years ago

yes, using

yes, see screenshot. Don't know if that would make difference, but it is a 'Single'

Screenshot 2021-05-05 at 17 10 33 Screenshot 2021-05-05 at 17 11 22
dgrigg commented 3 years ago

Tested with asset, single entry and section entry locally, all worked correctly. On the destination site the 'contact' entry exists and is enabled for the 'default' site?

timbertens commented 3 years ago

First of all, thanks for the search. Looking further into this, I can see a non-intended difference

source site

Screenshot 2021-05-06 at 10 23 14

destination site

Screenshot 2021-05-06 at 10 23 24

It appears that in https://github.com/craftcms/cms/issues/3368 the option was added to CraftCMS 3.2 to specify a slug on a single, this did not exist before and the slugs for singles were always the same in both source and destination sites.

Even stranger is that as far as I can see, this added functionality does not actually have an effect on the slug used, the one set in the section config still applies, but I guess this is what makes MigrationAssistant fail to insert the 'Contact' page in that LinkField as the slugs are used as key and they are different.

dgrigg commented 3 years ago

Ah, yes I do recall we had to make a slight tweak because of that change in Craft to make sure we got the entry slug on singles. Glad you sorted it out.