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

Database migration didn't work properly #28155

Closed
carlomanf opened this issue Jan 13, 2021 · 10 comments · Fixed by #28300
Closed

Database migration didn't work properly #28155

carlomanf opened this issue Jan 13, 2021 · 10 comments · Fixed by #28300
Assignees
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Status] In Progress Tracking issues with work in progress
Milestone

Comments

@carlomanf
Copy link

Describe the bug
The database migration introduced in #27910 did not erase all of the data it was designed to erase.

  • Auto-drafts are correctly erased but their term relationships didn't get erased. In other words, you end up with "orphan" entries in the term relationships table.

  • The _wp_file_based term didn't get erased.

  • The gutenberg_last_synchronize_theme_template_checks option didn't get erased.

  • The gutenberg_last_synchronize_theme_template-part_checks option didn't get erased.

Expected behavior
Either the migration needs to be complete, or don't bother including a migration at all.

Editor version (please complete the following information):

  • WordPress version: 5.6
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? plugin
  • If the Gutenberg plugin is installed, which version is it? 13 Jan 2021 commit on master branch
@talldan talldan added the Needs Technical Feedback Needs testing from a developer perspective. label Jan 13, 2021
@talldan
Copy link
Contributor

talldan commented Jan 13, 2021

Pinging @youknowriad as the author of #27910 for feedback.

@youknowriad
Copy link
Contributor

I assumed the "delete_term" does remove the relationships but it seems that it doesn't. and I forgot about the options.

@carlomanf
Copy link
Author

I assumed the "delete_term" does remove the relationships but it seems that it doesn't.

I think it is meant to. I can't work out why it doesn't here, but I'd guess it's the auto-draft status causing trouble again.

@youknowriad
Copy link
Contributor

Do you have an idea on how we could overcome that?

@carlomanf
Copy link
Author

If you were desperate you could always write out the queries through $wpdb, but identifying the cause of the migration failure might uncover a better solution.

@ockham
Copy link
Contributor

ockham commented Jan 13, 2021

wp_delete_object_term_relationships looks promising 🤔 I'll see if that's supposed to be automatically run by wp_delete_term (and under what circumstances), or if it always needs to be manually run.

@ockham
Copy link
Contributor

ockham commented Jan 13, 2021

Hmm, while wp_delete_term doesn't seem to invoke wp_delete_object_term_relationships, it does look like it should remove term relationships no less: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/taxonomy.php?rev=49947#L1935

@carlomanf
Copy link
Author

Hmm, while wp_delete_term doesn't seem to invoke wp_delete_object_term_relationships, it does look like it should remove term relationships no less: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/taxonomy.php?rev=49947#L1935

It's more complicated than that. The call to wp_delete_term actually had no effect at all, so it didn't even delete the term, let alone the relationships. wp_delete_post was also meant to delete the relationships for the given post, and didn't.

It might be wise to write some unit tests for this, if it's possible to do so.

@ockham
Copy link
Contributor

ockham commented Jan 18, 2021

@ockham
Copy link
Contributor

ockham commented Jan 18, 2021

The other problem seems to be that get_term_by doesn't seem to find any wp_theme terms. The reason for this might be that we're attempting to do so from the _gutenberg_migrate_database method, which is hooked into plugins_loaded. However, the wp_theme taxonomy is registered in gutenberg_register_wp_theme_taxonomy, which is hooked into init. And init comes after plugins_loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants