Skip to content

Commit 531b897

Browse files
committed
Rename and reorder the columns
1 parent 1c9b2e8 commit 531b897

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

features/db-search.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ Feature: Search through the database
10731073
When I run `wp db search example.com --format=csv`
10741074
Then STDOUT should contain:
10751075
"""
1076-
wp_options,option_value,option_id,14,mail.example.com
1077-
wp_options,option_value,option_id,15,login@example.com
1076+
wp_options,option_value,mail.example.com,option_id,14
1077+
wp_options,option_value,login@example.com,option_id,15
10781078
"""
10791079

10801080
When I try `wp db search example.com --format=ids`

src/DB_Command.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,12 +1484,16 @@ public function search( $args, $assoc_args ) {
14841484

14851485
if ( $format ) {
14861486
$search_results[] = [
1487-
'table' => $table,
1488-
'column' => $column,
1489-
'key' => $primary_key,
1490-
'value' => $result->$primary_key,
1487+
'table' => $table,
1488+
'column' => $column,
14911489
// Remove the colors for the format output.
1492-
'match' => str_replace( [ $colors['match'][0], $colors['match'][1] ], [ '', '' ], $col_val ),
1490+
'match' => str_replace(
1491+
[ $colors['match'][0], $colors['match'][1] ],
1492+
[ '','' ],
1493+
$col_val
1494+
),
1495+
'primary_key_name' => $primary_key,
1496+
'primary_key_value' => $result->$primary_key,
14931497
];
14941498
} else {
14951499
WP_CLI::log( $matches_only ? $col_val : ( $one_line ? "{$table_column_val}:{$pk_val}{$col_val}" : "{$pk_val}{$col_val}" ) );
@@ -1504,7 +1508,7 @@ public function search( $args, $assoc_args ) {
15041508
$formatter_args = [
15051509
'format' => $format,
15061510
];
1507-
$formatter_fields = [ 'table', 'column', 'key', 'value', 'match' ];
1511+
$formatter_fields = [ 'table', 'column', 'match', 'primary_key_name', 'primary_key_value' ];
15081512

15091513
if ( $fields ) {
15101514
$fields = explode( ',', $assoc_args['fields'] );
@@ -1515,7 +1519,7 @@ public function search( $args, $assoc_args ) {
15151519
if ( count( $tables ) > 1 ) {
15161520
WP_CLI::error( 'The "ids" format can only be used for a single table.' );
15171521
}
1518-
$search_results = array_column( $search_results, 'value' );
1522+
$search_results = array_column( $search_results, 'primary_key_value' );
15191523
}
15201524

15211525
$formatter = new Formatter( $formatter_args, $formatter_fields );

0 commit comments

Comments
 (0)