Skip to content

Commit df3fc0c

Browse files
authored
Merge pull request #492 from wp-cli/copilot/add-plugin-update-info
Display extension names during bulk updates
2 parents 0acb676 + bb30a4f commit df3fc0c

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

features/plugin-update.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,25 @@ Feature: Update WordPress plugins
267267
"""
268268
Success: Updated 1 of 1 plugins (1 skipped).
269269
"""
270+
271+
@require-wp-5.2
272+
Scenario: Updating all plugins should show the name of each plugin as it is updated
273+
Given a WP install
274+
And I run `wp plugin delete akismet`
275+
276+
When I run `wp plugin install health-check --version=1.5.0`
277+
Then STDOUT should not be empty
278+
279+
When I run `wp plugin install wordpress-importer --version=0.5`
280+
Then STDOUT should not be empty
281+
282+
When I try `wp plugin update --all`
283+
Then STDOUT should contain:
284+
"""
285+
Updating Health Check & Troubleshooting...
286+
"""
287+
288+
And STDOUT should contain:
289+
"""
290+
Success: Updated 2 of 2 plugins.
291+
"""

features/theme-update.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,25 @@ Feature: Update WordPress themes
154154
"""
155155
1.1.1
156156
"""
157+
158+
@require-wp-4.5
159+
Scenario: Updating all themes should show the name of each theme as it is updated
160+
Given a WP install
161+
And I run `wp theme delete --all --force`
162+
163+
When I run `wp theme install moina --version=1.0.2`
164+
Then STDOUT should not be empty
165+
166+
When I run `wp theme install twentytwelve --version=1.0`
167+
Then STDOUT should not be empty
168+
169+
When I try `wp theme update --all`
170+
Then STDOUT should contain:
171+
"""
172+
Updating Moina...
173+
"""
174+
175+
And STDOUT should contain:
176+
"""
177+
Success: Updated 2 of 2 themes.
178+
"""

phpcs.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<exclude-pattern>*/src/WP_CLI/CommandWithUpgrade\.php$</exclude-pattern>
6262
<exclude-pattern>*/src/WP_CLI/(CommandWith|DestructivePlugin|DestructiveTheme)Upgrader\.php$</exclude-pattern>
6363
<exclude-pattern>*/src/WP_CLI/Parse(Plugin|Theme)NameInput\.php$</exclude-pattern>
64+
<exclude-pattern>*/src/WP_CLI/ExtensionUpgraderSkin\.php$</exclude-pattern>
6465
</rule>
6566

6667
<!-- Exclude classes from UselessOverridingMethod sniff as the method is used for generating docs. -->

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,14 @@ protected function get_upgrader( $assoc_args ) {
389389
$force = Utils\get_flag_value( $assoc_args, 'force', false );
390390
$insecure = Utils\get_flag_value( $assoc_args, 'insecure', false );
391391
$upgrader_class = $this->get_upgrader_class( $force );
392-
return Utils\get_upgrader( $upgrader_class, $insecure );
392+
393+
if ( ! class_exists( '\WP_Upgrader_Skin' ) ) {
394+
if ( file_exists( ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php' ) ) {
395+
include ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
396+
}
397+
}
398+
399+
return Utils\get_upgrader( $upgrader_class, $insecure, new ExtensionUpgraderSkin() );
393400
}
394401

395402
protected function update_many( $args, $assoc_args ) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace WP_CLI;
4+
5+
use WP_CLI;
6+
7+
/**
8+
* An Upgrader Skin for extensions (plugins/themes) that displays which item is being updated
9+
*
10+
* @package wp-cli
11+
*/
12+
class ExtensionUpgraderSkin extends UpgraderSkin {
13+
14+
/**
15+
* Called before an update is performed.
16+
*/
17+
public function before() {
18+
if ( isset( $this->plugin_info ) && is_array( $this->plugin_info ) && isset( $this->plugin_info['Name'] ) ) {
19+
WP_CLI::log( sprintf( 'Updating %s...', html_entity_decode( $this->plugin_info['Name'], ENT_QUOTES, get_bloginfo( 'charset' ) ) ) );
20+
} elseif ( isset( $this->theme_info ) && is_object( $this->theme_info ) && method_exists( $this->theme_info, 'get' ) ) {
21+
WP_CLI::log( sprintf( 'Updating %s...', html_entity_decode( $this->theme_info->get( 'Name' ), ENT_QUOTES, get_bloginfo( 'charset' ) ) ) );
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)