Fix batch pagination bug in migrations and add undo support#587
Merged
Conversation
Three batch migrations used LIMIT/OFFSET pagination while also removing processed items from the result set, causing ~50% of items to be silently skipped. Fix all three to always query from OFFSET 0: - migrate_post_tags_batch: deleted relationships naturally expose next batch - migrate_activitypub_attributed_to_batch: add ap_actor_id=0 sentinel on fetch failure so posts drop out of the NOT LIKE filter - convert_replies_to_comments_batch: mark processed posts with _friends_reply_checked meta and add NOT EXISTS subquery Also add backfill_mention_tags to the 4.0.0 auto-upgrade path (prerequisite for convert_replies_to_comments), store recovery data during tag migration, and add undo support for tag and reply-to-comment migrations with admin UI.
Contributor
Test this PR in WordPress PlaygroundYou can test this pull request directly in WordPress Playground: This will install and activate the plugin with the changes from this PR. |
f1f0bed to
65b7d7f
Compare
Make the Migrations page accessible via the settings tab bar instead of being a hidden page. Only shown to users with manage_options capability. Uses the shared settings-header template for consistent navigation.
65b7d7f to
1c4ba62
Compare
The migration had no status_option, so completion was inferred from the stored plugin version — which may still be < 4.0.0 during an upgrade. Add a status_option and set it in all return paths of the method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
migrate_post_tags_batch,migrate_activitypub_attributed_to_batch,convert_replies_to_comments_batch) that silently skipped ~50% of items when processing more than one batch. All three usedLIMIT X OFFSET Ywhile removing processed items from the result set, causing the offset to advance past unprocessed rows.backfill_mention_tagsto the 4.0.0 auto-upgrade path — it's a prerequisite forconvert_replies_to_commentsand is non-destructive/local-only.Details
Offset fix approach per migration
migrate_post_tags_batchOFFSET 0; deleted rows naturally expose next batchmigrate_activitypub_attributed_to_batchap_actor_idand drop fromNOT LIKEfilter, but failed posts stay and offset advances past themOFFSET 0; storeap_actor_id=0sentinel on failureconvert_replies_to_comments_batchOFFSET 0; mark all processed posts with_friends_reply_checkedmeta +NOT EXISTSsubqueryNew tests
test_migrate_post_tags_batch_boundary— 150 posts (exceeds batch_size=100), verifies all migratedtest_undo_post_tags_migration— full round-trip: migrate → verify recovery → undo → verify restoredtest_full_upgrade_path_from_3_6_0— exercisesupgrade_plugin()end-to-endTest plan
composer test— 247 tests, 1051 assertions passcomposer check-cs— cleanWordPress Playground
https://playground.wordpress.net/#{%22steps%22:[{%22step%22:%22installPlugin%22,%22pluginData%22:{%22resource%22:%22git:directory%22,%22url%22:%22https://github.com/akirk/friends%22,%22ref%22:%22migration-hardening%22,%22refType%22:%22branch%22},%22options%22:{%22activate%22:true}}]}