Skip to content
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

Don't report an error when 5 out of 5 plugins were updated #338

Merged
merged 7 commits into from Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions features/plugin-update.feature
Expand Up @@ -228,3 +228,33 @@ Feature: Update WordPress plugins
Success:
"""
And the return code should be 0


Scenario: Updating all plugins with some of them having an invalid version shouldn't report an error
Given a WP install

When I run `wp plugin install health-check --version=1.5.0`
Then STDOUT should not be empty

When I run `wp plugin install wordpress-importer --version=0.5`
Then STDOUT should not be empty

When I run `sed -i.bak 's/Version: .*/Version: 10000/' $(wp plugin path health-check)`
Then STDOUT should be empty
And the return code should be 0

When I try `wp plugin update --all`
Then STDERR should contain:
"""
Warning: health-check: version higher than expected.
"""

And STDOUT should not contain:
"""
Error: Only updated 1 of 1 plugins.
"""

And STDOUT should contain:
"""
Success: Updated 1 of 1 plugins (1 skipped).
"""
4 changes: 2 additions & 2 deletions features/plugin.feature
Expand Up @@ -159,7 +159,7 @@ Feature: Manage WordPress plugins
"""
And STDERR should contain:
"""
Error: No plugins updated.
Error: No plugins updated (2 failed).
"""
And the return code should be 1

Expand All @@ -177,7 +177,7 @@ Feature: Manage WordPress plugins
"""
And STDERR should contain:
"""
Error: Only updated 1 of 3 plugins.
Error: Only updated 1 of 3 plugins (2 failed).
"""
And the return code should be 1

Expand Down
11 changes: 8 additions & 3 deletions src/WP_CLI/CommandWithUpgrade.php
Expand Up @@ -334,7 +334,8 @@ protected function update_many( $args, $assoc_args ) {

$items = $this->get_item_list();

$errors = 0;
$errors = 0;
$skipped = 0;
if ( ! Utils\get_flag_value( $assoc_args, 'all' ) ) {
$items = $this->filter_item_list( $items, $args );
$errors = count( $args ) - count( $items );
Expand Down Expand Up @@ -378,7 +379,7 @@ protected function update_many( $args, $assoc_args ) {
foreach ( $items_to_update as $item_key => $item_info ) {
if ( static::INVALID_VERSION_MESSAGE === $item_info['update'] ) {
WP_CLI::warning( "{$item_info['name']}: " . static::INVALID_VERSION_MESSAGE . '.' );
$errors++;
$skipped++;
unset( $items_to_update[ $item_key ] );
}
}
Expand Down Expand Up @@ -478,7 +479,11 @@ static function ( $result ) {
}

$total_updated = Utils\get_flag_value( $assoc_args, 'all' ) ? $num_to_update : count( $args );
Utils\report_batch_operation_results( $this->item_type, 'update', $total_updated, $num_updated, $errors );
if ( 0 === $num_updated && $skipped ) {
$errors = $skipped;
$skipped = null;
}
Utils\report_batch_operation_results( $this->item_type, 'update', $total_updated, $num_updated, $errors, $skipped );
if ( null !== $exclude ) {
WP_CLI::log( "Skipped updates for: $exclude" );
}
Expand Down