File tree 2 files changed +31
-2
lines changed
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
133
133
When I run `wp db size --size_format=TB`
134
134
Then STDOUT should be a number
135
135
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
+
136
161
Scenario : Display database size in bytes with specific format for a WordPress install
137
162
Given a WP install
138
163
Original file line number Diff line number Diff line change @@ -817,6 +817,9 @@ public function tables( $args, $assoc_args ) {
817
817
* [--network]
818
818
* : List all the tables in a multisite install.
819
819
*
820
+ * [--decimals=<decimals>]
821
+ * : Number of digits after decimal point. Defaults to 0.
822
+ *
820
823
* [--all-tables-with-prefix]
821
824
* : List all tables that match the table prefix even if not registered on $wpdb. Overrides --network.
822
825
*
@@ -999,12 +1002,13 @@ public function size( $args, $assoc_args ) {
999
1002
}
1000
1003
$ size_format_display = preg_replace ( '/IB$/u ' , 'iB ' , strtoupper ( $ size_format ) );
1001
1004
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 ;
1003
1007
}
1004
1008
}
1005
1009
1006
1010
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 ' ] ) );
1008
1012
} else {
1009
1013
// Display the rows.
1010
1014
$ args = [
You can’t perform that action at this time.
0 commit comments