Skip to content

Commit cb5459b

Browse files
committed
Fix bug in site option patch STDIN detection
1 parent 1eca572 commit cb5459b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Site_Option_Command.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use WP_CLI\Entity\RecursiveDataStructureTraverser;
44
use WP_CLI\Utils;
5+
use WP_CLI\Entity\Utils as EntityUtils;
56

67
/**
78
* Adds, updates, deletes, and lists site options in a multisite installation.
@@ -174,7 +175,7 @@ public function list_( $args, $assoc_args ) {
174175
$fields = explode( ',', $assoc_args['fields'] );
175176
}
176177

177-
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'format' ) === 'total_bytes' ) {
178+
if ( Utils\get_flag_value( $assoc_args, 'format' ) === 'total_bytes' ) {
178179
$fields = array( 'size_bytes' );
179180
$size_query = ",SUM(LENGTH(meta_value)) AS `size_bytes`";
180181
}
@@ -190,7 +191,7 @@ public function list_( $args, $assoc_args ) {
190191
}
191192
$results = $wpdb->get_results( $query );
192193

193-
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'format' ) === 'total_bytes' ) {
194+
if ( Utils\get_flag_value( $assoc_args, 'format' ) === 'total_bytes' ) {
194195
WP_CLI::line( $results[0]->size_bytes );
195196
} else {
196197
$formatter = new \WP_CLI\Formatter(
@@ -362,12 +363,13 @@ public function patch( $args, $assoc_args ) {
362363

363364
if ( 'delete' == $action ) {
364365
$patch_value = null;
365-
} elseif ( \WP_CLI\Entity\Utils::has_stdin() ) {
366-
$stdin_value = WP_CLI::get_value_from_arg_or_stdin( $args, -1 );
367-
$patch_value = WP_CLI::read_value( trim( $stdin_value ), $assoc_args );
368366
} else {
369-
// Take the patch value as the last positional argument. Mutates $key_path to be 1 element shorter!
370-
$patch_value = WP_CLI::read_value( array_pop( $key_path ), $assoc_args );
367+
$stdin_value = EntityUtils::has_stdin()
368+
? trim( WP_CLI::get_value_from_arg_or_stdin( $args, -1 ) )
369+
: null;
370+
$patch_value = ! empty( $stdin_value )
371+
? WP_CLI::read_value( $stdin_value, $assoc_args )
372+
: WP_CLI::read_value( array_pop( $key_path ), $assoc_args );
371373
}
372374

373375
/* Need to make a copy of $current_value here as it is modified by reference */

0 commit comments

Comments
 (0)