From 1fe271c5ebb1815732a8cf6bb6979c9261ee6375 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 11 Oct 2023 07:55:49 -0700 Subject: [PATCH] Warn on delete failure, instead of hard exiting (#376) * Warn on delete failure, instead of hard exiting * Add tests for e1667099ed1545e10048dc837a50b50478b9a119 * Newline at the end of the file Co-authored-by: Pascal Birchler --------- Co-authored-by: Pascal Birchler --- features/plugin-delete.feature | 29 +++++++++++++++++++++++++++++ src/Plugin_Command.php | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/features/plugin-delete.feature b/features/plugin-delete.feature index a0cdb822..8fc3cc9d 100644 --- a/features/plugin-delete.feature +++ b/features/plugin-delete.feature @@ -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: + """ diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 97dcd37c..7461b1fb 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -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; } } @@ -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 ); } }