22
33use WP_CLI \Formatter ;
44use WP_CLI \Utils ;
5+ use cli \table \Column ;
56
67/**
78 * Performs basic database operations using credentials stored in wp-config.php.
@@ -259,6 +260,12 @@ public function check( $_, $assoc_args ) {
259260 WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
260261
261262 $ 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+
262269 self ::run (
263270 Utils \esc_cmd ( $ command , DB_NAME ),
264271 $ assoc_args
@@ -307,6 +314,12 @@ public function optimize( $_, $assoc_args ) {
307314 WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
308315
309316 $ 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+
310323 self ::run (
311324 Utils \esc_cmd ( $ command , DB_NAME ),
312325 $ assoc_args
@@ -355,6 +368,12 @@ public function repair( $_, $assoc_args ) {
355368 WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
356369
357370 $ 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+
358377 self ::run (
359378 Utils \esc_cmd ( $ command , DB_NAME ),
360379 $ assoc_args
@@ -1142,6 +1161,12 @@ public function size( $args, $assoc_args ) {
11421161 $ size_key = floor ( log ( (float ) $ row ['Size ' ] ) / log ( 1000 ) );
11431162 $ sizes = [ 'B ' , 'KB ' , 'MB ' , 'GB ' , 'TB ' ];
11441163
1164+ if ( is_infinite ( $ size_key ) ) {
1165+ $ size_key = 0 ;
1166+ }
1167+
1168+ $ size_key = (int ) $ size_key ;
1169+
11451170 $ size_format = isset ( $ sizes [ $ size_key ] ) ? $ sizes [ $ size_key ] : $ sizes [0 ];
11461171 }
11471172
@@ -1199,7 +1224,6 @@ public function size( $args, $assoc_args ) {
11991224 if ( ! empty ( $ size_format ) && ! $ tables && ! $ format && ! $ human_readable && true !== $ all_tables && true !== $ all_tables_with_prefix ) {
12001225 WP_CLI ::line ( str_replace ( " {$ size_format_display }" , '' , $ rows [0 ]['Size ' ] ) );
12011226 } else {
1202-
12031227 // Sort the rows by user input
12041228 if ( $ orderby ) {
12051229 usort (
@@ -1220,7 +1244,8 @@ function ( $a, $b ) use ( $order, $orderby ) {
12201244
12211245 // Display the rows.
12221246 $ args = [
1223- 'format ' => $ format ,
1247+ 'format ' => $ format ,
1248+ 'alignments ' => [ 'Size ' => Column::ALIGN_RIGHT ],
12241249 ];
12251250
12261251 $ formatter = new Formatter ( $ args , $ fields );
@@ -1816,7 +1841,7 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
18161841 $ required ['default-character-set ' ] = constant ( 'DB_CHARSET ' );
18171842 }
18181843
1819- // Using 'dbuser' as option name to workaround clash with WP-CLI's global WP 'user' parameter, with 'dbpass' also available for tidyness .
1844+ // Using 'dbuser' as option name to workaround clash with WP-CLI's global WP 'user' parameter, with 'dbpass' also available for tidiness .
18201845 if ( isset ( $ assoc_args ['dbuser ' ] ) ) {
18211846 $ required ['user ' ] = $ assoc_args ['dbuser ' ];
18221847 unset( $ assoc_args ['dbuser ' ] );
0 commit comments