File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -506,9 +506,10 @@ public function query( $args, $assoc_args ) {
506506 if ( isset ( $ assoc_args ['execute ' ] ) ) {
507507 $ assoc_args ['execute ' ] = $ this ->get_sql_mode_query ( $ assoc_args ) . $ assoc_args ['execute ' ];
508508 }
509-
510- // Check if the query is an UPDATE or DELETE.
511- if ( isset ( $ assoc_args ['execute ' ] ) && preg_match ( '/\b(UPDATE|DELETE|INSERT)\b/i ' , $ assoc_args ['execute ' ] ) ) {
509+
510+ $ is_update_or_delete = isset ( $ assoc_args ['execute ' ] ) && preg_match ( '/\b(UPDATE|DELETE|INSERT)\b/i ' , $ assoc_args ['execute ' ] );
511+
512+ if ( $ is_update_or_delete ) {
512513 // Append `SELECT ROW_COUNT()` to the query.
513514 $ assoc_args ['execute ' ] .= '; SELECT ROW_COUNT(); ' ;
514515 }
@@ -521,7 +522,7 @@ public function query( $args, $assoc_args ) {
521522 }
522523
523524 // For UPDATE/DELETE queries, parse the output to get the number of rows affected.
524- if ( isset ( $ assoc_args [ ' execute ' ] ) && preg_match ( ' /\b(UPDATE|DELETE|INSERT)\b/i ' , $ assoc_args [ ' execute ' ] ) ) {
525+ if ( $ is_update_or_delete ) {
525526 $ output_lines = explode ( "\n" , trim ( $ stdout ) );
526527 $ affected_rows = (int ) trim ( end ( $ output_lines ) );
527528 WP_CLI ::success ( "Query succeeded. Rows affected: {$ affected_rows }" );
You can’t perform that action at this time.
0 commit comments