Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ItsSeanvD opened this issue Mar 31, 2023 · 5 comments
Open

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

ItsSeanvD opened this issue Mar 31, 2023 · 5 comments

Comments

@ItsSeanvD
Copy link

ItsSeanvD commented Mar 31, 2023

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
Copy link

sander-lameco commented Apr 24, 2023

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
Copy link

mandrasch commented Jun 14, 2023

Is this also a solution for #250? 🙂

@andrewmenich
Copy link

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants