Skip to content

Commit 0cc54a7

Browse files
committed
Allow all mysql flags while importing database
1 parent d35634a commit 0cc54a7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/DB_Command.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ public function export( $args, $assoc_args ) {
539539
* [--dbpass=<value>]
540540
* : Password to pass to mysql. Defaults to DB_PASSWORD.
541541
*
542+
* [--<field>=<value>]
543+
* : Extra arguments to pass to mysqldump. [Refer to mysqldump docs](https://dev.mysql.com/doc/en/mysqldump.html#mysqldump-option-summary).
544+
*
542545
* [--skip-optimization]
543546
* : When using an SQL file, do not include speed optimization such as disabling auto-commit and key checks.
544547
*
@@ -555,10 +558,7 @@ public function import( $args, $assoc_args ) {
555558
$result_file = sprintf( '%s.sql', DB_NAME );
556559
}
557560

558-
$mysql_args = array(
559-
'database' => DB_NAME,
560-
);
561-
$mysql_args = array_merge( self::get_dbuser_dbpass_args( $assoc_args ), $mysql_args );
561+
$assoc_args['database'] = DB_NAME;
562562

563563
if ( '-' !== $result_file ) {
564564
if ( ! is_readable( $result_file ) ) {
@@ -569,10 +569,14 @@ public function import( $args, $assoc_args ) {
569569
? 'SOURCE %s;'
570570
: 'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %s; COMMIT;';
571571

572-
$mysql_args['execute'] = sprintf( $query, $result_file );
572+
if ( isset( $assoc_args['skip-optimization'] ) ) {
573+
unset( $assoc_args['skip-optimization'] );
574+
}
575+
576+
$assoc_args['execute'] = sprintf( $query, $result_file );
573577
}
574578

575-
self::run( '/usr/bin/env mysql --no-defaults --no-auto-rehash', $mysql_args );
579+
self::run( '/usr/bin/env mysql --no-defaults --no-auto-rehash', $assoc_args );
576580

577581
WP_CLI::success( sprintf( "Imported from '%s'.", $result_file ) );
578582
}
@@ -1025,10 +1029,10 @@ public function prefix() {
10251029
* | 98 | foo_options | a:1:{s:12:"_multiwidget";i:1;} | yes |
10261030
* | 99 | foo_settings | a:0:{} | yes |
10271031
* +----+--------------+--------------------------------+-----+
1028-
*
1032+
*
10291033
* # SQL search and delete records from database table 'wp_options' where 'option_name' match 'foo'
10301034
* wp db query "DELETE from wp_options where option_id in ($(wp db query "SELECT GROUP_CONCAT(option_id SEPARATOR ',') from wp_options where option_name like '%foo%';" --silent --skip-column-names))"
1031-
*
1035+
*
10321036
* @when after_wp_load
10331037
*/
10341038
public function search( $args, $assoc_args ) {

0 commit comments

Comments
 (0)