Skip to content

Commit 813977a

Browse files
authored
Merge pull request #57 from LC43/fix/report-improvement
Fix/report improvement
2 parents 9c0c05d + 18e7657 commit 813977a

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

features/search-replace.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ Feature: Do global search/replace
473473
"""
474474
And STDERR should be empty
475475

476+
@suppress_report__only_changes
476477
Scenario: Suppress report or only report changes
477478
Given a WP install
478479

@@ -570,6 +571,18 @@ Feature: Do global search/replace
570571
"""
571572
And STDERR should be empty
572573

574+
When I run `wp search-replace nobaz1 baz6 --report-changed-only`
575+
Then STDOUT should contain:
576+
"""
577+
Success: Made 0 replacements.
578+
"""
579+
And STDOUT should not contain:
580+
"""
581+
Table Column Replacements Type
582+
"""
583+
And STDERR should be empty
584+
585+
@no_table__no_primary_key
573586
Scenario: Deal with non-existent table and table with no primary keys
574587
Given a WP install
575588

@@ -609,6 +622,18 @@ Feature: Do global search/replace
609622
| no_key | | skipped | |
610623
And STDERR should be empty
611624

625+
And I run `wp search-replace foo bar no_key --report-changed-only`
626+
Then STDOUT should contain:
627+
"""
628+
Success: Made 0 replacements.
629+
"""
630+
And STDOUT should not contain:
631+
"""
632+
| Table | Column | Replacements | Type |
633+
| no_key | | skipped | |
634+
"""
635+
And STDERR should be empty
636+
612637
When I try `wp search-replace foo bar no_key --no-report`
613638
Then STDOUT should contain:
614639
"""

src/Search_Replace_Command.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,12 @@ public function __invoke( $args, $assoc_args ) {
302302
// since we'll be updating one row at a time,
303303
// we need a primary key to identify the row
304304
if ( empty( $primary_keys ) ) {
305-
if ( $this->report && ! $this->report_changed_only ) {
305+
306+
// wasn't updated, so skip to the next table
307+
if ( $this->report_changed_only ) {
308+
continue;
309+
}
310+
if ( $this->report ) {
306311
$report[] = array( $table, '', 'skipped', '' );
307312
} else {
308313
WP_CLI::warning( $all_columns ? "No primary keys for table '$table'." : "No such table '$table'." );
@@ -364,7 +369,7 @@ public function __invoke( $args, $assoc_args ) {
364369
return;
365370
}
366371

367-
if ( $this->report ) {
372+
if ( $this->report && ! empty( $report ) ) {
368373
$table = new \cli\Table();
369374
$table->setHeaders( array( 'Table', 'Column', 'Replacements', 'Type' ) );
370375
$table->setRows( $report );

0 commit comments

Comments
 (0)