sebastian-lenz / craft-linkfield

Link field for Craft 3
MIT License
122 stars 65 forks source link

Fix for issue with typed link field migration for craft 4 #261

Open ItsSeanvD opened 1 year ago

ItsSeanvD commented 1 year ago

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.

sander-lameco commented 1 year ago

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.

mandrasch commented 1 year ago

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

andrewmenich commented 8 months ago

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
pdaleramirez commented 7 months ago

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.

HAWilliams01 commented 2 months ago

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