Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions features/db-import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ Feature: Import a WordPress database
Then the wp_cli_test.sql file should exist

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

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

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

@require-mysql-or-mariadb
Scenario: Import db that has emoji in post
Expand Down
6 changes: 3 additions & 3 deletions features/db-query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ Feature: Query the database with WordPress' MySQL config
Given a WP install

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

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

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

Scenario: SQL modes do not include any of the modes incompatible with WordPress
Given a WP install
Expand Down
27 changes: 9 additions & 18 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ public function cli( $_, $assoc_args ) {
}

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

$command = sprintf(
'/usr/bin/env %s%s --no-auto-rehash',
$this->get_mysql_command(),
'%s%s --no-auto-rehash',
Utils\get_mysql_binary_path(),
$this->get_defaults_flag_string( $assoc_args )
);
WP_CLI::debug( "Running shell command: {$command}", 'db' );
Expand Down Expand Up @@ -837,7 +837,7 @@ private function get_posts_table_charset( $assoc_args ) {
list( $stdout, $stderr, $exit_code ) = self::run(
sprintf(
'%s%s --no-auto-rehash --batch --skip-column-names',
$this->get_mysql_command(),
Utils\get_mysql_binary_path(),
$this->get_defaults_flag_string( $assoc_args )
),
[ 'execute' => $query ],
Expand Down Expand Up @@ -945,8 +945,8 @@ public function import( $args, $assoc_args ) {
}

$command = sprintf(
'/usr/bin/env %s%s --no-auto-rehash',
$this->get_mysql_command(),
'%s%s --no-auto-rehash',
Utils\get_mysql_binary_path(),
$this->get_defaults_flag_string( $assoc_args )
);
WP_CLI::debug( "Running shell command: {$command}", 'db' );
Expand Down Expand Up @@ -1939,7 +1939,7 @@ protected function run_query( $query, $assoc_args = [] ) {
self::run(
sprintf(
'%s%s --no-auto-rehash',
$this->get_mysql_command(),
Utils\get_mysql_binary_path(),
$this->get_defaults_flag_string( $assoc_args )
),
array_merge( [ 'execute' => $query ], $mysql_args )
Expand Down Expand Up @@ -2337,7 +2337,7 @@ protected function get_current_sql_modes( $assoc_args ) {
list( $stdout, $stderr, $exit_code ) = self::run(
sprintf(
'%s%s --no-auto-rehash --batch --skip-column-names',
$this->get_mysql_command(),
Utils\get_mysql_binary_path(),
$this->get_defaults_flag_string( $assoc_args )
),
array_merge( $args, [ 'execute' => 'SELECT @@SESSION.sql_mode' ] ),
Expand Down Expand Up @@ -2365,13 +2365,4 @@ protected function get_current_sql_modes( $assoc_args ) {

return $modes;
}

/**
* Returns the correct `mysql` command based on the detected database type.
*
* @return string The appropriate check command.
*/
private function get_mysql_command() {
return 'mariadb' === Utils\get_db_type() ? 'mariadb' : 'mysql';
}
}
Loading