Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions features/db-size.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ Feature: Display database size

When I run `wp db size --size_format=mb`
Then STDOUT should be a number

Scenario: Display only database size in gigabytes for a WordPress install
Given a WP install

When I run `wp db size --size_format=gb`
Then STDOUT should be a number

Scenario: Display only database size in terabytes for a WordPress install
Given a WP install

When I run `wp db size --size_format=tb`
Then STDOUT should be a number
16 changes: 16 additions & 0 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ public function tables( $args, $assoc_args ) {
* - b (bytes)
* - kb (kilobytes)
* - mb (megabytes)
* - gb (gigabytes)
* - tb (terabytes)
* ---
*
* [--tables]
Expand Down Expand Up @@ -722,9 +724,23 @@ public function size( $args, $assoc_args ) {
if ( ! defined( 'MB_IN_BYTES' ) ) {
define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
}
if ( ! defined( 'GB_IN_BYTES' ) ) {
define( 'GB_IN_BYTES', 1024 * MB_IN_BYTES );
}
if ( ! defined( 'TB_IN_BYTES' ) ) {
define( 'TB_IN_BYTES', 1024 * GB_IN_BYTES );
}

// Display the database size as a number.
switch( $size_format ) {
case 'tb':
$divisor = TB_IN_BYTES;
break;

case 'gb':
$divisor = GB_IN_BYTES;
break;

case 'mb':
$divisor = MB_IN_BYTES;
break;
Expand Down