From 95eee0d521358c1b6e365ee49381c22b9f8ab57b Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 17 Oct 2022 15:16:49 -0700 Subject: [PATCH 1/2] Avoid throwing error when excluding missing plugin --- features/plugin-activate.feature | 10 ++++++++++ features/plugin-deactivate.feature | 10 ++++++++++ features/plugin-delete.feature | 10 ++++++++++ features/plugin-uninstall.feature | 12 ++++++++++++ features/plugin-update.feature | 10 ++++++++++ features/theme.feature | 10 ++++++++++ src/WP_CLI/CommandWithUpgrade.php | 6 ++++++ 7 files changed, 68 insertions(+) diff --git a/features/plugin-activate.feature b/features/plugin-activate.feature index a2c32c2a7..ed3345534 100644 --- a/features/plugin-activate.feature +++ b/features/plugin-activate.feature @@ -115,3 +115,13 @@ Feature: Activate WordPress plugins Success: Activated 1 of 1 plugins. """ And the return code should be 0 + + Scenario: Excluding a missing plugin should not throw an error + Given a WP install + And I run `wp plugin activate --all --exclude=missing-plugin` + Then STDERR should be empty + And STDOUT should contain: + """ + Success: + """ + And the return code should be 0 diff --git a/features/plugin-deactivate.feature b/features/plugin-deactivate.feature index 5cbd8e0dc..7a6791101 100644 --- a/features/plugin-deactivate.feature +++ b/features/plugin-deactivate.feature @@ -94,3 +94,13 @@ Feature: Deactivate WordPress plugins Error: Please specify one or more plugins, or use --all. """ And STDOUT should be empty + + Scenario: Excluding a missing plugin should not throw an error + Given a WP install + And I run `wp plugin deactivate --all --exclude=missing-plugin` + Then STDERR should be empty + And STDOUT should contain: + """ + Success: + """ + And the return code should be 0 diff --git a/features/plugin-delete.feature b/features/plugin-delete.feature index 3ec4c4726..a0cdb822e 100644 --- a/features/plugin-delete.feature +++ b/features/plugin-delete.feature @@ -47,3 +47,13 @@ Feature: Delete WordPress plugins Success: No plugins deleted. """ And the return code should be 0 + + Scenario: Excluding a missing plugin should not throw an error + Given a WP install + And I run `wp plugin delete --all --exclude=missing-plugin` + Then STDERR should be empty + And STDOUT should contain: + """ + Success: + """ + And the return code should be 0 diff --git a/features/plugin-uninstall.feature b/features/plugin-uninstall.feature index 86ef9dbeb..e267507b7 100644 --- a/features/plugin-uninstall.feature +++ b/features/plugin-uninstall.feature @@ -79,3 +79,15 @@ Feature: Uninstall a WordPress plugin Success: No plugins uninstalled. """ And the return code should be 0 + + + + Scenario: Excluding a missing plugin should not throw an error + Given a WP install + And I run `wp plugin uninstall --all --exclude=missing-plugin` + Then STDERR should be empty + And STDOUT should contain: + """ + Success: + """ + And the return code should be 0 diff --git a/features/plugin-update.feature b/features/plugin-update.feature index 1a884135f..1aa586b73 100644 --- a/features/plugin-update.feature +++ b/features/plugin-update.feature @@ -218,3 +218,13 @@ Feature: Update WordPress plugins """ Success: """ + + Scenario: Excluding a missing plugin should not throw an error + Given a WP install + And I run `wp plugin update --all --exclude=missing-plugin` + Then STDERR should be empty + And STDOUT should contain: + """ + Success: + """ + And the return code should be 0 diff --git a/features/theme.feature b/features/theme.feature index 660452d5d..8473d66f5 100644 --- a/features/theme.feature +++ b/features/theme.feature @@ -673,3 +673,13 @@ Feature: Manage WordPress themes When I try `wp theme is-active p2` Then the return code should be 1 + + Scenario: Excluding a missing theme should not throw an error + Given a WP install + And I run `wp theme update --all --exclude=missing-theme` + Then STDERR should be empty + And STDOUT should contain: + """ + Success: + """ + And the return code should be 0 diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 27f4a3ec0..b95cf4f6d 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -360,9 +360,15 @@ protected function update_many( $args, $assoc_args ) { foreach ( $exclude_items as $item ) { if ( 'plugin' === $this->item_type ) { $plugin = $this->fetcher->get( $item ); + if ( ! $plugin ) { + continue; + } unset( $items_to_update[ $plugin->file ] ); } elseif ( 'theme' === $this->item_type ) { $theme_root = get_theme_root() . '/' . $item; + if ( ! is_dir( $theme_root ) ) { + continue; + } unset( $items_to_update[ $theme_root ] ); } } From 3bf93307cedbfc2e28a32fa4e8883362d09d5316 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 17 Oct 2022 15:38:49 -0700 Subject: [PATCH 2/2] Fix theme update test --- features/theme.feature | 2 ++ 1 file changed, 2 insertions(+) diff --git a/features/theme.feature b/features/theme.feature index 8473d66f5..470bed9c6 100644 --- a/features/theme.feature +++ b/features/theme.feature @@ -676,6 +676,8 @@ Feature: Manage WordPress themes Scenario: Excluding a missing theme should not throw an error Given a WP install + And I run `wp theme delete --all --force` + And I run `wp theme install p2 --version=1.5.5 --activate` And I run `wp theme update --all --exclude=missing-theme` Then STDERR should be empty And STDOUT should contain: