-
Notifications
You must be signed in to change notification settings - Fork 45
skip-revisions, select columns, callbacks = The forever reroll (now with tests) #205
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
base: main
Are you sure you want to change the base?
Conversation
Added --revision / --no-revision Added --callback Reroll wp-cli#104, wp-cli#128, wp-cli#184 Fixes wp-cli#125, wp-cli#127, wp-cli#142
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Thanks for your PR! Would it be possible to split it up into 3 individual ones, one per new argument? That would make reviews much easier. There could also be one PS. Notice the lint failure |
I understand it's a significant diff on core code, but:
There is also at least one imperfection I'm aware of:
|
|
ping |
|
Heya, apologies for missing your previous reply. Thanks a lot for your effort, it's truly appreciated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds three major features to the WP-CLI search-replace command: the ability to filter rows using WHERE clauses (--where), skip revisions (--no-revisions), and execute custom callback functions during replacements (--callback). These long-requested features provide users with more precise control over search-replace operations.
- Added
--whereflag to filter rows by SQL conditions, supporting multiple table/column specifications - Added
--revisions/--no-revisionsflag to exclude draft/revision posts from replacements - Added
--callbackflag to execute user-defined PHP functions for custom replacement logic
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
| src/WP_CLI/SearchReplacer.php | Added callback parameter to constructor and run methods; implemented callback invocation logic with error handling for both regex and non-regex replacements |
| src/Search_Replace_Command.php | Added --where, --revisions, and --callback command-line options; implemented WHERE clause parsing, revision filtering, and callback validation; integrated custom clauses into SQL queries |
| features/search-replace-where.feature | Test scenarios for the new --where flag covering single/multiple tables, subqueries, dry-run mode, and column restrictions |
| features/search-replace-revisions.feature | Test scenarios for the new --revisions flag verifying published vs draft post filtering with and without regex |
| features/search-replace-callback.feature | Test scenarios for the new --callback flag including custom functions, regex callbacks, error handling, and parameter validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Replacement callback & row-based filtering (include/exclude posts revisions)
--whereexpression has been a long requested feature (for more than 8 years)Added
--whereflag to precisely select rows aimed for replacementAdded
--revision/--no-revisionAdded
--callbackReroll of Feature: Call user function with --callback flag #104 (Dec 2018), Replacement callback & row-based filtering #128 (Sept 2019) (Feature: Call user function with --callback flag Feature: Call user function with --callback flag #104 and skip-revisions, select columns, callbacks = The forever reroll #184 (June 2023)
Fix Filter by post types and post status in post table #125 (Introduce
--whereflag) and Limit search-replace in DB --wp_db_id="wp_posts:1234" (New command parameter) #142 (--wp_db_id)Resolves Pass current
$coland$primary_keysdown to the SearchReplacer #127 (Callback access to current primary key & column)