From bf99cd21771b3f32554b3e1ce7329b912f099304 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 9 Nov 2022 11:43:21 -0700 Subject: [PATCH 1/7] Report that plugins were skipped --- src/WP_CLI/CommandWithUpgrade.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index b95cf4f6d..0a8c11951 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -335,6 +335,7 @@ protected function update_many( $args, $assoc_args ) { $items = $this->get_item_list(); $errors = 0; + $skipped = 0; if ( ! Utils\get_flag_value( $assoc_args, 'all' ) ) { $items = $this->filter_item_list( $items, $args ); $errors = count( $args ) - count( $items ); @@ -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 ] ); } } @@ -478,7 +479,7 @@ 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 ); + 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" ); } From f237a13833390162840251b1d7787e2f193d74a0 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 9 Nov 2022 12:47:57 -0700 Subject: [PATCH 2/7] Add behat test --- features/plugin-update.feature | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/features/plugin-update.feature b/features/plugin-update.feature index 1aa586b73..bf4d891d2 100644 --- a/features/plugin-update.feature +++ b/features/plugin-update.feature @@ -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). + """ From 4fcdfce7a520b4a7f17fb59843e1831a4fa8222c Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 9 Nov 2022 12:52:55 -0700 Subject: [PATCH 3/7] phpcs --- src/WP_CLI/CommandWithUpgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 0a8c11951..923d60467 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -334,7 +334,7 @@ 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 ); From 3a4494a347506567905ab2d8e59ee25f417012aa Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 9 Nov 2022 14:51:30 -0700 Subject: [PATCH 4/7] Try and fix sed execution --- features/plugin-update.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/plugin-update.feature b/features/plugin-update.feature index bf4d891d2..fc7920fdf 100644 --- a/features/plugin-update.feature +++ b/features/plugin-update.feature @@ -239,7 +239,7 @@ Feature: Update WordPress plugins 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)` + When I run `sed -ibak 's/Version: .*/Version: 10000/' $(wp plugin path health-check)` Then STDOUT should be empty And the return code should be 0 From 62ea4f54636535bdae39b3620ae4af96b5e616e8 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 9 Nov 2022 16:07:29 -0700 Subject: [PATCH 5/7] Update tests for bf99cd21771b3f32554b3e1ce7329b912f099304 --- features/plugin.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/plugin.feature b/features/plugin.feature index 16016547a..e1a1a90da 100644 --- a/features/plugin.feature +++ b/features/plugin.feature @@ -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 @@ -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 From 350560c38718d41a38d26cfb2f3c530150256e42 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 9 Nov 2022 16:09:38 -0700 Subject: [PATCH 6/7] Fix tests --- features/plugin-update.feature | 2 +- src/WP_CLI/CommandWithUpgrade.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/features/plugin-update.feature b/features/plugin-update.feature index fc7920fdf..1cdc163df 100644 --- a/features/plugin-update.feature +++ b/features/plugin-update.feature @@ -239,7 +239,7 @@ Feature: Update WordPress plugins When I run `wp plugin install wordpress-importer --version=0.5` Then STDOUT should not be empty - When I run `sed -ibak 's/Version: .*/Version: 10000/' $(wp plugin path health-check)` + 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 diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 923d60467..d7629ad1d 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -479,6 +479,10 @@ static function ( $result ) { } $total_updated = Utils\get_flag_value( $assoc_args, 'all' ) ? $num_to_update : count( $args ); + 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" ); From 5c135354211a9b249e5159a59c5b8dcba3b5676c Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 9 Nov 2022 16:13:05 -0700 Subject: [PATCH 7/7] phpcs --- src/WP_CLI/CommandWithUpgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index d7629ad1d..c3423f0ec 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -480,7 +480,7 @@ static function ( $result ) { $total_updated = Utils\get_flag_value( $assoc_args, 'all' ) ? $num_to_update : count( $args ); if ( 0 === $num_updated && $skipped ) { - $errors = $skipped; + $errors = $skipped; $skipped = null; } Utils\report_batch_operation_results( $this->item_type, 'update', $total_updated, $num_updated, $errors, $skipped );