From 64593b7474f85b60b4a3d59b8c86bb77acb4871b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 07:43:55 +0000 Subject: [PATCH 1/4] Initial plan From f779b17f59daeab68614ce51cdfa3066406f12ca Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 07:50:30 +0000 Subject: [PATCH 2/4] Skip views in search-replace command, report as skipped (view) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/search-replace.feature | 25 +++++++++++++++++++++++++ src/Search_Replace_Command.php | 12 ++++++++++++ 2 files changed, 37 insertions(+) diff --git a/features/search-replace.feature b/features/search-replace.feature index d6feee8a..84d67344 100644 --- a/features/search-replace.feature +++ b/features/search-replace.feature @@ -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 diff --git a/src/Search_Replace_Command.php b/src/Search_Replace_Command.php index bbad1bdf..4f9ea242 100644 --- a/src/Search_Replace_Command.php +++ b/src/Search_Replace_Command.php @@ -465,6 +465,11 @@ 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 ); + // 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( $args, $views_args ); + foreach ( $tables as $table ) { foreach ( $this->skip_tables as $skip_table ) { @@ -473,6 +478,13 @@ public function __invoke( $args, $assoc_args ) { } } + if ( in_array( $table, $views, true ) ) { + if ( $this->report && ! $this->report_changed_only ) { + $report[] = array( $table, '', 'skipped (view)', '' ); + } + continue; + } + $table_sql = self::esc_sql_ident( $table ); if ( $this->export_handle ) { From 7d6afea21bfac0e6882ac8eeb8fa58a1295a96f9 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 16 Mar 2026 09:50:03 +0100 Subject: [PATCH 3/4] Don't pass args --- src/Search_Replace_Command.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Search_Replace_Command.php b/src/Search_Replace_Command.php index 4f9ea242..e2a05483 100644 --- a/src/Search_Replace_Command.php +++ b/src/Search_Replace_Command.php @@ -468,10 +468,9 @@ public function __invoke( $args, $assoc_args ) { // 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( $args, $views_args ); + $views = Utils\wp_get_table_names( [], $views_args ); foreach ( $tables as $table ) { - foreach ( $this->skip_tables as $skip_table ) { if ( fnmatch( $skip_table, $table ) ) { continue 2; From fea95249b6d6dd1cb90e5ed764e9d32cafcaf8c8 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 16 Mar 2026 10:51:18 +0100 Subject: [PATCH 4/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/Search_Replace_Command.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Search_Replace_Command.php b/src/Search_Replace_Command.php index e2a05483..a5e2d291 100644 --- a/src/Search_Replace_Command.php +++ b/src/Search_Replace_Command.php @@ -469,6 +469,7 @@ public function __invoke( $args, $assoc_args ) { $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 ) { @@ -477,7 +478,7 @@ public function __invoke( $args, $assoc_args ) { } } - if ( in_array( $table, $views, true ) ) { + if ( isset( $view_set[ $table ] ) ) { if ( $this->report && ! $this->report_changed_only ) { $report[] = array( $table, '', 'skipped (view)', '' ); }