Skip to content

Commit dd11df1

Browse files
committed
Extra space removals
1 parent 6be3288 commit dd11df1

File tree

1 file changed

+94
-94
lines changed

1 file changed

+94
-94
lines changed

src/DB_Command.php

Lines changed: 94 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -575,100 +575,100 @@ public function tables( $args, $assoc_args ) {
575575
*
576576
* @when after_wp_load
577577
*/
578-
public function size( $args, $assoc_args ) {
579-
580-
global $wpdb;
581-
582-
$format = WP_CLI\Utils\get_flag_value( $assoc_args, 'format' );
583-
$size_format = WP_CLI\Utils\get_flag_value( $assoc_args, 'size_format' );
584-
$tables = WP_CLI\Utils\get_flag_value( $assoc_args, 'tables' );
585-
$tables = ! empty( $tables );
586-
587-
unset( $assoc_args['format'] );
588-
unset( $assoc_args['size_format'] );
589-
unset( $assoc_args['tables'] );
590-
591-
if ( empty( $args ) && empty( $assoc_args ) ) {
592-
$assoc_args['scope'] = 'all';
593-
}
594-
595-
// Build rows for the formatter.
596-
$rows = array();
597-
$fields = array( 'Name', 'Size' );
598-
599-
if ( $tables ) {
600-
601-
// Add all of the table sizes
602-
foreach( WP_CLI\Utils\wp_get_table_names( $args, $assoc_args ) as $table_name ) {
603-
604-
// Get the table size.
605-
$table_bytes = $wpdb->get_var( $wpdb->prepare(
606-
"SELECT SUM(data_length + index_length) FROM information_schema.TABLES where table_schema = '%s' and Table_Name = '%s' GROUP BY Table_Name LIMIT 1",
607-
DB_NAME,
608-
$table_name
609-
)
610-
);
611-
612-
// Add the table size to the list.
613-
$rows[] = array(
614-
'Name' => $table_name,
615-
'Size' => strtoupper( $table_bytes ) . " " . 'B',
616-
);
617-
}
618-
} else {
619-
620-
// Get the database size.
621-
$db_bytes = $wpdb->get_var( $wpdb->prepare(
622-
"SELECT SUM(data_length + index_length) FROM information_schema.TABLES where table_schema = '%s' GROUP BY table_schema;",
623-
DB_NAME
624-
)
625-
);
626-
627-
// Add the database size to the list.
628-
$rows[] = array(
629-
'Name' => DB_NAME,
630-
'Size' => strtoupper( $db_bytes ) . " " . 'B',
631-
);
632-
}
633-
634-
if ( ! empty( $size_format ) ) {
635-
foreach( $rows as $index => $row ) {
636-
// These added WP 4.4.0.
637-
if ( ! defined( 'KB_IN_BYTES' ) ) {
638-
define( 'KB_IN_BYTES', 1024 );
639-
}
640-
if ( ! defined( 'MB_IN_BYTES' ) ) {
641-
define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
642-
}
643-
644-
// Display the database size as a number.
645-
switch( $size_format ) {
646-
case 'mb':
647-
$divisor = MB_IN_BYTES;
648-
break;
649-
650-
case 'kb':
651-
$divisor = KB_IN_BYTES;
652-
break;
653-
654-
case 'b':
655-
default:
656-
$divisor = 1;
657-
break;
658-
}
659-
660-
$rows[ $index ]['Size'] = $row['Size'] / $divisor . " " . ucfirst( $size_format );
661-
}
662-
}
663-
664-
// Display the rows.
665-
$args = array(
666-
'format' => $format,
667-
);
668-
669-
$formatter = new \WP_CLI\Formatter( $args, $fields );
670-
$formatter->display_items( $rows );
671-
}
578+
public function size( $args, $assoc_args ) {
579+
580+
global $wpdb;
581+
582+
$format = WP_CLI\Utils\get_flag_value( $assoc_args, 'format' );
583+
$size_format = WP_CLI\Utils\get_flag_value( $assoc_args, 'size_format' );
584+
$tables = WP_CLI\Utils\get_flag_value( $assoc_args, 'tables' );
585+
$tables = ! empty( $tables );
586+
587+
unset( $assoc_args['format'] );
588+
unset( $assoc_args['size_format'] );
589+
unset( $assoc_args['tables'] );
590+
591+
if ( empty( $args ) && empty( $assoc_args ) ) {
592+
$assoc_args['scope'] = 'all';
593+
}
594+
595+
// Build rows for the formatter.
596+
$rows = array();
597+
$fields = array( 'Name', 'Size' );
598+
599+
if ( $tables ) {
600+
601+
// Add all of the table sizes
602+
foreach( WP_CLI\Utils\wp_get_table_names( $args, $assoc_args ) as $table_name ) {
603+
604+
// Get the table size.
605+
$table_bytes = $wpdb->get_var( $wpdb->prepare(
606+
"SELECT SUM(data_length + index_length) FROM information_schema.TABLES where table_schema = '%s' and Table_Name = '%s' GROUP BY Table_Name LIMIT 1",
607+
DB_NAME,
608+
$table_name
609+
)
610+
);
611+
612+
// Add the table size to the list.
613+
$rows[] = array(
614+
'Name' => $table_name,
615+
'Size' => strtoupper( $table_bytes ) . " " . 'B',
616+
);
617+
}
618+
} else {
619+
620+
// Get the database size.
621+
$db_bytes = $wpdb->get_var( $wpdb->prepare(
622+
"SELECT SUM(data_length + index_length) FROM information_schema.TABLES where table_schema = '%s' GROUP BY table_schema;",
623+
DB_NAME
624+
)
625+
);
626+
627+
// Add the database size to the list.
628+
$rows[] = array(
629+
'Name' => DB_NAME,
630+
'Size' => strtoupper( $db_bytes ) . " " . 'B',
631+
);
632+
}
633+
634+
if ( ! empty( $size_format ) ) {
635+
foreach( $rows as $index => $row ) {
636+
// These added WP 4.4.0.
637+
if ( ! defined( 'KB_IN_BYTES' ) ) {
638+
define( 'KB_IN_BYTES', 1024 );
639+
}
640+
if ( ! defined( 'MB_IN_BYTES' ) ) {
641+
define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
642+
}
643+
644+
// Display the database size as a number.
645+
switch( $size_format ) {
646+
case 'mb':
647+
$divisor = MB_IN_BYTES;
648+
break;
649+
650+
case 'kb':
651+
$divisor = KB_IN_BYTES;
652+
break;
653+
654+
case 'b':
655+
default:
656+
$divisor = 1;
657+
break;
658+
}
659+
660+
$rows[ $index ]['Size'] = $row['Size'] / $divisor . " " . ucfirst( $size_format );
661+
}
662+
}
663+
664+
// Display the rows.
665+
$args = array(
666+
'format' => $format,
667+
);
668+
669+
$formatter = new \WP_CLI\Formatter( $args, $fields );
670+
$formatter->display_items( $rows );
671+
}
672672

673673
/**
674674
* Displays the database table prefix.

0 commit comments

Comments
 (0)