Skip to content

Commit 2872f04

Browse files
authored
Merge pull request #124 from ajoah/skip-tables-wildcard
Adds wildcards support to `--skip-tables` parameter
2 parents 7d02c54 + c270da0 commit 2872f04

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ change primary key values.
6363

6464
[--skip-tables=<tables>]
6565
Do not perform the replacement on specific tables. Use commas to
66-
specify multiple tables.
66+
specify multiple tables. Wildcards are supported, e.g. `'wp_*options'` or `'wp_post*'`.
6767

6868
[--skip-columns=<columns>]
6969
Do not perform the replacement on specific columns. Use commas to

features/search-replace-export.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ Feature: Search / replace with file export
2626
INSERT INTO `wp_options`
2727
"""
2828

29+
When I run `wp search-replace example.com example.net --skip-tables=wp_opt\?ons,wp_post\* --export`
30+
Then STDOUT should not contain:
31+
"""
32+
wp_posts
33+
"""
34+
And STDOUT should not contain:
35+
"""
36+
wp_postmeta
37+
"""
38+
And STDOUT should not contain:
39+
"""
40+
wp_options
41+
"""
42+
And STDOUT should contain:
43+
"""
44+
wp_users
45+
"""
46+
2947
When I run `wp search-replace example.com example.net --skip-columns=option_value --export`
3048
Then STDOUT should contain:
3149
"""

features/search-replace.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ Feature: Do global search/replace
1515
wp_posts
1616
"""
1717

18+
When I run `wp search-replace foo bar --skip-tables=wp_post\*`
19+
Then STDOUT should not contain:
20+
"""
21+
wp_posts
22+
"""
23+
And STDOUT should not contain:
24+
"""
25+
wp_postmeta
26+
"""
27+
And STDOUT should contain:
28+
"""
29+
wp_users
30+
"""
31+
1832
When I run `wp search-replace foo bar --skip-columns=guid`
1933
Then STDOUT should not contain:
2034
"""

src/Search_Replace_Command.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Search_Replace_Command extends WP_CLI_Command {
7777
*
7878
* [--skip-tables=<tables>]
7979
* : Do not perform the replacement on specific tables. Use commas to
80-
* specify multiple tables.
80+
* specify multiple tables. Wildcards are supported, e.g. `'wp_*options'` or `'wp_post*'`.
8181
*
8282
* [--skip-columns=<columns>]
8383
* : Do not perform the replacement on specific columns. Use commas to
@@ -316,8 +316,10 @@ public function __invoke( $args, $assoc_args ) {
316316

317317
foreach ( $tables as $table ) {
318318

319-
if ( in_array( $table, $this->skip_tables, true ) ) {
320-
continue;
319+
foreach ( $this->skip_tables as $skip_table ) {
320+
if ( fnmatch( $skip_table, $table ) ) {
321+
continue 2;
322+
}
321323
}
322324

323325
$table_sql = self::esc_sql_ident( $table );

0 commit comments

Comments
 (0)