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
@@ -1161,6 +1180,12 @@ public function size( $args, $assoc_args ) {
11611180 $ size_key = floor ( log ( (float ) $ row ['Size ' ] ) / log ( 1000 ) );
11621181 $ sizes = [ 'B ' , 'KB ' , 'MB ' , 'GB ' , 'TB ' ];
11631182
1183+ if ( is_infinite ( $ size_key ) ) {
1184+ $ size_key = 0 ;
1185+ }
1186+
1187+ $ size_key = (int ) $ size_key ;
1188+
11641189 $ size_format = isset ( $ sizes [ $ size_key ] ) ? $ sizes [ $ size_key ] : $ sizes [0 ];
11651190 }
11661191
@@ -1218,7 +1243,6 @@ public function size( $args, $assoc_args ) {
12181243 if ( ! empty ( $ size_format ) && ! $ tables && ! $ format && ! $ human_readable && true !== $ all_tables && true !== $ all_tables_with_prefix ) {
12191244 WP_CLI ::line ( str_replace ( " {$ size_format_display }" , '' , $ rows [0 ]['Size ' ] ) );
12201245 } else {
1221-
12221246 // Sort the rows by user input
12231247 if ( $ orderby ) {
12241248 usort (
@@ -1239,7 +1263,8 @@ function ( $a, $b ) use ( $order, $orderby ) {
12391263
12401264 // Display the rows.
12411265 $ args = [
1242- 'format ' => $ format ,
1266+ 'format ' => $ format ,
1267+ 'alignments ' => [ 'Size ' => Column::ALIGN_RIGHT ],
12431268 ];
12441269
12451270 $ formatter = new Formatter ( $ args , $ fields );
@@ -1835,7 +1860,7 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
18351860 $ required ['default-character-set ' ] = constant ( 'DB_CHARSET ' );
18361861 }
18371862
1838- // Using 'dbuser' as option name to workaround clash with WP-CLI's global WP 'user' parameter, with 'dbpass' also available for tidyness .
1863+ // Using 'dbuser' as option name to workaround clash with WP-CLI's global WP 'user' parameter, with 'dbpass' also available for tidiness .
18391864 if ( isset ( $ assoc_args ['dbuser ' ] ) ) {
18401865 $ required ['user ' ] = $ assoc_args ['dbuser ' ];
18411866 unset( $ assoc_args ['dbuser ' ] );
0 commit comments