Skip to content

Commit

Permalink
Warn on delete failure, instead of hard exiting (#376)
Browse files Browse the repository at this point in the history
* Warn on delete failure, instead of hard exiting

* Add tests for e166709

* Newline at the end of the file

Co-authored-by: Pascal Birchler <[email protected]>

---------

Co-authored-by: Pascal Birchler <[email protected]>
  • Loading branch information
danielbachhuber and swissspidy authored Oct 11, 2023
1 parent 17b1654 commit 1fe271c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
29 changes: 29 additions & 0 deletions features/plugin-delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,32 @@ Feature: Delete WordPress plugins
Success:
"""
And the return code should be 0

Scenario: Reports a failure for a plugin that can't be deleted
Given a WP install

When I run `chmod -w wp-content/plugins/akismet`
And I try `wp plugin delete akismet`
Then STDERR should contain:
"""
Warning: The 'akismet' plugin could not be deleted.
"""
And STDERR should contain:
"""
Error: No plugins deleted.
"""
Then STDOUT should not contain:
"""
Success:
"""

When I run `chmod +w wp-content/plugins/akismet`
And I run `wp plugin delete akismet`
Then STDERR should not contain:
"""
Error:
"""
Then STDOUT should contain:
"""
Success:
"""
3 changes: 2 additions & 1 deletion src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ public function delete( $args, $assoc_args = array() ) {
WP_CLI::log( "Deleted '{$plugin->name}' plugin." );
++$successes;
} else {
WP_CLI::warning( "The '{$plugin->name}' plugin could not be deleted." );
++$errors;
}
}
Expand Down Expand Up @@ -1297,6 +1298,6 @@ private function delete_plugin( $plugin ) {
$command = 'rm -rf ';
}

return ! WP_CLI::launch( $command . escapeshellarg( $path ) );
return ! WP_CLI::launch( $command . escapeshellarg( $path ), false );
}
}

0 comments on commit 1fe271c

Please sign in to comment.