Skip to content

Commit e9c4e8a

Browse files
authored
Merge pull request #275 from mrsdizzie/fix-mariadb-warnings
Don't hardcode MySQL command names
2 parents df19fde + d44bf0d commit e9c4e8a

File tree

3 files changed

+44
-30
lines changed

3 files changed

+44
-30
lines changed

features/db-check.feature

+4-12
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,11 @@ Feature: Check the database
128128
Given a WP install
129129

130130
When I try `wp db check --defaults --debug`
131-
Then STDERR should contain:
132-
"""
133-
Debug (db): Running shell command: /usr/bin/env mysqlcheck %s
134-
"""
131+
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) %s#
135132

136133
When I try `wp db check --debug`
137-
Then STDERR should contain:
138-
"""
139-
Debug (db): Running shell command: /usr/bin/env mysqlcheck --no-defaults %s
140-
"""
134+
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#
141135

142136
When I try `wp db check --no-defaults --debug`
143-
Then STDERR should contain:
144-
"""
145-
Debug (db): Running shell command: /usr/bin/env mysqlcheck --no-defaults %s
146-
"""
137+
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#
138+

features/db-export.feature

+3-12
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,10 @@ Feature: Export a WordPress database
8282
Given a WP install
8383

8484
When I try `wp db export --defaults --debug`
85-
Then STDERR should contain:
86-
"""
87-
Debug (db): Running initial shell command: /usr/bin/env mysqldump
88-
"""
85+
Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump)#
8986

9087
When I try `wp db export --debug`
91-
Then STDERR should contain:
92-
"""
93-
Debug (db): Running initial shell command: /usr/bin/env mysqldump --no-defaults
94-
"""
88+
Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump) --no-defaults#
9589

9690
When I try `wp db export --no-defaults --debug`
97-
Then STDERR should contain:
98-
"""
99-
Debug (db): Running initial shell command: /usr/bin/env mysqldump --no-defaults
100-
"""
91+
Then STDERR should match #Debug \(db\): Running initial shell command: /usr/bin/env (mysqldump|mariadb-dump) --no-defaults#

src/DB_Command.php

+37-6
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@ public function clean( $_, $assoc_args ) {
250250
*/
251251
public function check( $_, $assoc_args ) {
252252

253-
$command = sprintf( '/usr/bin/env mysqlcheck%s %s', $this->get_defaults_flag_string( $assoc_args ), '%s' );
253+
$command = sprintf(
254+
'/usr/bin/env %s%s %s',
255+
$this->get_check_command(),
256+
$this->get_defaults_flag_string( $assoc_args ),
257+
'%s'
258+
);
254259
WP_CLI::debug( "Running shell command: {$command}", 'db' );
255260

256261
$assoc_args['check'] = true;
@@ -293,8 +298,12 @@ public function check( $_, $assoc_args ) {
293298
* Success: Database optimized.
294299
*/
295300
public function optimize( $_, $assoc_args ) {
296-
297-
$command = sprintf( '/usr/bin/env mysqlcheck%s %s', $this->get_defaults_flag_string( $assoc_args ), '%s' );
301+
$command = sprintf(
302+
'/usr/bin/env %s%s %s',
303+
$this->get_check_command(),
304+
$this->get_defaults_flag_string( $assoc_args ),
305+
'%s'
306+
);
298307
WP_CLI::debug( "Running shell command: {$command}", 'db' );
299308

300309
$assoc_args['optimize'] = true;
@@ -337,8 +346,12 @@ public function optimize( $_, $assoc_args ) {
337346
* Success: Database repaired.
338347
*/
339348
public function repair( $_, $assoc_args ) {
340-
341-
$command = sprintf( '/usr/bin/env mysqlcheck%s %s', $this->get_defaults_flag_string( $assoc_args ), '%s' );
349+
$command = sprintf(
350+
'/usr/bin/env %s%s %s',
351+
$this->get_check_command(),
352+
$this->get_defaults_flag_string( $assoc_args ),
353+
'%s'
354+
);
342355
WP_CLI::debug( "Running shell command: {$command}", 'db' );
343356

344357
$assoc_args['repair'] = true;
@@ -611,7 +624,7 @@ public function export( $args, $assoc_args ) {
611624
$assoc_args['result-file'] = $result_file;
612625
}
613626

614-
$mysqldump_binary = Utils\force_env_on_nix_systems( 'mysqldump' );
627+
$mysqldump_binary = Utils\force_env_on_nix_systems( $this->get_dump_command() );
615628

616629
$support_column_statistics = exec( $mysqldump_binary . ' --help | grep "column-statistics"' );
617630

@@ -2152,4 +2165,22 @@ protected function get_current_sql_modes( $assoc_args ) {
21522165

21532166
return $modes;
21542167
}
2168+
2169+
/**
2170+
* Returns the correct `check` command based on the detected database type.
2171+
*
2172+
* @return string The appropriate check command.
2173+
*/
2174+
private function get_check_command() {
2175+
return ( strpos( Utils\get_mysql_version(), 'MariaDB' ) !== false ) ? 'mariadb-check' : 'mysqlcheck';
2176+
}
2177+
2178+
/**
2179+
* Returns the correct `dump` command based on the detected database type.
2180+
*
2181+
* @return string The appropriate dump command.
2182+
*/
2183+
private function get_dump_command() {
2184+
return ( strpos( Utils\get_mysql_version(), 'MariaDB' ) !== false ) ? 'mariadb-dump' : 'mysqldump';
2185+
}
21552186
}

0 commit comments

Comments
 (0)