Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 87
Add hook to expose changed files for OPCache invalidation#501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
09314e692852e2b024949f6d816f94b42b8bbc3db7b0f85fae04f253ece98b3ae13d9cee75525a092d5648f2691File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; | ||
swissspidy marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| /** | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -782,6 +782,10 @@ function ( $item ) { | ||
| foreach ( $items_to_update as $item ) { | ||
| $cache_manager->whitelist_package( $item['update_package'], $this->item_type, $item['name'], $item['update_version'] ); | ||
| } | ||
| /** | ||
| * @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 ) { | ||
| @@ -806,6 +810,11 @@ function ( $item ) { | ||
| remove_filter( 'site_transient_' . $this->upgrade_transient, $transient_filter, 999 ); | ||
| } | ||
| if ( ! is_array( $result ) ) { | ||
| // This should never happen, but bulk_upgrade() can return false. | ||
| WP_CLI::error( 'Unable to connect to the filesystem.' ); | ||
| } | ||
| /** | ||
| * @var array $items_to_update | ||
| */ | ||
| @@ -859,6 +868,10 @@ static function ( $result ) { | ||
| if ( null !== $exclude ) { | ||
| WP_CLI::log( "Skipped updates for: $exclude" ); | ||
| } | ||
| if ( isset( $upgrader ) ) { | ||
| WP_CLI::do_hook( "{$this->item_type}_update_finished", $upgrader->get_changed_files() ); | ||
| } | ||
swissspidy marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Whitelisting to provide backward compatibility to classes possibly extending this class. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
| namespace WP_CLI; | ||
| /** | ||
| * A plugin upgrader class that tracks changed files. | ||
| */ | ||
| class PluginUpgrader extends \Plugin_Upgrader { | ||
| /** | ||
| * List of files that were changed during the update process. | ||
| * | ||
| * @var array<string> | ||
| */ | ||
| private $changed_files = []; | ||
| public function install_package( $args = array() ) { | ||
| $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; | ||
| } | ||
swissspidy marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Returns a list of files that were changed during the update process. | ||
| * | ||
| * @return array<string> Changed files. | ||
| */ | ||
| public function get_changed_files() { | ||
| return $this->changed_files; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
| namespace WP_CLI; | ||
| /** | ||
| * A theme upgrader class that tracks changed files. | ||
| */ | ||
| class ThemeUpgrader extends \Theme_Upgrader { | ||
| /** | ||
| * List of files that were changed during the update process. | ||
| * | ||
| * @var array<string> | ||
| */ | ||
| private $changed_files = []; | ||
| public function install_package( $args = array() ) { | ||
| $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; | ||
| } | ||
swissspidy marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Returns a list of files that were changed during the update process. | ||
| * | ||
| * @return array<string> Changed files. | ||
| */ | ||
| public function get_changed_files() { | ||
| return $this->changed_files; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.