Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions features/search-replace.feature
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@ Feature: Do global search/replace
wp_awesome
"""

@require-mysql
Scenario: Skip views during search/replace
Given a WP install
And I run `wp db query "CREATE VIEW wp_posts_view AS SELECT ID, post_title FROM wp_posts;"`

When I run `wp search-replace foo bar --all-tables-with-prefix`
Then STDOUT should contain:
"""
wp_posts_view
"""
And STDOUT should contain:
"""
skipped (view)
"""

When I run `wp search-replace foo bar --all-tables`
Then STDOUT should contain:
"""
wp_posts_view
"""
And STDOUT should contain:
"""
skipped (view)
"""

@require-mysql
Scenario: Run on unregistered, unprefixed tables with --all-tables flag
Given a WP install
Expand Down
14 changes: 13 additions & 1 deletion src/Search_Replace_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,26 @@ public function __invoke( $args, $assoc_args ) {
// Get table names based on leftover $args or supplied $assoc_args
$tables = Utils\wp_get_table_names( $args, $assoc_args );

foreach ( $tables as $table ) {
// Identify views so they can be skipped; views are dynamic and cannot be directly modified.
$views_args = $assoc_args;
$views_args['views-only'] = true;
$views = Utils\wp_get_table_names( [], $views_args );
$view_set = array_flip( array_intersect( $views, $tables ) );

foreach ( $tables as $table ) {
foreach ( $this->skip_tables as $skip_table ) {
if ( fnmatch( $skip_table, $table ) ) {
continue 2;
}
}

if ( isset( $view_set[ $table ] ) ) {
if ( $this->report && ! $this->report_changed_only ) {
$report[] = array( $table, '', 'skipped (view)', '' );
}
continue;
}

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

if ( $this->export_handle ) {
Expand Down
Loading