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

feat: logic func which will throw exception if core WP tables are empty. #330

Open
wants to merge 11 commits into
base: trunk
Choose a base branch
from

Conversation

eddiesshop
Copy link
Collaborator

During a recent content diff, somehow the live wp_terms table (the table with new content that we're trying to merge into the current database) was empty. This caused the function recreate_categories to not function as expected. This is because when it tries to gather all the categories which must be brought over, it does a JOIN with this wp_terms table. But if that table is empty, the query will return no results, even though the wp_terms_taxonomy table has valid categories to be imported.

This function attempts to prevent that from happening in the first place, by checking if any core WP tables are empty before proceeding in earnest with the content diff.

During a recent content diff, somehow the live wp_terms table (the table with new content that we're trying to merge into the current database) was empty. This caused the function recreate_categories to not function as expected. This is because when it tries to gather all the categories which must be brought over, it does a JOIN with this wp_terms table. But if that table is empty, the query will return no results, even though the wp_terms_taxonomy table has valid categories to be imported.

This function attempts to prevent that from happening in the first place, by checking if any core WP tables are empty before proceeding in earnest with the content diff.
@eddiesshop eddiesshop requested a review from kariae August 17, 2023 18:48
@eddiesshop
Copy link
Collaborator Author

@kariae during my local testing, I saw that the wp_links table was empty. I think we typically don't consider this a crucial table that must be migrated correct?

If that's the case, then we should probably add one more change to this PR which ignores that table by default. Let me know what you think though.

…ditional handling of which Core WP tables can be safely ignored.
@eddiesshop
Copy link
Collaborator Author

I went ahead and added a new folder called Exceptions and a new class called CoreWPTableEmptyException. Then I went ahead and added some catches to where the validate_db_tables function are called and checked if any of the tables are within an ignore list. If they are then execution are allowed to proceed. If any table is not within the ignore list, then a WP_CLI::error is displayed and execution is halted.

@naxoc naxoc requested a review from a team August 31, 2023 14:32
Copy link
Collaborator

@iuravic iuravic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddiesshop as I shared during our Sprint, I think we should hardcode that some core tables are expected to possibly be empty not to break automatic execution of content refresh via Knife.

I've created a blank Atomic site and the following tables can be empty:
wp_commentmeta wp_comments wp_links wp_termmeta

Can you please add this?

Adding wp_termmeta, wp_comments, and wp_commentmeta to list of default ignored tables.
@eddiesshop
Copy link
Collaborator Author

@iuravic I added those tables you indicated to the ignore list. So if an exception is thrown, it is caught, and if those tables are the reason for the exception, then they are ignored, and the content diff is allowed to continue.

@eddiesshop
Copy link
Collaborator Author

Hey @iuravic! I ran PHPCS on the code that was modified. I've tested this fix with the content refresh that I was performing when this problem arose. Is there a particular site/setup you'd like me to test this with?

@iuravic iuravic assigned iuravic and eddiesshop and unassigned iuravic Jan 4, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants