@@ -250,7 +250,12 @@ public function clean( $_, $assoc_args ) {
250
250
*/
251
251
public function check ( $ _ , $ assoc_args ) {
252
252
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
+ );
254
259
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
255
260
256
261
$ assoc_args ['check ' ] = true ;
@@ -293,8 +298,12 @@ public function check( $_, $assoc_args ) {
293
298
* Success: Database optimized.
294
299
*/
295
300
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
+ );
298
307
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
299
308
300
309
$ assoc_args ['optimize ' ] = true ;
@@ -337,8 +346,12 @@ public function optimize( $_, $assoc_args ) {
337
346
* Success: Database repaired.
338
347
*/
339
348
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
+ );
342
355
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
343
356
344
357
$ assoc_args ['repair ' ] = true ;
@@ -611,7 +624,7 @@ public function export( $args, $assoc_args ) {
611
624
$ assoc_args ['result-file ' ] = $ result_file ;
612
625
}
613
626
614
- $ mysqldump_binary = Utils \force_env_on_nix_systems ( ' mysqldump ' );
627
+ $ mysqldump_binary = Utils \force_env_on_nix_systems ( $ this -> get_dump_command () );
615
628
616
629
$ support_column_statistics = exec ( $ mysqldump_binary . ' --help | grep "column-statistics" ' );
617
630
@@ -2152,4 +2165,22 @@ protected function get_current_sql_modes( $assoc_args ) {
2152
2165
2153
2166
return $ modes ;
2154
2167
}
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
+ }
2155
2186
}
0 commit comments