@@ -250,7 +250,7 @@ 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 ( '%s%s %s ' , $ this -> sanitize_mysql_command ( ' mysqlcheck ' ) , $ this ->get_defaults_flag_string ( $ assoc_args ), '%s ' );
254
254
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
255
255
256
256
$ assoc_args ['check ' ] = true ;
@@ -294,7 +294,7 @@ public function check( $_, $assoc_args ) {
294
294
*/
295
295
public function optimize ( $ _ , $ assoc_args ) {
296
296
297
- $ command = sprintf ( '/usr/bin/env mysqlcheck%s %s ' , $ this ->get_defaults_flag_string ( $ assoc_args ), '%s ' );
297
+ $ command = sprintf ( '%s%s %s ' , $ this -> sanitize_mysql_command ( ' mysqlcheck ' ) , $ this ->get_defaults_flag_string ( $ assoc_args ), '%s ' );
298
298
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
299
299
300
300
$ assoc_args ['optimize ' ] = true ;
@@ -338,7 +338,7 @@ public function optimize( $_, $assoc_args ) {
338
338
*/
339
339
public function repair ( $ _ , $ assoc_args ) {
340
340
341
- $ command = sprintf ( '/usr/bin/env mysqlcheck%s %s ' , $ this ->get_defaults_flag_string ( $ assoc_args ), '%s ' );
341
+ $ command = sprintf ( '%s%s %s ' , $ this -> sanitize_mysql_command ( ' mysqlcheck ' ) , $ this ->get_defaults_flag_string ( $ assoc_args ), '%s ' );
342
342
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
343
343
344
344
$ assoc_args ['repair ' ] = true ;
@@ -384,7 +384,7 @@ public function repair( $_, $assoc_args ) {
384
384
*/
385
385
public function cli ( $ _ , $ assoc_args ) {
386
386
387
- $ command = sprintf ( '/usr/bin/env mysql%s --no-auto-rehash ' , $ this ->get_defaults_flag_string ( $ assoc_args ) );
387
+ $ command = sprintf ( '%s%s --no-auto-rehash ' , $ this -> sanitize_mysql_command ( ' mysql ' ) , $ this ->get_defaults_flag_string ( $ assoc_args ) );
388
388
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
389
389
390
390
if ( ! isset ( $ assoc_args ['database ' ] ) ) {
@@ -483,7 +483,7 @@ public function cli( $_, $assoc_args ) {
483
483
*/
484
484
public function query ( $ args , $ assoc_args ) {
485
485
486
- $ command = sprintf ( '/usr/bin/env mysql%s --no-auto-rehash ' , $ this ->get_defaults_flag_string ( $ assoc_args ) );
486
+ $ command = sprintf ( '%s%s --no-auto-rehash ' , $ this -> sanitize_mysql_command ( ' mysql ' ) , $ this ->get_defaults_flag_string ( $ assoc_args ) );
487
487
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
488
488
489
489
$ assoc_args ['database ' ] = DB_NAME ;
@@ -611,7 +611,7 @@ public function export( $args, $assoc_args ) {
611
611
$ assoc_args ['result-file ' ] = $ result_file ;
612
612
}
613
613
614
- $ mysqldump_binary = Utils \force_env_on_nix_systems ( 'mysqldump ' );
614
+ $ mysqldump_binary = $ this -> sanitize_mysql_command ( 'mysqldump ' );
615
615
616
616
$ support_column_statistics = exec ( $ mysqldump_binary . ' --help | grep "column-statistics" ' );
617
617
@@ -701,7 +701,8 @@ private function get_posts_table_charset( $assoc_args ) {
701
701
702
702
list ( $ stdout , $ stderr , $ exit_code ) = self ::run (
703
703
sprintf (
704
- '/usr/bin/env mysql%s --no-auto-rehash --batch --skip-column-names ' ,
704
+ '%s%s --no-auto-rehash --batch --skip-column-names ' ,
705
+ $ this ->sanitize_mysql_command ( 'mysql ' ),
705
706
$ this ->get_defaults_flag_string ( $ assoc_args )
706
707
),
707
708
[ 'execute ' => $ query ],
@@ -788,7 +789,7 @@ public function import( $args, $assoc_args ) {
788
789
$ result_file = 'STDIN ' ;
789
790
}
790
791
791
- $ command = sprintf ( '/usr/bin/env mysql%s --no-auto-rehash ' , $ this ->get_defaults_flag_string ( $ assoc_args ) );
792
+ $ command = sprintf ( '%s%s --no-auto-rehash ' , $ this -> sanitize_mysql_command ( ' mysql ' ) , $ this ->get_defaults_flag_string ( $ assoc_args ) );
792
793
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
793
794
WP_CLI ::debug ( 'Associative arguments: ' . json_encode ( $ assoc_args ), 'db ' );
794
795
@@ -1721,7 +1722,8 @@ protected function run_query( $query, $assoc_args = [] ) {
1721
1722
1722
1723
self ::run (
1723
1724
sprintf (
1724
- '/usr/bin/env mysql%s --no-auto-rehash ' ,
1725
+ '%s%s --no-auto-rehash ' ,
1726
+ $ this ->sanitize_mysql_command ( 'mysql ' ),
1725
1727
$ this ->get_defaults_flag_string ( $ assoc_args )
1726
1728
),
1727
1729
array_merge ( [ 'execute ' => $ query ], $ mysql_args )
@@ -2121,7 +2123,8 @@ protected function get_current_sql_modes( $assoc_args ) {
2121
2123
2122
2124
list ( $ stdout , $ stderr , $ exit_code ) = self ::run (
2123
2125
sprintf (
2124
- '/usr/bin/env mysql%s --no-auto-rehash --batch --skip-column-names ' ,
2126
+ '%s%s --no-auto-rehash --batch --skip-column-names ' ,
2127
+ $ this ->sanitize_mysql_command ( 'mysql ' ),
2125
2128
$ this ->get_defaults_flag_string ( $ assoc_args )
2126
2129
),
2127
2130
array_merge ( $ args , [ 'execute ' => 'SELECT @@SESSION.sql_mode ' ] ),
@@ -2152,4 +2155,20 @@ protected function get_current_sql_modes( $assoc_args ) {
2152
2155
2153
2156
return $ modes ;
2154
2157
}
2158
+
2159
+ /**
2160
+ * Helper to sanitize `mysql` command.
2161
+ * If the system has MariaDB installed, the user get the warning message:
2162
+ * /usr/bin/mysqldump: Deprecated program name.
2163
+ * It will be removed in a future release, use '/usr/bin/mariadb-dump' instead
2164
+ *
2165
+ * This helper will sanitize the `mysql` command to use `mariadb-dump` instead
2166
+ * of `mysqldump` if the system has MariaDB installed.
2167
+ *
2168
+ * @param string
2169
+ * @return string
2170
+ */
2171
+ private static function sanitize_mysql_command ( $ command ) {
2172
+ return sprintf ( '/usr/bin/env $(/usr/bin/readlink $(command -v %s)) ' , $ command );
2173
+ }
2155
2174
}
0 commit comments