Skip to content

Commit c397ba4

Browse files
authored
Merge pull request #302 from wp-cli/copilot/fix-wp-db-optimize-repair
Add automatic --silent flag to mysqlcheck commands when --quiet is set
2 parents db5498e + 9780f67 commit c397ba4

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

features/db-check.feature

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ Feature: Check the database
1313
Success: Database checked.
1414
"""
1515

16+
Scenario: db check with --quiet flag should only show errors
17+
Given a WP install
18+
19+
When I run `wp db check --quiet`
20+
Then STDOUT should be empty
21+
22+
Scenario: db check can explicitly pass --silent to mysqlcheck
23+
Given a WP install
24+
25+
When I run `wp db check --silent`
26+
Then STDOUT should not contain:
27+
"""
28+
wp_cli_test.wp_users
29+
"""
30+
And STDOUT should contain:
31+
"""
32+
Success: Database checked.
33+
"""
34+
1635
Scenario: Run db check with MySQL defaults to check the database
1736
Given a WP install
1837

features/db.feature

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@ Feature: Perform database operations
185185
"""
186186
And STDOUT should not be empty
187187
188+
Scenario: db repair with --quiet flag should only show errors
189+
Given a WP install
190+
191+
When I run `wp db repair --quiet`
192+
Then STDOUT should not contain:
193+
"""
194+
error
195+
"""
196+
197+
Scenario: db repair can explicitly pass --silent to mysqlcheck
198+
Given a WP install
199+
200+
When I run `wp db repair --silent`
201+
Then STDOUT should not contain:
202+
"""
203+
error
204+
"""
205+
And STDOUT should contain:
206+
"""
207+
Success: Database repaired.
208+
"""
209+
188210
Scenario: DB Query
189211
Given a WP install
190212
@@ -334,7 +356,7 @@ Feature: Perform database operations
334356
"""
335357
Query succeeded. Rows affected: 1
336358
"""
337-
359+
338360
When I run `wp db query "SELECT * FROM wp_users WHERE ID = 1"`
339361
Then STDOUT should not contain:
340362
"""

src/DB_Command.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ public function check( $_, $assoc_args ) {
260260
WP_CLI::debug( "Running shell command: {$command}", 'db' );
261261

262262
$assoc_args['check'] = true;
263+
264+
// Pass --silent to mysqlcheck when in quiet mode.
265+
if ( WP_CLI::get_config( 'quiet' ) ) {
266+
$assoc_args['silent'] = true;
267+
}
268+
263269
self::run(
264270
Utils\esc_cmd( $command, DB_NAME ),
265271
$assoc_args
@@ -308,6 +314,12 @@ public function optimize( $_, $assoc_args ) {
308314
WP_CLI::debug( "Running shell command: {$command}", 'db' );
309315

310316
$assoc_args['optimize'] = true;
317+
318+
// Pass --silent to mysqlcheck when in quiet mode.
319+
if ( WP_CLI::get_config( 'quiet' ) ) {
320+
$assoc_args['silent'] = true;
321+
}
322+
311323
self::run(
312324
Utils\esc_cmd( $command, DB_NAME ),
313325
$assoc_args
@@ -356,6 +368,12 @@ public function repair( $_, $assoc_args ) {
356368
WP_CLI::debug( "Running shell command: {$command}", 'db' );
357369

358370
$assoc_args['repair'] = true;
371+
372+
// Pass --silent to mysqlcheck when in quiet mode.
373+
if ( WP_CLI::get_config( 'quiet' ) ) {
374+
$assoc_args['silent'] = true;
375+
}
376+
359377
self::run(
360378
Utils\esc_cmd( $command, DB_NAME ),
361379
$assoc_args

0 commit comments

Comments
 (0)