@@ -172,8 +172,9 @@ public function __invoke( $args, $assoc_args ) {
172
172
$ this ->recurse_objects = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'recurse-objects ' , true );
173
173
$ this ->verbose = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'verbose ' );
174
174
$ this ->format = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'format ' );
175
+ $ this ->regex = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex ' , false );
175
176
176
- if ( ( $ this ->regex = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , ' regex ' , false ) ) ) {
177
+ if ( null !== $ this ->regex ) {
177
178
$ default_regex_delimiter = false ;
178
179
$ this ->regex_flags = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex-flags ' , false );
179
180
$ this ->regex_delimiter = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex-delimiter ' , '' );
@@ -183,7 +184,8 @@ public function __invoke( $args, $assoc_args ) {
183
184
}
184
185
}
185
186
186
- if ( null !== ( $ regex_limit = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex-limit ' ) ) ) {
187
+ $ regex_limit = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex-limit ' );
188
+ if ( null !== $ regex_limit ) {
187
189
if ( ! preg_match ( '/^(?:[0-9]+|-1)$/ ' , $ regex_limit ) || 0 === (int ) $ regex_limit ) {
188
190
WP_CLI ::error ( '`--regex-limit` expects a non-zero positive integer or -1. ' );
189
191
}
@@ -218,7 +220,8 @@ public function __invoke( $args, $assoc_args ) {
218
220
exit ;
219
221
}
220
222
221
- if ( null !== ( $ export = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'export ' ) ) ) {
223
+ $ export = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'export ' );
224
+ if ( null !== $ export ) {
222
225
if ( $ this ->dry_run ) {
223
226
WP_CLI ::error ( 'You cannot supply --dry-run and --export at the same time. ' );
224
227
}
@@ -239,7 +242,8 @@ public function __invoke( $args, $assoc_args ) {
239
242
$ php_only = true ;
240
243
}
241
244
242
- if ( null !== ( $ log = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'log ' ) ) ) {
245
+ $ log = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'log ' );
246
+ if ( null !== $ log ) {
243
247
if ( true === $ log || '- ' === $ log ) {
244
248
$ this ->log_handle = STDOUT ;
245
249
} else {
@@ -250,13 +254,18 @@ public function __invoke( $args, $assoc_args ) {
250
254
}
251
255
}
252
256
if ( $ this ->log_handle ) {
253
- if ( null !== ( $ before_context = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'before_context ' ) ) && preg_match ( '/^[0-9]+$/ ' , $ before_context ) ) {
257
+ $ before_context = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'before_context ' );
258
+ if ( null !== $ before_context && preg_match ( '/^[0-9]+$/ ' , $ before_context ) ) {
254
259
$ this ->log_before_context = (int ) $ before_context ;
255
260
}
256
- if ( null !== ( $ after_context = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'after_context ' ) ) && preg_match ( '/^[0-9]+$/ ' , $ after_context ) ) {
261
+
262
+ $ after_context = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'after_context ' );
263
+ if ( null !== $ after_context && preg_match ( '/^[0-9]+$/ ' , $ after_context ) ) {
257
264
$ this ->log_after_context = (int ) $ after_context ;
258
265
}
259
- if ( false !== ( $ log_prefixes = getenv ( 'WP_CLI_SEARCH_REPLACE_LOG_PREFIXES ' ) ) && preg_match ( '/^([^,]*),([^,]*)$/ ' , $ log_prefixes , $ matches ) ) {
266
+
267
+ $ log_prefixes = getenv ( 'WP_CLI_SEARCH_REPLACE_LOG_PREFIXES ' );
268
+ if ( false !== $ log_prefixes && preg_match ( '/^([^,]*),([^,]*)$/ ' , $ log_prefixes , $ matches ) ) {
260
269
$ this ->log_prefixes = array ( $ matches [1 ], $ matches [2 ] );
261
270
}
262
271
@@ -273,7 +282,9 @@ public function __invoke( $args, $assoc_args ) {
273
282
'log_new ' => '' ,
274
283
);
275
284
}
276
- if ( false !== ( $ log_colors = getenv ( 'WP_CLI_SEARCH_REPLACE_LOG_COLORS ' ) ) && preg_match ( '/^([^,]*),([^,]*),([^,]*)$/ ' , $ log_colors , $ matches ) ) {
285
+
286
+ $ log_colors = getenv ( 'WP_CLI_SEARCH_REPLACE_LOG_COLORS ' );
287
+ if ( false !== $ log_colors && preg_match ( '/^([^,]*),([^,]*),([^,]*)$/ ' , $ log_colors , $ matches ) ) {
277
288
$ default_log_colors = array (
278
289
'log_table_column_id ' => $ matches [1 ],
279
290
'log_old ' => $ matches [2 ],
@@ -629,7 +640,8 @@ private static function get_columns( $table ) {
629
640
$ text_columns = array ();
630
641
$ all_columns = array ();
631
642
$ suppress_errors = $ wpdb ->suppress_errors ();
632
- if ( ( $ results = $ wpdb ->get_results ( "DESCRIBE $ table_sql " ) ) ) {
643
+ $ results = $ wpdb ->get_results ( "DESCRIBE $ table_sql " );
644
+ if ( ! empty ( $ results ) ) {
633
645
foreach ( $ results as $ col ) {
634
646
if ( 'PRI ' === $ col ->Key ) {
635
647
$ primary_keys [] = $ col ->Field ;
@@ -732,7 +744,8 @@ private function get_colors( $assoc_args, $colors ) {
732
744
$ color_codes_regex = '/^(?:%[ ' . $ color_codes . '])*$/ ' ;
733
745
734
746
foreach ( array_keys ( $ colors ) as $ color_col ) {
735
- if ( null !== ( $ col_color_flag = \WP_CLI \Utils \get_flag_value ( $ assoc_args , $ color_col . '_color ' ) ) ) {
747
+ $ col_color_flag = \WP_CLI \Utils \get_flag_value ( $ assoc_args , $ color_col . '_color ' );
748
+ if ( null !== $ col_color_flag ) {
736
749
if ( ! preg_match ( $ color_codes_regex , $ col_color_flag , $ matches ) ) {
737
750
WP_CLI ::warning ( "Unrecognized percent color code ' $ col_color_flag' for ' {$ color_col }_color'. " );
738
751
} else {
@@ -763,7 +776,9 @@ private function log_sql_diff( $col, $primary_keys, $table, $old, $new ) {
763
776
} else {
764
777
$ primary_keys_sql = '' ;
765
778
}
766
- if ( ! ( $ results = $ wpdb ->get_results ( $ wpdb ->prepare ( "SELECT {$ primary_keys_sql }` $ col` FROM ` $ table` WHERE ` $ col` LIKE BINARY %s " , '% ' . self ::esc_like ( $ old ) . '% ' ), ARRAY_N ) ) ) {
779
+
780
+ $ results = $ wpdb ->get_results ( $ wpdb ->prepare ( "SELECT {$ primary_keys_sql }` $ col` FROM ` $ table` WHERE ` $ col` LIKE BINARY %s " , '% ' . self ::esc_like ( $ old ) . '% ' ), ARRAY_N );
781
+ if ( empty ( $ results ) ) {
767
782
return 0 ;
768
783
}
769
784
0 commit comments