craft-linkfield icon indicating copy to clipboard operation
craft-linkfield copied to clipboard

Fix for issue with typed link field migration for craft 4

Open ItsSeanvD opened this issue 1 year ago • 5 comments

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.

ItsSeanvD avatar Mar 31 '23 14:03 ItsSeanvD

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.

sander-lameco avatar Apr 24 '23 09:04 sander-lameco

Is this also a solution for https://github.com/sebastian-lenz/craft-linkfield/issues/250? 🙂

mandrasch avatar Jun 14 '23 07:06 mandrasch

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.

  1. Create a migrations directory in your projects root folder (alongside config, templates etc.)
  2. Add the modified migration file to the newly created folder (gist here)
  3. Run craft migrate/up which should only detect this newly created migration. Said migration will update the migrations table in the database so that when you run the rest of your Craft 4 update migrations, the broken typedlinkfield migration will not run.
  4. Run the rest of your Craft 4 migrations (craft migrate/all)
  5. $$$
  6. profit

andrewmenich avatar Jan 24 '24 17:01 andrewmenich

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.

pdaleramirez avatar Mar 11 '24 23:03 pdaleramirez

I was able to use pdaleramirez's solution with one slight modification to complete the migration

HAWilliams01 avatar Aug 14 '24 14:08 HAWilliams01