From 09314e6bdccd7542db5198a6393f740f7df1ab00 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 22:34:28 +0000 Subject: [PATCH 1/8] Initial plan From 92852e2a274e92dfa3a64c3683ddf8feb68060d3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 22:43:07 +0000 Subject: [PATCH 2/8] Add --show-changed-files flag for opcache invalidation support Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Plugin_Command.php | 4 +++ src/Theme_Command.php | 4 +++ src/WP_CLI/CommandWithUpgrade.php | 37 +++++++++++++++++++-- src/WP_CLI/ExtensionUpgraderSkin.php | 49 ++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 5ce246aca..d6e61eba8 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -707,6 +707,10 @@ protected function install_from_repo( $slug, $assoc_args ) { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * + * [--show-changed-files] + * : Show the list of files that were changed during the update. + * : Useful for invalidating PHP-FPM opcache using external tools. + * * ## EXAMPLES * * $ wp plugin update bbpress --version=dev diff --git a/src/Theme_Command.php b/src/Theme_Command.php index e18b17e89..73b4c9b16 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -691,6 +691,10 @@ public function get( $args, $assoc_args ) { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * + * [--show-changed-files] + * : Show the list of files that were changed during the update. + * : Useful for invalidating PHP-FPM opcache using external tools. + * * ## EXAMPLES * * # Update multiple themes diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 8326c168d..292659d7a 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -393,7 +393,7 @@ protected static function alter_api_response( $response, $version ) { } } - protected function get_upgrader( $assoc_args ) { + protected function get_upgrader( $assoc_args, $skin = null ) { $force = Utils\get_flag_value( $assoc_args, 'force', false ); $insecure = Utils\get_flag_value( $assoc_args, 'insecure', false ); $upgrader_class = $this->get_upgrader_class( $force ); @@ -404,7 +404,11 @@ protected function get_upgrader( $assoc_args ) { } } - return Utils\get_upgrader( $upgrader_class, $insecure, new ExtensionUpgraderSkin() ); + if ( null === $skin ) { + $skin = new ExtensionUpgraderSkin(); + } + + return Utils\get_upgrader( $upgrader_class, $insecure, $skin ); } protected function update_many( $args, $assoc_args ) { @@ -521,13 +525,24 @@ function ( $item ) { $result = array(); + // Check if file tracking is requested. + $show_changed_files = Utils\get_flag_value( $assoc_args, 'show-changed-files', false ); + $skin = null; + // Only attempt to update if there is something to update. if ( ! empty( $items_to_update ) ) { $cache_manager = WP_CLI::get_http_cache_manager(); foreach ( $items_to_update as $item ) { $cache_manager->whitelist_package( $item['update_package'], $this->item_type, $item['name'], $item['update_version'] ); } - $upgrader = $this->get_upgrader( $assoc_args ); + + // Enable file tracking if requested. + if ( $show_changed_files ) { + $skin = new ExtensionUpgraderSkin(); + $skin->enable_file_tracking(); + } + + $upgrader = $this->get_upgrader( $assoc_args, $skin ); // Ensure the upgrader uses the download offer present in each item. $transient_filter = function ( $transient ) use ( $items_to_update ) { foreach ( $items_to_update as $name => $item_data ) { @@ -604,6 +619,22 @@ static function ( $result ) { if ( null !== $exclude ) { WP_CLI::log( "Skipped updates for: $exclude" ); } + + // Output changed files if requested. + if ( $show_changed_files && null !== $skin ) { + $changed_files = $skin->get_changed_files(); + if ( ! empty( $changed_files ) ) { + // Remove duplicates and sort files. + $changed_files = array_unique( $changed_files ); + sort( $changed_files ); + + WP_CLI::log( '' ); + WP_CLI::log( 'Changed files:' ); + foreach ( $changed_files as $file ) { + WP_CLI::log( $file ); + } + } + } } // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Whitelisting to provide backward compatibility to classes possibly extending this class. diff --git a/src/WP_CLI/ExtensionUpgraderSkin.php b/src/WP_CLI/ExtensionUpgraderSkin.php index cef43ad27..c750ce5f1 100644 --- a/src/WP_CLI/ExtensionUpgraderSkin.php +++ b/src/WP_CLI/ExtensionUpgraderSkin.php @@ -14,6 +14,55 @@ */ class ExtensionUpgraderSkin extends UpgraderSkin { + /** + * List of files that were changed during the update process. + * + * @var array + */ + private $changed_files = []; + + /** + * Whether to track changed files. + * + * @var bool + */ + private $track_files = false; + + /** + * Enable file tracking for opcache invalidation. + */ + public function enable_file_tracking() { + $this->track_files = true; + $this->setup_file_tracking_hooks(); + } + + /** + * Get the list of changed files. + * + * @return array List of file paths. + */ + public function get_changed_files() { + return $this->changed_files; + } + + /** + * Setup hooks to track file changes during upgrade. + */ + private function setup_file_tracking_hooks() { + // Hook into wp_opcache_invalidate_file filter to track files being invalidated + add_filter( + 'wp_opcache_invalidate_file', + function ( $file ) { + if ( $this->track_files && ! empty( $file ) ) { + $this->changed_files[] = $file; + } + return $file; + }, + 10, + 1 + ); + } + /** * Called before an update is performed. */ From b024949bf4b482d03347c0ec44754dce21d0870d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 22:44:39 +0000 Subject: [PATCH 3/8] Use upgrader_post_install hook for reliable file tracking Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/plugin-update.feature | 18 +++++++++++++ features/theme-update.feature | 18 +++++++++++++ src/WP_CLI/ExtensionUpgraderSkin.php | 38 +++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/features/plugin-update.feature b/features/plugin-update.feature index 1cf5e248a..66f5b8ac1 100644 --- a/features/plugin-update.feature +++ b/features/plugin-update.feature @@ -289,3 +289,21 @@ Feature: Update WordPress plugins """ Success: Updated 2 of 2 plugins. """ + + @require-wp-5.2 + Scenario: Show changed files when updating plugins + Given a WP install + + When I run `wp plugin install wordpress-importer --version=0.5 --force` + Then STDOUT should not be empty + + When I run `wp plugin update wordpress-importer --show-changed-files` + Then STDOUT should contain: + """ + Changed files: + """ + And STDOUT should contain: + """ + wordpress-importer + """ + diff --git a/features/theme-update.feature b/features/theme-update.feature index adc546b0b..8c68a2591 100644 --- a/features/theme-update.feature +++ b/features/theme-update.feature @@ -176,3 +176,21 @@ Feature: Update WordPress themes """ Success: Updated 2 of 2 themes. """ + + Scenario: Show changed files when updating themes + Given a WP install + And I run `wp theme delete --all --force` + + When I run `wp theme install twentytwelve --version=3.0` + Then STDOUT should not be empty + + When I run `wp theme update twentytwelve --show-changed-files` + Then STDOUT should contain: + """ + Changed files: + """ + And STDOUT should contain: + """ + twentytwelve + """ + diff --git a/src/WP_CLI/ExtensionUpgraderSkin.php b/src/WP_CLI/ExtensionUpgraderSkin.php index c750ce5f1..b21bf9294 100644 --- a/src/WP_CLI/ExtensionUpgraderSkin.php +++ b/src/WP_CLI/ExtensionUpgraderSkin.php @@ -49,7 +49,20 @@ public function get_changed_files() { * Setup hooks to track file changes during upgrade. */ private function setup_file_tracking_hooks() { - // Hook into wp_opcache_invalidate_file filter to track files being invalidated + // Hook into upgrader_post_install to capture the destination directory + add_filter( + 'upgrader_post_install', + function ( $response, $hook_extra, $result ) { + if ( $this->track_files && is_array( $result ) && isset( $result['destination'] ) && is_string( $result['destination'] ) ) { + $this->scan_directory_for_files( $result['destination'] ); + } + return $response; + }, + 10, + 3 + ); + + // Also hook into wp_opcache_invalidate_file filter to track files being invalidated add_filter( 'wp_opcache_invalidate_file', function ( $file ) { @@ -63,6 +76,29 @@ function ( $file ) { ); } + /** + * Recursively scan a directory and add all PHP files to the changed files list. + * + * @param string $dir Directory to scan. + */ + private function scan_directory_for_files( $dir ) { + if ( ! is_dir( $dir ) ) { + return; + } + + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator( $dir, \RecursiveDirectoryIterator::SKIP_DOTS ), + \RecursiveIteratorIterator::SELF_FIRST + ); + + foreach ( $iterator as $file ) { + /** @var \SplFileInfo $file */ + if ( $file->isFile() && 'php' === $file->getExtension() ) { + $this->changed_files[] = $file->getPathname(); + } + } + } + /** * Called before an update is performed. */ From f6d816f14b47668acb6d3482603c9df2c0867c65 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 22:45:24 +0000 Subject: [PATCH 4/8] Add examples for --show-changed-files flag usage Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Plugin_Command.php | 9 +++++++++ src/Theme_Command.php | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index d6e61eba8..ca0804279 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -757,6 +757,15 @@ protected function install_from_repo( $slug, $assoc_args ) { * | nginx-cache-controller | 3.1.1 | 3.2.0 | Updated | * +------------------------+-------------+-------------+---------+ * + * # Show changed files for opcache invalidation + * $ wp plugin update akismet --show-changed-files + * Success: Updated 1 of 1 plugins. + * + * Changed files: + * /var/www/html/wp-content/plugins/akismet/akismet.php + * /var/www/html/wp-content/plugins/akismet/class.akismet.php + * ... + * * @alias upgrade */ public function update( $args, $assoc_args ) { diff --git a/src/Theme_Command.php b/src/Theme_Command.php index 73b4c9b16..8b34853bb 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -740,6 +740,15 @@ public function get( $args, $assoc_args ) { * # Update all themes * $ wp theme update --all * + * # Show changed files for opcache invalidation + * $ wp theme update twentytwelve --show-changed-files + * Success: Updated 1 of 1 themes. + * + * Changed files: + * /var/www/html/wp-content/themes/twentytwelve/style.php + * /var/www/html/wp-content/themes/twentytwelve/functions.php + * ... + * * @alias upgrade */ public function update( $args, $assoc_args ) { From 94b42b8dec2b344790b338af639d3e14ea40cb2d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 22:46:37 +0000 Subject: [PATCH 5/8] Address code review feedback: remove redundant hook and fix example Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Theme_Command.php | 2 +- src/WP_CLI/ExtensionUpgraderSkin.php | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/Theme_Command.php b/src/Theme_Command.php index 8b34853bb..fa1461a7b 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -745,8 +745,8 @@ public function get( $args, $assoc_args ) { * Success: Updated 1 of 1 themes. * * Changed files: - * /var/www/html/wp-content/themes/twentytwelve/style.php * /var/www/html/wp-content/themes/twentytwelve/functions.php + * /var/www/html/wp-content/themes/twentytwelve/footer.php * ... * * @alias upgrade diff --git a/src/WP_CLI/ExtensionUpgraderSkin.php b/src/WP_CLI/ExtensionUpgraderSkin.php index b21bf9294..f852bfc04 100644 --- a/src/WP_CLI/ExtensionUpgraderSkin.php +++ b/src/WP_CLI/ExtensionUpgraderSkin.php @@ -61,19 +61,6 @@ function ( $response, $hook_extra, $result ) { 10, 3 ); - - // Also hook into wp_opcache_invalidate_file filter to track files being invalidated - add_filter( - 'wp_opcache_invalidate_file', - function ( $file ) { - if ( $this->track_files && ! empty( $file ) ) { - $this->changed_files[] = $file; - } - return $file; - }, - 10, - 1 - ); } /** From bbc3db71fb23c9cfad9a3aa97c860e7d94326658 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 22:48:41 +0000 Subject: [PATCH 6/8] Add safeguards: prevent duplicate hooks, add error handling, clarify logic Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/WP_CLI/CommandWithUpgrade.php | 3 ++- src/WP_CLI/ExtensionUpgraderSkin.php | 36 +++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 292659d7a..657ba6195 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -527,7 +527,8 @@ function ( $item ) { // Check if file tracking is requested. $show_changed_files = Utils\get_flag_value( $assoc_args, 'show-changed-files', false ); - $skin = null; + // Skin is only created if file tracking is needed; otherwise get_upgrader creates default skin. + $skin = null; // Only attempt to update if there is something to update. if ( ! empty( $items_to_update ) ) { diff --git a/src/WP_CLI/ExtensionUpgraderSkin.php b/src/WP_CLI/ExtensionUpgraderSkin.php index f852bfc04..d5873d049 100644 --- a/src/WP_CLI/ExtensionUpgraderSkin.php +++ b/src/WP_CLI/ExtensionUpgraderSkin.php @@ -28,6 +28,13 @@ class ExtensionUpgraderSkin extends UpgraderSkin { */ private $track_files = false; + /** + * Whether file tracking hooks have been set up. + * + * @var bool + */ + private $hooks_setup = false; + /** * Enable file tracking for opcache invalidation. */ @@ -49,6 +56,13 @@ public function get_changed_files() { * Setup hooks to track file changes during upgrade. */ private function setup_file_tracking_hooks() { + // Prevent duplicate hook registrations. + if ( $this->hooks_setup ) { + return; + } + + $this->hooks_setup = true; + // Hook into upgrader_post_install to capture the destination directory add_filter( 'upgrader_post_install', @@ -73,16 +87,22 @@ private function scan_directory_for_files( $dir ) { return; } - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator( $dir, \RecursiveDirectoryIterator::SKIP_DOTS ), - \RecursiveIteratorIterator::SELF_FIRST - ); + try { + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator( $dir, \RecursiveDirectoryIterator::SKIP_DOTS ), + \RecursiveIteratorIterator::SELF_FIRST + ); - foreach ( $iterator as $file ) { - /** @var \SplFileInfo $file */ - if ( $file->isFile() && 'php' === $file->getExtension() ) { - $this->changed_files[] = $file->getPathname(); + foreach ( $iterator as $file ) { + /** @var \SplFileInfo $file */ + if ( $file->isFile() && 'php' === $file->getExtension() ) { + $this->changed_files[] = $file->getPathname(); + } } + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch -- Intentionally ignoring errors to prevent update failure. + } catch ( \Exception $e ) { + // Silently handle filesystem errors to prevent update process from failing. + // The changed files list may be incomplete, but the update should still succeed. } } From b0f85facb84f92a7e2b25bfdcce055ff04542057 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 15 Feb 2026 17:15:51 +0100 Subject: [PATCH 7/8] Fix synopsis --- src/Plugin_Command.php | 2 +- src/Theme_Command.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index ca0804279..cc6ff865f 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -709,7 +709,7 @@ protected function install_from_repo( $slug, $assoc_args ) { * * [--show-changed-files] * : Show the list of files that were changed during the update. - * : Useful for invalidating PHP-FPM opcache using external tools. + * Useful for invalidating PHP-FPM opcache using external tools. * * ## EXAMPLES * diff --git a/src/Theme_Command.php b/src/Theme_Command.php index fa1461a7b..62960d6ab 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -693,7 +693,7 @@ public function get( $args, $assoc_args ) { * * [--show-changed-files] * : Show the list of files that were changed during the update. - * : Useful for invalidating PHP-FPM opcache using external tools. + * Useful for invalidating PHP-FPM opcache using external tools. * * ## EXAMPLES * From e04f2534b6e93df1ff202282b08c10d29b3f9bec Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 15 Feb 2026 17:40:08 +0100 Subject: [PATCH 8/8] Use `wp_opcache_invalidate_file` filter instead --- phpcs.xml.dist | 2 +- src/Plugin_Command.php | 2 +- src/Theme_Command.php | 2 +- src/WP_CLI/CommandWithUpgrade.php | 32 +++------ src/WP_CLI/DestructiveThemeUpgrader.php | 2 +- src/WP_CLI/ExtensionUpgraderSkin.php | 92 ------------------------- src/WP_CLI/PluginUpgrader.php | 45 ++++++++++++ src/WP_CLI/ThemeUpgrader.php | 45 ++++++++++++ 8 files changed, 102 insertions(+), 120 deletions(-) create mode 100644 src/WP_CLI/PluginUpgrader.php create mode 100644 src/WP_CLI/ThemeUpgrader.php diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 96cef65a9..c78b63b53 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -59,7 +59,7 @@ */src/WP_CLI/Fetchers/(Plugin|Theme)\.php$ */src/WP_CLI/CommandWithUpgrade\.php$ - */src/WP_CLI/(CommandWith|DestructivePlugin|DestructiveTheme)Upgrader\.php$ + */src/WP_CLI/(CommandWith|DestructivePlugin|DestructiveTheme|Plugin|Theme)Upgrader\.php$ */src/WP_CLI/Parse(Plugin|Theme)NameInput\.php$ */src/WP_CLI/ExtensionUpgraderSkin\.php$ diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index cc6ff865f..10773a310 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -79,7 +79,7 @@ public function __construct() { } protected function get_upgrader_class( $force ) { - return $force ? '\\WP_CLI\\DestructivePluginUpgrader' : 'Plugin_Upgrader'; + return $force ? '\\WP_CLI\\DestructivePluginUpgrader' : '\\WP_CLI\\PluginUpgrader'; } /** diff --git a/src/Theme_Command.php b/src/Theme_Command.php index 62960d6ab..9d4392d74 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -76,7 +76,7 @@ public function __construct() { } protected function get_upgrader_class( $force ) { - return $force ? '\\WP_CLI\\DestructiveThemeUpgrader' : 'Theme_Upgrader'; + return $force ? '\\WP_CLI\\DestructiveThemeUpgrader' : '\\WP_CLI\\ThemeUpgrader'; } /** diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 657ba6195..bb48e6e86 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -393,7 +393,7 @@ protected static function alter_api_response( $response, $version ) { } } - protected function get_upgrader( $assoc_args, $skin = null ) { + protected function get_upgrader( $assoc_args ) { $force = Utils\get_flag_value( $assoc_args, 'force', false ); $insecure = Utils\get_flag_value( $assoc_args, 'insecure', false ); $upgrader_class = $this->get_upgrader_class( $force ); @@ -404,11 +404,7 @@ protected function get_upgrader( $assoc_args, $skin = null ) { } } - if ( null === $skin ) { - $skin = new ExtensionUpgraderSkin(); - } - - return Utils\get_upgrader( $upgrader_class, $insecure, $skin ); + return Utils\get_upgrader( $upgrader_class, $insecure, new ExtensionUpgraderSkin() ); } protected function update_many( $args, $assoc_args ) { @@ -525,11 +521,6 @@ function ( $item ) { $result = array(); - // Check if file tracking is requested. - $show_changed_files = Utils\get_flag_value( $assoc_args, 'show-changed-files', false ); - // Skin is only created if file tracking is needed; otherwise get_upgrader creates default skin. - $skin = null; - // Only attempt to update if there is something to update. if ( ! empty( $items_to_update ) ) { $cache_manager = WP_CLI::get_http_cache_manager(); @@ -537,13 +528,10 @@ function ( $item ) { $cache_manager->whitelist_package( $item['update_package'], $this->item_type, $item['name'], $item['update_version'] ); } - // Enable file tracking if requested. - if ( $show_changed_files ) { - $skin = new ExtensionUpgraderSkin(); - $skin->enable_file_tracking(); - } - - $upgrader = $this->get_upgrader( $assoc_args, $skin ); + /** + * @var ThemeUpgrader|PluginUpgrader $upgrader + */ + $upgrader = $this->get_upgrader( $assoc_args ); // Ensure the upgrader uses the download offer present in each item. $transient_filter = function ( $transient ) use ( $items_to_update ) { foreach ( $items_to_update as $name => $item_data ) { @@ -622,13 +610,9 @@ static function ( $result ) { } // Output changed files if requested. - if ( $show_changed_files && null !== $skin ) { - $changed_files = $skin->get_changed_files(); + if ( Utils\get_flag_value( $assoc_args, 'show-changed-files' ) ) { + $changed_files = $upgrader->get_changed_files(); if ( ! empty( $changed_files ) ) { - // Remove duplicates and sort files. - $changed_files = array_unique( $changed_files ); - sort( $changed_files ); - WP_CLI::log( '' ); WP_CLI::log( 'Changed files:' ); foreach ( $changed_files as $file ) { diff --git a/src/WP_CLI/DestructiveThemeUpgrader.php b/src/WP_CLI/DestructiveThemeUpgrader.php index 699d6dc0e..0d89af7a1 100644 --- a/src/WP_CLI/DestructiveThemeUpgrader.php +++ b/src/WP_CLI/DestructiveThemeUpgrader.php @@ -5,7 +5,7 @@ /** * A theme upgrader class that clears the destination directory. */ -class DestructiveThemeUpgrader extends \Theme_Upgrader { +class DestructiveThemeUpgrader extends ThemeUpgrader { public function install_package( $args = array() ) { parent::upgrade_strings(); // Needed for the 'remove_old' string. diff --git a/src/WP_CLI/ExtensionUpgraderSkin.php b/src/WP_CLI/ExtensionUpgraderSkin.php index d5873d049..cef43ad27 100644 --- a/src/WP_CLI/ExtensionUpgraderSkin.php +++ b/src/WP_CLI/ExtensionUpgraderSkin.php @@ -14,98 +14,6 @@ */ class ExtensionUpgraderSkin extends UpgraderSkin { - /** - * List of files that were changed during the update process. - * - * @var array - */ - private $changed_files = []; - - /** - * Whether to track changed files. - * - * @var bool - */ - private $track_files = false; - - /** - * Whether file tracking hooks have been set up. - * - * @var bool - */ - private $hooks_setup = false; - - /** - * Enable file tracking for opcache invalidation. - */ - public function enable_file_tracking() { - $this->track_files = true; - $this->setup_file_tracking_hooks(); - } - - /** - * Get the list of changed files. - * - * @return array List of file paths. - */ - public function get_changed_files() { - return $this->changed_files; - } - - /** - * Setup hooks to track file changes during upgrade. - */ - private function setup_file_tracking_hooks() { - // Prevent duplicate hook registrations. - if ( $this->hooks_setup ) { - return; - } - - $this->hooks_setup = true; - - // Hook into upgrader_post_install to capture the destination directory - add_filter( - 'upgrader_post_install', - function ( $response, $hook_extra, $result ) { - if ( $this->track_files && is_array( $result ) && isset( $result['destination'] ) && is_string( $result['destination'] ) ) { - $this->scan_directory_for_files( $result['destination'] ); - } - return $response; - }, - 10, - 3 - ); - } - - /** - * Recursively scan a directory and add all PHP files to the changed files list. - * - * @param string $dir Directory to scan. - */ - private function scan_directory_for_files( $dir ) { - if ( ! is_dir( $dir ) ) { - return; - } - - try { - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator( $dir, \RecursiveDirectoryIterator::SKIP_DOTS ), - \RecursiveIteratorIterator::SELF_FIRST - ); - - foreach ( $iterator as $file ) { - /** @var \SplFileInfo $file */ - if ( $file->isFile() && 'php' === $file->getExtension() ) { - $this->changed_files[] = $file->getPathname(); - } - } - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch -- Intentionally ignoring errors to prevent update failure. - } catch ( \Exception $e ) { - // Silently handle filesystem errors to prevent update process from failing. - // The changed files list may be incomplete, but the update should still succeed. - } - } - /** * Called before an update is performed. */ diff --git a/src/WP_CLI/PluginUpgrader.php b/src/WP_CLI/PluginUpgrader.php new file mode 100644 index 000000000..45fa3cf44 --- /dev/null +++ b/src/WP_CLI/PluginUpgrader.php @@ -0,0 +1,45 @@ + + */ + private $changed_files = []; + + public function install_package( $args = array() ) { + parent::upgrade_strings(); // Needed for the 'remove_old' string. + + $track_files = function ( $will_invalidate, $filepath ) { + $this->changed_files[] = $filepath; + return $will_invalidate; + }; + + add_filter( 'wp_opcache_invalidate_file', $track_files, 10, 2 ); + + $result = parent::install_package( $args ); + + remove_filter( 'wp_opcache_invalidate_file', $track_files ); + + // Remove duplicates and sort files. + $this->changed_files = array_unique( $this->changed_files ); + sort( $this->changed_files ); + + return $result; + } + + /** + * Returns a list of files that were changed during the update process. + * + * @return array Changed files. + */ + public function get_changed_files() { + return $this->changed_files; + } +} diff --git a/src/WP_CLI/ThemeUpgrader.php b/src/WP_CLI/ThemeUpgrader.php new file mode 100644 index 000000000..e4a1ac4ae --- /dev/null +++ b/src/WP_CLI/ThemeUpgrader.php @@ -0,0 +1,45 @@ + + */ + private $changed_files = []; + + public function install_package( $args = array() ) { + parent::upgrade_strings(); // Needed for the 'remove_old' string. + + $track_files = function ( $will_invalidate, $filepath ) { + $this->changed_files[] = $filepath; + return $will_invalidate; + }; + + add_filter( 'wp_opcache_invalidate_file', $track_files, 10, 2 ); + + $result = parent::install_package( $args ); + + remove_filter( 'wp_opcache_invalidate_file', $track_files ); + + // Remove duplicates and sort files. + $this->changed_files = array_unique( $this->changed_files ); + sort( $this->changed_files ); + + return $result; + } + + /** + * Returns a list of files that were changed during the update process. + * + * @return array Changed files. + */ + public function get_changed_files() { + return $this->changed_files; + } +}