Skip to content

Commit efbd997

Browse files
authored
Merge branch 'main' into exclude_revisions
2 parents 6f2c866 + a959fd3 commit efbd997

4 files changed

Lines changed: 68 additions & 1 deletion

File tree

.github/workflows/code-quality.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
branches:
77
- main
88
- master
9+
schedule:
10+
- cron: '17 2 * * *' # Run every day on a seemly random time.
911

1012
jobs:
1113
code-quality:

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: 24 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
@@ -1143,6 +1161,12 @@ public function size( $args, $assoc_args ) {
11431161
$size_key = floor( log( (float) $row['Size'] ) / log( 1000 ) );
11441162
$sizes = [ 'B', 'KB', 'MB', 'GB', 'TB' ];
11451163

1164+
if ( is_infinite( $size_key ) ) {
1165+
$size_key = 0;
1166+
}
1167+
1168+
$size_key = (int) $size_key;
1169+
11461170
$size_format = isset( $sizes[ $size_key ] ) ? $sizes[ $size_key ] : $sizes[0];
11471171
}
11481172

0 commit comments

Comments
 (0)