Skip to content

Commit edbfb7b

Browse files
ekamranswissspidy
andauthored
Keep failed update output parseable for JSON and CSV (#529)
Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent 13ed432 commit edbfb7b

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

features/plugin-update.feature

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,37 @@ Feature: Update WordPress plugins
380380
Success: Updated 2 of 2 plugins.
381381
"""
382382

383+
@require-wp-5.2 @skip-windows
384+
Scenario: Failed plugin update keeps JSON output parseable
385+
Given a WP install
386+
And I run `wp plugin install wordpress-importer --version=0.5 --force`
387+
And I run `chmod -w wp-content/plugins/wordpress-importer`
388+
389+
When I try `wp plugin update wordpress-importer --format=json`
390+
Then STDOUT should be JSON containing:
391+
"""
392+
[{"name":"wordpress-importer","old_version":"0.5","status":"Error"}]
393+
"""
394+
And STDERR should be empty
395+
And the return code should be 1
396+
397+
When I run `chmod +w wp-content/plugins/wordpress-importer`
398+
399+
@require-wp-5.2 @skip-windows
400+
Scenario: Failed plugin update keeps CSV output parseable
401+
Given a WP install
402+
And I run `wp plugin install wordpress-importer --version=0.5 --force`
403+
And I run `chmod -w wp-content/plugins/wordpress-importer`
404+
405+
When I try `wp plugin update wordpress-importer --format=csv`
406+
Then STDOUT should be CSV containing:
407+
| name | old_version | status |
408+
| wordpress-importer | 0.5 | Error |
409+
And STDERR should be empty
410+
And the return code should be 1
411+
412+
When I run `chmod +w wp-content/plugins/wordpress-importer`
413+
383414
# Skipped on Windows because of mkdir usage that would need to be refactored for compatibility.
384415
@require-wp-5.2 @skip-windows
385416
Scenario: Skip plugin update when plugin directory is a VCS checkout

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ static function ( $result ) {
880880
$errors = $skipped;
881881
$skipped = null;
882882
}
883+
if ( ! empty( $assoc_args['format'] ) && in_array( $assoc_args['format'], [ 'json', 'csv' ], true ) && $errors ) {
884+
WP_CLI::halt( 1 );
885+
}
883886
Utils\report_batch_operation_results( $this->item_type, 'update', $total_updated, $num_updated, $errors, $skipped );
884887
if ( null !== $exclude ) {
885888
WP_CLI::log( "Skipped updates for: $exclude" );

0 commit comments

Comments
 (0)