File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,31 @@ Feature: Display database size
133133 When I run `wp db size --size_format=TB`
134134 Then STDOUT should be a number
135135
136+ Scenario : Display only database size in megabytes with specific precision for a WordPress install
137+ Given a WP install
138+
139+ When I run `wp db size --size_format=mb --decimals=0`
140+ Then STDOUT should not contain:
141+ """
142+ .
143+ """
144+
145+ And STDOUT should not contain:
146+ """
147+ MB
148+ """
149+
150+ When I run `wp db size --size_format=mb --decimals=1`
151+ Then STDOUT should contain:
152+ """
153+ .
154+ """
155+
156+ And STDOUT should not contain:
157+ """
158+ MB
159+ """
160+
136161 Scenario : Display database size in bytes with specific format for a WordPress install
137162 Given a WP install
138163
Original file line number Diff line number Diff line change @@ -817,6 +817,9 @@ public function tables( $args, $assoc_args ) {
817817 * [--network]
818818 * : List all the tables in a multisite install.
819819 *
820+ * [--decimals=<decimals>]
821+ * : Number of digits after decimal point. Defaults to 0.
822+ *
820823 * [--all-tables-with-prefix]
821824 * : List all tables that match the table prefix even if not registered on $wpdb. Overrides --network.
822825 *
@@ -999,12 +1002,13 @@ public function size( $args, $assoc_args ) {
9991002 }
10001003 $ size_format_display = preg_replace ( '/IB$/u ' , 'iB ' , strtoupper ( $ size_format ) );
10011004
1002- $ rows [ $ index ]['Size ' ] = ceil ( $ row ['Size ' ] / $ divisor ) . ' ' . $ size_format_display ;
1005+ $ decimals = Utils \get_flag_value ( $ assoc_args , 'decimals ' , 0 );
1006+ $ rows [ $ index ]['Size ' ] = round ( $ row ['Size ' ] / $ divisor , $ decimals ) . ' ' . $ size_format_display ;
10031007 }
10041008 }
10051009
10061010 if ( ! empty ( $ size_format ) && ! $ tables && ! $ format && ! $ human_readable && true !== $ all_tables && true !== $ all_tables_with_prefix ) {
1007- WP_CLI ::line ( filter_var ( $ rows [0 ]['Size ' ], FILTER_SANITIZE_NUMBER_INT ) );
1011+ WP_CLI ::line ( str_replace ( " { $ size_format_display }" , '' , $ rows [0 ]['Size ' ] ) );
10081012 } else {
10091013 // Display the rows.
10101014 $ args = [
You can’t perform that action at this time.
0 commit comments