craft-linkfield
craft-linkfield copied to clipboard
Fix for issue with typed link field migration for craft 4
If you have any bugs with typed link field follow the next steps. Go to your vendor. Go to the next path: sebastianlenz -> linkfield -> src -> migrations. Find the migration .php file. Search for the following line: "$payload = Json::decode($row[$columnName]);". The last part: place this piece of code in a try catch like this:
try { $payload = Json::decode($row[$columnName]); } catch(\Exception $e) { var_dump($table); var_dump($columnName); var_dump($row); var_dump($e->getMessage()); continue; }
This should fix it.
Thanks this was driving me crazy.
What is the exact issue here, and why does this fix it? Also I notice now data is missing.
Pre-migration:
{"ariaLabel":null,"customQuery":null,"customText":"Gratisadviesgesprek","target":"","title":null,"type":"url","value":"#leadform"}
Post-migration:
{"ariaLabel":null,"customQuery":null,"customText":"Gratis adviesgesprek","target":"","title":null}
EDIT:
The data isn't missing, it is distributed differently in the lenz_linkfield
table.
Is this also a solution for https://github.com/sebastian-lenz/craft-linkfield/issues/250? 🙂
This solution works pretty well - ideally the maintainer will add the try/catch to the migration. But until then, here are some steps you can take to take to get this working across different environments.
- Create a
migrations
directory in your projects root folder (alongsideconfig
,templates
etc.) - Add the modified migration file to the newly created folder (gist here)
- Run
craft migrate/up
which should only detect this newly created migration. Said migration will update themigrations
table in the database so that when you run the rest of your Craft 4 update migrations, the broken typedlinkfield migration will not run. - Run the rest of your Craft 4 migrations (
craft migrate/all
) - $$$
- profit
I've encountered a migration error saying a duplicate entry has already been added. If anyone has a similar issue,. You can modify the plugin migration class and try out my solution: https://gist.github.com/pdaleramirez/681b1fffb082c7ceed8be02f5c7455e8
I modified the class, and it worked for me.
I was able to use pdaleramirez's solution with one slight modification to complete the migration