@@ -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
@@ -721,7 +717,6 @@ public function import( $args, $assoc_args ) {
721
717
$ mysql_args = [
722
718
'database ' => DB_NAME ,
723
719
];
724
- $ mysql_args = array_merge ( self ::get_dbuser_dbpass_args ( $ assoc_args ), $ mysql_args );
725
720
726
721
if ( '- ' !== $ result_file ) {
727
722
if ( ! is_readable ( $ result_file ) ) {
@@ -1548,12 +1543,14 @@ protected function run_query( $query, $assoc_args = [] ) {
1548
1543
1549
1544
WP_CLI ::debug ( "Query: {$ query }" , 'db ' );
1550
1545
1546
+ $ mysql_args = self ::get_mysql_args ( $ assoc_args );
1547
+
1551
1548
self ::run (
1552
1549
sprintf (
1553
1550
'/usr/bin/env mysql%s --no-auto-rehash ' ,
1554
1551
$ this ->get_defaults_flag_string ( $ assoc_args )
1555
1552
),
1556
- array_merge ( $ assoc_args , [ 'execute ' => $ query ] )
1553
+ array_merge ( $ mysql_args , [ 'execute ' => $ query ] )
1557
1554
);
1558
1555
}
1559
1556
@@ -1604,25 +1601,6 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
1604
1601
return Utils \run_mysql_command ( $ cmd , $ final_args , null , $ send_to_shell , $ interactive );
1605
1602
}
1606
1603
1607
- /**
1608
- * Helper to pluck 'dbuser' and 'dbpass' from associative args array.
1609
- *
1610
- * @param array $assoc_args Associative args array.
1611
- * @return array Array with `dbuser' and 'dbpass' set if in passed-in associative args array.
1612
- */
1613
- private static function get_dbuser_dbpass_args ( $ assoc_args ) {
1614
- $ mysql_args = [];
1615
- $ dbuser = Utils \get_flag_value ( $ assoc_args , 'dbuser ' );
1616
- if ( null !== $ dbuser ) {
1617
- $ mysql_args ['dbuser ' ] = $ dbuser ;
1618
- }
1619
- $ dbpass = Utils \get_flag_value ( $ assoc_args , 'dbpass ' );
1620
- if ( null !== $ dbpass ) {
1621
- $ mysql_args ['dbpass ' ] = $ dbpass ;
1622
- }
1623
- return $ mysql_args ;
1624
- }
1625
-
1626
1604
/**
1627
1605
* Gets the column names of a db table differentiated into key columns and text columns and all columns.
1628
1606
*
0 commit comments