Skip to content

Commit c3f3f84

Browse files
authored
Merge pull request #332 from wp-cli/fix/330-exclude-missing-plugin
Avoid throwing error when excluding missing plugin
2 parents 2981c34 + 3bf9330 commit c3f3f84

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed

features/plugin-activate.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,13 @@ Feature: Activate WordPress plugins
115115
Success: Activated 1 of 1 plugins.
116116
"""
117117
And the return code should be 0
118+
119+
Scenario: Excluding a missing plugin should not throw an error
120+
Given a WP install
121+
And I run `wp plugin activate --all --exclude=missing-plugin`
122+
Then STDERR should be empty
123+
And STDOUT should contain:
124+
"""
125+
Success:
126+
"""
127+
And the return code should be 0

features/plugin-deactivate.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,13 @@ Feature: Deactivate WordPress plugins
9494
Error: Please specify one or more plugins, or use --all.
9595
"""
9696
And STDOUT should be empty
97+
98+
Scenario: Excluding a missing plugin should not throw an error
99+
Given a WP install
100+
And I run `wp plugin deactivate --all --exclude=missing-plugin`
101+
Then STDERR should be empty
102+
And STDOUT should contain:
103+
"""
104+
Success:
105+
"""
106+
And the return code should be 0

features/plugin-delete.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,13 @@ Feature: Delete WordPress plugins
4747
Success: No plugins deleted.
4848
"""
4949
And the return code should be 0
50+
51+
Scenario: Excluding a missing plugin should not throw an error
52+
Given a WP install
53+
And I run `wp plugin delete --all --exclude=missing-plugin`
54+
Then STDERR should be empty
55+
And STDOUT should contain:
56+
"""
57+
Success:
58+
"""
59+
And the return code should be 0

features/plugin-uninstall.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@ Feature: Uninstall a WordPress plugin
7979
Success: No plugins uninstalled.
8080
"""
8181
And the return code should be 0
82+
83+
84+
85+
Scenario: Excluding a missing plugin should not throw an error
86+
Given a WP install
87+
And I run `wp plugin uninstall --all --exclude=missing-plugin`
88+
Then STDERR should be empty
89+
And STDOUT should contain:
90+
"""
91+
Success:
92+
"""
93+
And the return code should be 0

features/plugin-update.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,13 @@ Feature: Update WordPress plugins
218218
"""
219219
Success:
220220
"""
221+
222+
Scenario: Excluding a missing plugin should not throw an error
223+
Given a WP install
224+
And I run `wp plugin update --all --exclude=missing-plugin`
225+
Then STDERR should be empty
226+
And STDOUT should contain:
227+
"""
228+
Success:
229+
"""
230+
And the return code should be 0

features/theme.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,3 +673,15 @@ Feature: Manage WordPress themes
673673

674674
When I try `wp theme is-active p2`
675675
Then the return code should be 1
676+
677+
Scenario: Excluding a missing theme should not throw an error
678+
Given a WP install
679+
And I run `wp theme delete --all --force`
680+
And I run `wp theme install p2 --version=1.5.5 --activate`
681+
And I run `wp theme update --all --exclude=missing-theme`
682+
Then STDERR should be empty
683+
And STDOUT should contain:
684+
"""
685+
Success:
686+
"""
687+
And the return code should be 0

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,15 @@ protected function update_many( $args, $assoc_args ) {
360360
foreach ( $exclude_items as $item ) {
361361
if ( 'plugin' === $this->item_type ) {
362362
$plugin = $this->fetcher->get( $item );
363+
if ( ! $plugin ) {
364+
continue;
365+
}
363366
unset( $items_to_update[ $plugin->file ] );
364367
} elseif ( 'theme' === $this->item_type ) {
365368
$theme_root = get_theme_root() . '/' . $item;
369+
if ( ! is_dir( $theme_root ) ) {
370+
continue;
371+
}
366372
unset( $items_to_update[ $theme_root ] );
367373
}
368374
}

0 commit comments

Comments
 (0)