Update/delete taxanomy fix upstream #2349
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
Deleting term needs to do 2 actions:
However, if the hook is invoked on
delete_term
the term is already deleted in WP by then. The operations needed to get the list of child terms then fails.This change switches the two actions into 2 hooks. On
pre_delete_term
which happens both before the term is deleted but also before the child terms were updated in WP already, we will enqueue child terms to sync queue. Then ondelete_term
(same as before) we will remove the term from ES.The sync queue is then processed on shutdown, that is after the children terms were already updated with the correct parent.
Another change in this PR is adding the permission check bypass for CLI and cron on term resyncing.
Alternate Designs
Benefits
Possible Drawbacks
Verification Process
wp elasticpress activate-feature terms
wp elasticpress index --setup
Create some hierarchy of categories
Delete middle one `wp term delete category
No errors
Term is deleted
Check that index is correctly showing the children of deleted term pointing to the parent of deleted term as their parent now
Checklist:
Applicable Issues
Changelog Entry
Fixes: Term deletion propagation to ElasticSearch