Skip to content

Commit

Permalink
Merge pull request #124 from ajoah/skip-tables-wildcard
Browse files Browse the repository at this point in the history
Adds wildcards support to `--skip-tables` parameter
  • Loading branch information
schlessera committed Jul 24, 2019
2 parents 7d02c54 + c270da0 commit 2872f04
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ change primary key values.

[--skip-tables=<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=<columns>]
Do not perform the replacement on specific columns. Use commas to
Expand Down
18 changes: 18 additions & 0 deletions features/search-replace-export.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ 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
"""
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:
"""
Expand Down
14 changes: 14 additions & 0 deletions features/search-replace.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ 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
"""
And STDOUT should contain:
"""
wp_users
"""

When I run `wp search-replace foo bar --skip-columns=guid`
Then STDOUT should not contain:
"""
Expand Down
8 changes: 5 additions & 3 deletions src/Search_Replace_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Search_Replace_Command extends WP_CLI_Command {
*
* [--skip-tables=<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=<columns>]
* : Do not perform the replacement on specific columns. Use commas to
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 2872f04

Please sign in to comment.