Skip to content
Open
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
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound">
<exclude-pattern>*/src/WP_CLI/Fetchers/(Plugin|Theme)\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_CLI/CommandWithUpgrade\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_CLI/(CommandWith|DestructivePlugin|DestructiveTheme)Upgrader\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_CLI/(CommandWith|DestructivePlugin|DestructiveTheme|Plugin|Theme)Upgrader\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_CLI/Parse(Plugin|Theme)NameInput\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_CLI/ExtensionUpgraderSkin\.php$</exclude-pattern>
</rule>
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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
*/
Expand Down Expand Up @@ -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() );
}
}

// phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Whitelisting to provide backward compatibility to classes possibly extending this class.
Expand Down
2 changes: 1 addition & 1 deletion src/WP_CLI/DestructivePluginUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* A plugin upgrader class that clears the destination directory.
*/
class DestructivePluginUpgrader extends \Plugin_Upgrader {
class DestructivePluginUpgrader extends PluginUpgrader {

public function install_package( $args = array() ) {
parent::upgrade_strings(); // Needed for the 'remove_old' string.
Expand Down
2 changes: 1 addition & 1 deletion src/WP_CLI/DestructiveThemeUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 43 additions & 0 deletions src/WP_CLI/PluginUpgrader.php
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;
}

/**
* 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;
}
}
43 changes: 43 additions & 0 deletions src/WP_CLI/ThemeUpgrader.php
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;
}

/**
* 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;
}
}