@@ -80,7 +80,7 @@ class DB_Command extends WP_CLI_Command {
80
80
*/
81
81
public function create ( $ _ , $ assoc_args ) {
82
82
83
- $ this ->run_query ( self ::get_create_query (), self :: get_dbuser_dbpass_args ( $ assoc_args ) );
83
+ $ this ->run_query ( self ::get_create_query (), $ assoc_args );
84
84
85
85
WP_CLI ::success ( 'Database created. ' );
86
86
}
@@ -111,7 +111,7 @@ public function create( $_, $assoc_args ) {
111
111
public function drop ( $ _ , $ assoc_args ) {
112
112
WP_CLI ::confirm ( "Are you sure you want to drop the ' " . DB_NAME . "' database? " , $ assoc_args );
113
113
114
- $ this ->run_query ( sprintf ( 'DROP DATABASE `%s` ' , DB_NAME ), self :: get_dbuser_dbpass_args ( $ assoc_args ) );
114
+ $ this ->run_query ( sprintf ( 'DROP DATABASE `%s` ' , DB_NAME ), $ assoc_args );
115
115
116
116
WP_CLI ::success ( 'Database dropped. ' );
117
117
}
@@ -142,10 +142,8 @@ public function drop( $_, $assoc_args ) {
142
142
public function reset ( $ _ , $ assoc_args ) {
143
143
WP_CLI ::confirm ( "Are you sure you want to reset the ' " . DB_NAME . "' database? " , $ assoc_args );
144
144
145
- $ mysql_args = self ::get_dbuser_dbpass_args ( $ assoc_args );
146
-
147
- $ this ->run_query ( sprintf ( 'DROP DATABASE IF EXISTS `%s` ' , DB_NAME ), $ mysql_args );
148
- $ this ->run_query ( self ::get_create_query (), $ mysql_args );
145
+ $ this ->run_query ( sprintf ( 'DROP DATABASE IF EXISTS `%s` ' , DB_NAME ), $ assoc_args );
146
+ $ this ->run_query ( self ::get_create_query (), $ assoc_args );
149
147
150
148
WP_CLI ::success ( 'Database reset. ' );
151
149
}
@@ -187,8 +185,6 @@ public function clean( $_, $assoc_args ) {
187
185
$ assoc_args
188
186
);
189
187
190
- $ mysql_args = self ::get_dbuser_dbpass_args ( $ assoc_args );
191
-
192
188
$ tables = Utils \wp_get_table_names (
193
189
[],
194
190
[ 'all-tables-with-prefix ' => true ]
@@ -201,7 +197,7 @@ public function clean( $_, $assoc_args ) {
201
197
DB_NAME ,
202
198
$ table
203
199
),
204
- $ mysql_args
200
+ $ assoc_args
205
201
);
206
202
}
207
203
@@ -718,10 +714,12 @@ public function import( $args, $assoc_args ) {
718
714
$ result_file = sprintf ( '%s.sql ' , DB_NAME );
719
715
}
720
716
721
- $ mysql_args = [
722
- 'database ' => DB_NAME ,
723
- ];
724
- $ mysql_args = array_merge ( self ::get_dbuser_dbpass_args ( $ assoc_args ), $ mysql_args );
717
+ // Process options to MySQL.
718
+ $ mysql_args = array_merge (
719
+ [ 'database ' => DB_NAME ],
720
+ self ::get_dbuser_dbpass_args ( $ assoc_args ),
721
+ self ::get_mysql_args ( $ assoc_args )
722
+ );
725
723
726
724
if ( '- ' !== $ result_file ) {
727
725
if ( ! is_readable ( $ result_file ) ) {
@@ -738,8 +736,6 @@ public function import( $args, $assoc_args ) {
738
736
} else {
739
737
$ result_file = 'STDIN ' ;
740
738
}
741
- // Check if any mysql option pass.
742
- $ mysql_args = array_merge ( $ mysql_args , self ::get_mysql_args ( $ assoc_args ) );
743
739
744
740
$ command = sprintf ( '/usr/bin/env mysql%s --no-auto-rehash ' , $ this ->get_defaults_flag_string ( $ assoc_args ) );
745
741
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
@@ -1548,12 +1544,17 @@ protected function run_query( $query, $assoc_args = [] ) {
1548
1544
1549
1545
WP_CLI ::debug ( "Query: {$ query }" , 'db ' );
1550
1546
1547
+ $ mysql_args = array_merge (
1548
+ self ::get_dbuser_dbpass_args ( $ assoc_args ),
1549
+ self ::get_mysql_args ( $ assoc_args )
1550
+ );
1551
+
1551
1552
self ::run (
1552
1553
sprintf (
1553
1554
'/usr/bin/env mysql%s --no-auto-rehash ' ,
1554
1555
$ this ->get_defaults_flag_string ( $ assoc_args )
1555
1556
),
1556
- array_merge ( $ assoc_args , [ 'execute ' => $ query ] )
1557
+ array_merge ( [ 'execute ' => $ query ], $ mysql_args )
1557
1558
);
1558
1559
}
1559
1560
@@ -1599,7 +1600,20 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
1599
1600
unset( $ assoc_args ['dbpass ' ], $ assoc_args ['password ' ] );
1600
1601
}
1601
1602
1602
- $ final_args = array_merge ( $ assoc_args , $ required );
1603
+ $ final_args = array_merge ( $ required , $ assoc_args );
1604
+
1605
+ // Adapt ordering of arguments.
1606
+ uksort (
1607
+ $ final_args ,
1608
+ static function ( $ a , $ b ) {
1609
+ switch ( $ b ) {
1610
+ case 'force ' :
1611
+ return -1 ;
1612
+ default :
1613
+ return 1 ;
1614
+ }
1615
+ }
1616
+ );
1603
1617
1604
1618
return Utils \run_mysql_command ( $ cmd , $ final_args , null , $ send_to_shell , $ interactive );
1605
1619
}
0 commit comments