@@ -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 ' , $ 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 ' , $ 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 ' , $ 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 --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 --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,8 +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 ' ,
705
- $ this ->get_defaults_flag_string ( $ assoc_args )
704
+ '%s --no-auto-rehash --batch --skip-column-names ' ,
705
+ $ this ->sanitize_mysql_command ( ' mysql ' , $ this -> get_defaults_flag_string ( $ assoc_args ) )
706
706
),
707
707
[ 'execute ' => $ query ],
708
708
false
@@ -788,7 +788,7 @@ public function import( $args, $assoc_args ) {
788
788
$ result_file = 'STDIN ' ;
789
789
}
790
790
791
- $ command = sprintf ( '/usr/bin/env mysql %s --no-auto-rehash ' , $ this ->get_defaults_flag_string ( $ assoc_args ) );
791
+ $ command = sprintf ( '%s --no-auto-rehash ' , $ this ->sanitize_mysql_command ( ' mysql ' , $ this -> get_defaults_flag_string ( $ assoc_args ) ) );
792
792
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
793
793
WP_CLI ::debug ( 'Associative arguments: ' . json_encode ( $ assoc_args ), 'db ' );
794
794
@@ -1721,8 +1721,8 @@ protected function run_query( $query, $assoc_args = [] ) {
1721
1721
1722
1722
self ::run (
1723
1723
sprintf (
1724
- '/usr/bin/env mysql %s --no-auto-rehash ' ,
1725
- $ this ->get_defaults_flag_string ( $ assoc_args )
1724
+ '%s --no-auto-rehash ' ,
1725
+ $ this ->sanitize_mysql_command ( ' mysql ' , $ this -> get_defaults_flag_string ( $ assoc_args ) )
1726
1726
),
1727
1727
array_merge ( [ 'execute ' => $ query ], $ mysql_args )
1728
1728
);
@@ -2121,8 +2121,8 @@ protected function get_current_sql_modes( $assoc_args ) {
2121
2121
2122
2122
list ( $ stdout , $ stderr , $ exit_code ) = self ::run (
2123
2123
sprintf (
2124
- '/usr/bin/env mysql %s --no-auto-rehash --batch --skip-column-names ' ,
2125
- $ this ->get_defaults_flag_string ( $ assoc_args )
2124
+ '%s --no-auto-rehash --batch --skip-column-names ' ,
2125
+ $ this ->sanitize_mysql_command ( ' mysql ' , $ this -> get_defaults_flag_string ( $ assoc_args ) )
2126
2126
),
2127
2127
array_merge ( $ args , [ 'execute ' => 'SELECT @@SESSION.sql_mode ' ] ),
2128
2128
false
@@ -2152,4 +2152,26 @@ protected function get_current_sql_modes( $assoc_args ) {
2152
2152
2153
2153
return $ modes ;
2154
2154
}
2155
+
2156
+ /**
2157
+ * Helper to sanitize `mysql` command.
2158
+ * If the system has MariaDB installed, the user get the warning message:
2159
+ * /usr/bin/mysqldump: Deprecated program name.
2160
+ * It will be removed in a future release, use '/usr/bin/mariadb-dump' instead
2161
+ *
2162
+ * This helper will sanitize the `mysql` command to use `mariadb-dump` instead
2163
+ * of `mysqldump` if the system has MariaDB installed.
2164
+ *
2165
+ * @param string mysql command
2166
+ * @param string default flags
2167
+ * @return string
2168
+ */
2169
+ private static function sanitize_mysql_command ( $ command , $ default_flags ) {
2170
+ return sprintf ( '/usr/bin/env $(test -L $(command -v %s) && /usr/bin/readlink -f $(command -v %s) || command -v %s)%s ' ,
2171
+ $ command ,
2172
+ $ command ,
2173
+ $ command ,
2174
+ $ default_flags
2175
+ );
2176
+ }
2155
2177
}
0 commit comments