Skip to content

Commit 9369699

Browse files
swissspidyclaude
andcommitted
Keep a --where condition of '0' instead of dropping it
array_filter() removed it, so the run was unrestricted in both the SQL and the --precise paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
1 parent 5f3581a commit 9369699

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎features/search-replace-where.feature‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,30 @@ Feature: Test search-replace --where option
444444
Post foo
445445
"""
446446

447+
@require-mysql
448+
Scenario: Where condition of 0 matches no rows
449+
Given a WP install
450+
And I run `wp post create --post_title='Post foo' --porcelain`
451+
And save STDOUT as {POST_ID}
452+
453+
When I run `wp search-replace foo bar --where='wp_posts:post_title:0'`
454+
Then STDOUT should contain:
455+
"""
456+
Success: Made 0 replacements.
457+
"""
458+
459+
When I run `wp search-replace foo bar --where='wp_posts:post_title:0' --precise`
460+
Then STDOUT should contain:
461+
"""
462+
Success: Made 0 replacements.
463+
"""
464+
465+
When I run `wp post get {POST_ID} --field=title`
466+
Then STDOUT should be:
467+
"""
468+
Post foo
469+
"""
470+
447471
Scenario: Where clause cannot be combined with an export
448472
Given a WP install
449473

‎src/Search_Replace_Command.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,11 @@ private function get_clauses( $table, $column = null ) {
16991699
$this->where[ $table ][ $column ] ?? [],
17001700
$this->where[ $table ]['*'] ?? [],
17011701
[ (string) $this->get_revision_clause( $table ) ]
1702-
)
1702+
),
1703+
static function ( $clause ) {
1704+
// Keep a condition like '0': only drop the absent or empty ones.
1705+
return '' !== trim( $clause );
1706+
}
17031707
);
17041708

17051709
// Parenthesize each clause, so that an OR in one cannot escape the AND with the others.

0 commit comments

Comments
 (0)