Skip to content

Commit becf8d3

Browse files
committed
Add test, simplify code
1 parent da05200 commit becf8d3

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

‎features/db-export.feature‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ Feature: Export a WordPress database
7070
PRAGMA foreign_keys=OFF
7171
"""
7272

73+
@skip-mariadb @skip-sqlite
74+
Scenario: Exclude data of certain tables is not supported by MySQL
75+
Given a WP install
76+
77+
When I try `wp db export wp_cli_test.sql --exclude_tables_data=wp_users`
78+
Then the return code should be 1
79+
And STDERR should contain:
80+
"""
81+
Error: The --exclude_tables_data option is only supported by MariaDB.
82+
"""
83+
7384
# Only MariaDB currently supports this feature.
7485
@require-mariadb
7586
Scenario: Exclude data of certain tables when exporting the database

‎src/DB_Command.php‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -812,24 +812,21 @@ public function export( $args, $assoc_args ) {
812812
}
813813
}
814814

815-
$exclude_tables_data = Utils\get_flag_value( $assoc_args, 'exclude_tables_data' );
816-
if ( isset( $exclude_tables_data ) ) {
817-
unset( $assoc_args['exclude_tables_data'] );
818-
if ( is_string( $exclude_tables_data ) && '' !== trim( $exclude_tables_data ) ) {
819-
if ( 'mariadb' !== Utils\get_db_type() ) {
820-
WP_CLI::error( 'The --exclude_tables_data option is only supported by MariaDB.' );
821-
}
815+
$exclude_tables_data = Utils\get_flag_value( $assoc_args, 'exclude_tables_data', '' );
816+
if ( ! empty( $exclude_tables_data ) ) {
817+
if ( 'mariadb' !== Utils\get_db_type() ) {
818+
WP_CLI::error( 'The --exclude_tables_data option is only supported by MariaDB.' );
819+
}
822820

823-
$tables = explode( ',', trim( $exclude_tables_data, ',' ) );
824-
foreach ( $tables as $table ) {
825-
$table = trim( $table );
826-
if ( '' === $table ) {
827-
continue;
828-
}
829-
$command .= ' --ignore-table-data';
830-
$command .= ' %s';
831-
$command_esc_args[] = DB_NAME . '.' . $table;
821+
$tables = explode( ',', trim( $exclude_tables_data, ',' ) );
822+
foreach ( $tables as $table ) {
823+
$table = trim( $table );
824+
if ( '' === $table ) {
825+
continue;
832826
}
827+
$command .= ' --ignore-table-data';
828+
$command .= ' %s';
829+
$command_esc_args[] = DB_NAME . '.' . $table;
833830
}
834831
}
835832

0 commit comments

Comments
 (0)