Skip to content

Commit 4cffe3d

Browse files
todeveniswissspidy
andauthored
Use Utils\get_mysql_binary_path() to get correct binary (#328)
Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent fb9ba97 commit 4cffe3d

3 files changed

Lines changed: 15 additions & 24 deletions

File tree

‎features/db-import.feature‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ Feature: Import a WordPress database
155155
Then the wp_cli_test.sql file should exist
156156

157157
When I try `wp db import --defaults --debug`
158-
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-auto-rehash#
158+
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-auto-rehash#
159159

160160
When I try `wp db import --debug`
161-
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#
161+
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-defaults --no-auto-rehash#
162162

163163
When I try `wp db import --no-defaults --debug`
164-
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#
164+
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-defaults --no-auto-rehash#
165165

166166
@require-mysql-or-mariadb
167167
Scenario: Import db that has emoji in post

‎features/db-query.feature‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ Feature: Query the database with WordPress' MySQL config
8383
Given a WP install
8484

8585
When I try `wp db query --defaults --debug`
86-
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-auto-rehash#
86+
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-auto-rehash#
8787

8888
When I try `wp db query --debug`
89-
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#
89+
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-defaults --no-auto-rehash#
9090

9191
When I try `wp db query --no-defaults --debug`
92-
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#
92+
Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-defaults --no-auto-rehash#
9393

9494
Scenario: SQL modes do not include any of the modes incompatible with WordPress
9595
Given a WP install

‎src/DB_Command.php‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ public function cli( $_, $assoc_args ) {
472472
}
473473

474474
$command = sprintf(
475-
'/usr/bin/env %s%s --no-auto-rehash',
476-
$this->get_mysql_command(),
475+
'%s%s --no-auto-rehash',
476+
Utils\get_mysql_binary_path(),
477477
$this->get_defaults_flag_string( $assoc_args )
478478
);
479479
WP_CLI::debug( "Running shell command: {$command}", 'db' );
@@ -593,8 +593,8 @@ public function query( $args, $assoc_args ) {
593593
}
594594

595595
$command = sprintf(
596-
'/usr/bin/env %s%s --no-auto-rehash',
597-
$this->get_mysql_command(),
596+
'%s%s --no-auto-rehash',
597+
Utils\get_mysql_binary_path(),
598598
$this->get_defaults_flag_string( $assoc_args )
599599
);
600600
WP_CLI::debug( "Running shell command: {$command}", 'db' );
@@ -837,7 +837,7 @@ private function get_posts_table_charset( $assoc_args ) {
837837
list( $stdout, $stderr, $exit_code ) = self::run(
838838
sprintf(
839839
'%s%s --no-auto-rehash --batch --skip-column-names',
840-
$this->get_mysql_command(),
840+
Utils\get_mysql_binary_path(),
841841
$this->get_defaults_flag_string( $assoc_args )
842842
),
843843
[ 'execute' => $query ],
@@ -945,8 +945,8 @@ public function import( $args, $assoc_args ) {
945945
}
946946

947947
$command = sprintf(
948-
'/usr/bin/env %s%s --no-auto-rehash',
949-
$this->get_mysql_command(),
948+
'%s%s --no-auto-rehash',
949+
Utils\get_mysql_binary_path(),
950950
$this->get_defaults_flag_string( $assoc_args )
951951
);
952952
WP_CLI::debug( "Running shell command: {$command}", 'db' );
@@ -1939,7 +1939,7 @@ protected function run_query( $query, $assoc_args = [] ) {
19391939
self::run(
19401940
sprintf(
19411941
'%s%s --no-auto-rehash',
1942-
$this->get_mysql_command(),
1942+
Utils\get_mysql_binary_path(),
19431943
$this->get_defaults_flag_string( $assoc_args )
19441944
),
19451945
array_merge( [ 'execute' => $query ], $mysql_args )
@@ -2360,7 +2360,7 @@ protected function get_current_sql_modes( $assoc_args ) {
23602360
list( $stdout, $stderr, $exit_code ) = self::run(
23612361
sprintf(
23622362
'%s%s --no-auto-rehash --batch --skip-column-names',
2363-
$this->get_mysql_command(),
2363+
Utils\get_mysql_binary_path(),
23642364
$this->get_defaults_flag_string( $assoc_args )
23652365
),
23662366
array_merge( $args, [ 'execute' => 'SELECT @@SESSION.sql_mode' ] ),
@@ -2388,13 +2388,4 @@ protected function get_current_sql_modes( $assoc_args ) {
23882388

23892389
return $modes;
23902390
}
2391-
2392-
/**
2393-
* Returns the correct `mysql` command based on the detected database type.
2394-
*
2395-
* @return string The appropriate check command.
2396-
*/
2397-
private function get_mysql_command() {
2398-
return 'mariadb' === Utils\get_db_type() ? 'mariadb' : 'mysql';
2399-
}
24002391
}

0 commit comments

Comments
 (0)