From 2545c1a9ebde8b27b9f6670a1c865b7e0f8a1d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Joahny?= Date: Fri, 19 Jul 2019 16:55:52 +0200 Subject: [PATCH 1/2] Adds wildcards support to skip-tables parameter --- README.md | 2 +- features/search-replace-export.feature | 14 ++++++++++++++ features/search-replace.feature | 10 ++++++++++ src/Search_Replace_Command.php | 8 +++++--- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a4470f210..f2133a34a 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ change primary key values. [--skip-tables=] Do not perform the replacement on specific tables. Use commas to - specify multiple tables. + specify multiple tables. Wildcards are supported, e.g. `'wp_*options'` or `'wp_post*'`. [--skip-columns=] Do not perform the replacement on specific columns. Use commas to diff --git a/features/search-replace-export.feature b/features/search-replace-export.feature index 61dc07f81..7e227445a 100644 --- a/features/search-replace-export.feature +++ b/features/search-replace-export.feature @@ -26,6 +26,20 @@ Feature: Search / replace with file export INSERT INTO `wp_options` """ + When I run `wp search-replace example.com example.net --skip-tables=wp_opt\?ons,wp_post\* --export` + Then STDOUT should not contain: + """ + wp_posts + """ + And STDOUT should not contain: + """ + wp_postmeta + """ + And STDOUT should not contain: + """ + wp_options + """ + When I run `wp search-replace example.com example.net --skip-columns=option_value --export` Then STDOUT should contain: """ diff --git a/features/search-replace.feature b/features/search-replace.feature index e57fd9f9a..1a4aa7ca8 100644 --- a/features/search-replace.feature +++ b/features/search-replace.feature @@ -15,6 +15,16 @@ Feature: Do global search/replace wp_posts """ + When I run `wp search-replace foo bar --skip-tables=wp_post\*` + Then STDOUT should not contain: + """ + wp_posts + """ + And STDOUT should not contain: + """ + wp_postmeta + """ + When I run `wp search-replace foo bar --skip-columns=guid` Then STDOUT should not contain: """ diff --git a/src/Search_Replace_Command.php b/src/Search_Replace_Command.php index fad2b9083..281748c59 100644 --- a/src/Search_Replace_Command.php +++ b/src/Search_Replace_Command.php @@ -77,7 +77,7 @@ class Search_Replace_Command extends WP_CLI_Command { * * [--skip-tables=] * : Do not perform the replacement on specific tables. Use commas to - * specify multiple tables. + * specify multiple tables. Wildcards are supported, e.g. `'wp_*options'` or `'wp_post*'`. * * [--skip-columns=] * : Do not perform the replacement on specific columns. Use commas to @@ -316,8 +316,10 @@ public function __invoke( $args, $assoc_args ) { foreach ( $tables as $table ) { - if ( in_array( $table, $this->skip_tables, true ) ) { - continue; + foreach ( $this->skip_tables as $skip_table ) { + if ( fnmatch( $skip_table, $table ) ) { + continue 2; + } } $table_sql = self::esc_sql_ident( $table ); From c270da0e2c9543fa5e4843ed7f9e3a494507cf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Joahny?= Date: Wed, 24 Jul 2019 15:35:53 +0200 Subject: [PATCH 2/2] add a positive condition to tests --- features/search-replace-export.feature | 4 ++++ features/search-replace.feature | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/features/search-replace-export.feature b/features/search-replace-export.feature index 7e227445a..7a24fab24 100644 --- a/features/search-replace-export.feature +++ b/features/search-replace-export.feature @@ -39,6 +39,10 @@ Feature: Search / replace with file export """ wp_options """ + And STDOUT should contain: + """ + wp_users + """ When I run `wp search-replace example.com example.net --skip-columns=option_value --export` Then STDOUT should contain: diff --git a/features/search-replace.feature b/features/search-replace.feature index 1a4aa7ca8..d354134b0 100644 --- a/features/search-replace.feature +++ b/features/search-replace.feature @@ -24,6 +24,10 @@ Feature: Do global search/replace """ wp_postmeta """ + And STDOUT should contain: + """ + wp_users + """ When I run `wp search-replace foo bar --skip-columns=guid` Then STDOUT should not contain: