From 0ccc2870253a8798df89b894da6e629abf5f342f Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Wed, 15 Oct 2025 15:58:56 -0400 Subject: [PATCH 01/26] feat: add --all flag to comment delete command --- features/comment.feature | 77 ++++++++++++++++++++++++++++++++++++++++ src/Comment_Command.php | 73 +++++++++++++++++++++++++++++++++++-- 2 files changed, 148 insertions(+), 2 deletions(-) diff --git a/features/comment.feature b/features/comment.feature index 290954e0..71a23789 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -472,3 +472,80 @@ Feature: Manage WordPress comments And I run `wp comment unspam {COMMENT_ID} --url=www.example.com` And I run `wp comment trash {COMMENT_ID} --url=www.example.com` And I run `wp comment untrash {COMMENT_ID} --url=www.example.com` + + Scenario: Delete all comments with --all flag + Given a WP install + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 1' --porcelain` + And save STDOUT as {COMMENT_ID_1} + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 2' --porcelain` + And save STDOUT as {COMMENT_ID_2} + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 3' --porcelain` + And save STDOUT as {COMMENT_ID_3} + + When I run `wp comment list --format=count` + Then STDOUT should be: + """ + 4 + """ + + When I run `wp comment delete --all` + Then STDOUT should be: + """ + Success: Trashed comment 1. + Success: Trashed comment {COMMENT_ID_1}. + Success: Trashed comment {COMMENT_ID_2}. + Success: Trashed comment {COMMENT_ID_3}. + """ + + When I run `wp comment list --format=count` + Then STDOUT should be: + """ + 0 + """ + + Scenario: Delete all comments with --all flag and --force + Given a WP install + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 1' --porcelain` + And save STDOUT as {COMMENT_ID_1} + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 2' --porcelain` + And save STDOUT as {COMMENT_ID_2} + + When I run `wp comment list --format=count` + Then STDOUT should be: + """ + 3 + """ + + When I run `wp comment delete --all --force` + Then STDOUT should be: + """ + Success: Deleted comment 1. + Success: Deleted comment {COMMENT_ID_1}. + Success: Deleted comment {COMMENT_ID_2}. + """ + + When I run `wp comment list --format=count` + Then STDOUT should be: + """ + 0 + """ + + Scenario: Delete all comments when no comments exist + Given a WP install + And I run `wp comment delete $(wp comment list --field=ID) --force` + + When I run `wp comment delete --all` + Then STDOUT should be: + """ + Success: No comments deleted. + """ + + Scenario: Error when no comment IDs and no --all flag provided + Given a WP install + + When I try `wp comment delete` + Then STDERR should be: + """ + Error: Please specify one or more comment IDs, or use --all. + """ + And the return code should be 1 diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 766e28a5..2a7f01e5 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -16,7 +16,7 @@ * # Update an existing comment. * $ wp comment update 123 --comment_author='That Guy' * Success: Updated comment 123. - * + * # Delete an existing comment. * $ wp comment delete 1337 --force * Success: Deleted comment 1337. @@ -416,9 +416,12 @@ function ( $comment ) { * * ## OPTIONS * - * ... + * [...] * : One or more IDs of comments to delete. * + * [--all] + * : If set, all comments will be deleted. + * * [--force] * : Skip the trash bin. * @@ -432,8 +435,22 @@ function ( $comment ) { * $ wp comment delete 1337 2341 --force * Success: Deleted comment 1337. * Success: Deleted comment 2341. + * + * # Delete all comments. + * $ wp comment delete --all --force + * Success: Deleted comment 1337. + * Success: Deleted comment 2341. + * Success: Deleted 2 of 2 comments. */ public function delete( $args, $assoc_args ) { + $all = Utils\get_flag_value( $assoc_args, 'all', false ); + + // Check if comment IDs or --all is passed. + $args = $this->check_optional_args_and_all( $args, $all, 'delete' ); + if ( ! $args ) { + return; + } + parent::_delete( $args, $assoc_args, @@ -734,4 +751,56 @@ public function exists( $args ) { WP_CLI::success( "Comment with ID {$args[0]} exists." ); } } + + /** + * If have optional args ([...]) and an all option, then check have something to do. + * + * @param array $args Passed-in arguments. + * @param bool $all All flag. + * @param string $verb Optional. Verb to use. Defaults to 'delete'. + * @param string $exclude Comma separated list of comment IDs. + * @return array Same as $args if not all, otherwise all comment IDs. + * @throws ExitException If neither comment ID nor --all were provided. + */ + private function check_optional_args_and_all( $args, $all, $verb = 'delete', $exclude = null ) { + if ( $all ) { + $args = $this->get_all_comment_ids(); + } + + if ( $all && $exclude ) { + $exclude_list = array_map( 'intval', explode( ',', trim( $exclude, ',' ) ) ); + $args = array_filter( + $args, + static function ( $id ) use ( $exclude_list ) { + return ! in_array( (int) $id, $exclude_list, true ); + } + ); + } + + if ( empty( $args ) ) { + if ( ! $all ) { + WP_CLI::error( 'Please specify one or more comment IDs, or use --all.' ); + } + + $past_tense_verb = Utils\past_tense_verb( $verb ); + WP_CLI::success( "No comments {$past_tense_verb}." ); + } + + return $args; + } + + /** + * Gets all available comment IDs. + * + * @return array Array of comment IDs. + */ + private function get_all_comment_ids() { + $query = new WP_Comment_Query(); + $comments = $query->query( array( + 'fields' => 'ids', + 'number' => 0, // Get all comments + ) ); + + return $comments; + } } From be450396f7da97f5e545f19d41f5868afdb3e0f7 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Wed, 15 Oct 2025 16:01:45 -0400 Subject: [PATCH 02/26] fix: linting errors --- src/Comment_Command.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 2a7f01e5..d8b89af5 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -795,11 +795,13 @@ static function ( $id ) use ( $exclude_list ) { * @return array Array of comment IDs. */ private function get_all_comment_ids() { - $query = new WP_Comment_Query(); - $comments = $query->query( array( - 'fields' => 'ids', - 'number' => 0, // Get all comments - ) ); + $query = new WP_Comment_Query(); + $comments = $query->query( + array( + 'fields' => 'ids', + 'number' => 0, // Get all comments + ) + ); return $comments; } From 24f1c4c39551df839fa81d9efbf6f0907bbc57e2 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Wed, 15 Oct 2025 16:04:56 -0400 Subject: [PATCH 03/26] fix: phpstan issues --- src/Comment_Command.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index d8b89af5..f150bd87 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -791,10 +791,8 @@ static function ( $id ) use ( $exclude_list ) { /** * Gets all available comment IDs. - * - * @return array Array of comment IDs. */ - private function get_all_comment_ids() { + private function get_all_comment_ids(): array { $query = new WP_Comment_Query(); $comments = $query->query( array( From c4d8775048394dc3103b5503bb5306570c9606bf Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Wed, 15 Oct 2025 16:05:27 -0400 Subject: [PATCH 04/26] fix: phpstan issues --- src/Comment_Command.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index f150bd87..c95d5ae9 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -760,7 +760,6 @@ public function exists( $args ) { * @param string $verb Optional. Verb to use. Defaults to 'delete'. * @param string $exclude Comma separated list of comment IDs. * @return array Same as $args if not all, otherwise all comment IDs. - * @throws ExitException If neither comment ID nor --all were provided. */ private function check_optional_args_and_all( $args, $all, $verb = 'delete', $exclude = null ) { if ( $all ) { From ea5d3140e5760e22adc9d06d8c7c5bcfc07ab594 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Wed, 15 Oct 2025 16:07:30 -0400 Subject: [PATCH 05/26] fix: incorrect return type --- src/Comment_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index c95d5ae9..4d45ceb3 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -791,7 +791,7 @@ static function ( $id ) use ( $exclude_list ) { /** * Gets all available comment IDs. */ - private function get_all_comment_ids(): array { + private function get_all_comment_ids(): array|int { $query = new WP_Comment_Query(); $comments = $query->query( array( From 846b801c5a326767c014c22aca400422353920f4 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Wed, 15 Oct 2025 16:09:42 -0400 Subject: [PATCH 06/26] fix: always return array --- src/Comment_Command.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 4d45ceb3..99b60c82 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -791,7 +791,7 @@ static function ( $id ) use ( $exclude_list ) { /** * Gets all available comment IDs. */ - private function get_all_comment_ids(): array|int { + private function get_all_comment_ids(): array { $query = new WP_Comment_Query(); $comments = $query->query( array( @@ -800,6 +800,10 @@ private function get_all_comment_ids(): array|int { ) ); + if (!is_array($comments)) { + return []; + } + return $comments; } } From 6dbf62de90f01964769470a7dfe058b1a7cf102e Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Wed, 15 Oct 2025 16:10:41 -0400 Subject: [PATCH 07/26] fix: code style --- src/Comment_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 99b60c82..3793fd69 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -800,7 +800,7 @@ private function get_all_comment_ids(): array { ) ); - if (!is_array($comments)) { + if ( ! is_array( $comments ) ) { return []; } From e0f124b63820f7eb3e84cd7756a2ef6375febd1f Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Wed, 15 Oct 2025 16:20:24 -0400 Subject: [PATCH 08/26] fix: update test expectations to handle comment deletion order --- features/comment.feature | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/features/comment.feature b/features/comment.feature index 71a23789..c970e2c9 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -489,11 +489,20 @@ Feature: Manage WordPress comments """ When I run `wp comment delete --all` - Then STDOUT should be: + Then STDOUT should contain: """ Success: Trashed comment 1. + """ + And STDOUT should contain: + """ Success: Trashed comment {COMMENT_ID_1}. + """ + And STDOUT should contain: + """ Success: Trashed comment {COMMENT_ID_2}. + """ + And STDOUT should contain: + """ Success: Trashed comment {COMMENT_ID_3}. """ @@ -517,10 +526,16 @@ Feature: Manage WordPress comments """ When I run `wp comment delete --all --force` - Then STDOUT should be: + Then STDOUT should contain: """ Success: Deleted comment 1. + """ + And STDOUT should contain: + """ Success: Deleted comment {COMMENT_ID_1}. + """ + And STDOUT should contain: + """ Success: Deleted comment {COMMENT_ID_2}. """ From 000c83243813485a44b064c4585edcb02a695e3c Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Thu, 16 Oct 2025 01:46:45 -0400 Subject: [PATCH 09/26] fix: remove $exclude code --- src/Comment_Command.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 3793fd69..1e386aad 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -758,24 +758,13 @@ public function exists( $args ) { * @param array $args Passed-in arguments. * @param bool $all All flag. * @param string $verb Optional. Verb to use. Defaults to 'delete'. - * @param string $exclude Comma separated list of comment IDs. * @return array Same as $args if not all, otherwise all comment IDs. */ - private function check_optional_args_and_all( $args, $all, $verb = 'delete', $exclude = null ) { + private function check_optional_args_and_all( $args, $all, $verb = 'delete' ) { if ( $all ) { $args = $this->get_all_comment_ids(); } - if ( $all && $exclude ) { - $exclude_list = array_map( 'intval', explode( ',', trim( $exclude, ',' ) ) ); - $args = array_filter( - $args, - static function ( $id ) use ( $exclude_list ) { - return ! in_array( (int) $id, $exclude_list, true ); - } - ); - } - if ( empty( $args ) ) { if ( ! $all ) { WP_CLI::error( 'Please specify one or more comment IDs, or use --all.' ); From 860bb2b99e25060ead12c5e0f13d45379774f8f9 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 16:19:17 -0400 Subject: [PATCH 10/26] fix: defer comment counts --- src/Comment_Command.php | 57 +++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 1e386aad..fe16dffe 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -451,23 +451,54 @@ public function delete( $args, $assoc_args ) { return; } - parent::_delete( - $args, - $assoc_args, - function ( $comment_id, $assoc_args ) { - $force = (bool) Utils\get_flag_value( $assoc_args, 'force' ); + $defer_term_counting = Utils\get_flag_value( $assoc_args, 'defer-term-counting', false ); + + if ( $all && ! $defer_term_counting ) { + $assoc_args['defer-term-counting'] = true; + } - $status = wp_get_comment_status( $comment_id ); - $result = wp_delete_comment( $comment_id, $force ); + $status = 0; - if ( ! $result ) { - return [ 'error', "Failed deleting comment {$comment_id}." ]; - } + if ( $defer_term_counting ) { + wp_defer_term_counting( true ); + } - $verb = ( $force || 'trash' === $status ) ? 'Deleted' : 'Trashed'; - return [ 'success', "{$verb} comment {$comment_id}." ]; + $total = count( $args ); + $successfully_deleted = 0; + + $force = (bool) Utils\get_flag_value( $assoc_args, 'force' ); + + foreach ( $args as $comment_id ) { + + $comment_status = wp_get_comment_status( $comment_id ); + $result = wp_delete_comment( $comment_id, $force ); + + if ( ! $result ) { + $response = [ 'error', "Failed deleting comment {$comment_id}." ]; + } else { + $verb = ( $force || 'trash' === $comment_status ) ? 'Deleted' : 'Trashed'; + $response = [ 'success', "{$verb} comment {$comment_id}." ]; + ++$successfully_deleted; } - ); + + $status = $this->success_or_failure( $response ); + if ( $status ) { + ++$successfully_deleted; + } + } + + if ( $defer_term_counting ) { + wp_defer_term_counting( false ); + } + + if ( $status ) { + WP_CLI::success( "Deleted {$successfully_deleted} comments." ); + } else { + $error_count = $total - $successfully_deleted; + WP_CLI::error( "Failed deleting {$error_count} comments." ); + } + + exit( 0 === $status ? 0 : 1 ); } private function call( $args, $status, $success, $failure ) { From 3af6933b9599dfcb2df7b906874fb74999c656e7 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 16:24:11 -0400 Subject: [PATCH 11/26] fix: strict comparison on mixed --- src/Comment_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index fe16dffe..5baa36fd 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -498,7 +498,7 @@ public function delete( $args, $assoc_args ) { WP_CLI::error( "Failed deleting {$error_count} comments." ); } - exit( 0 === $status ? 0 : 1 ); + exit( 0 == $status ? 0 : 1 ); } private function call( $args, $status, $success, $failure ) { From 3c9ea3c863de7c7495ced13e3eb542a2cf9796ea Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 16:33:18 -0400 Subject: [PATCH 12/26] fix: strict comparison on mixed --- src/Comment_Command.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 5baa36fd..d589883b 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -498,7 +498,11 @@ public function delete( $args, $assoc_args ) { WP_CLI::error( "Failed deleting {$error_count} comments." ); } - exit( 0 == $status ? 0 : 1 ); + if ( $status ) { + exit( 0 ); + } else { + exit( 1 ); + } } private function call( $args, $status, $success, $failure ) { From 95e7211612ea1e30c7d3ccd4b36e8f2feb5717a7 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 16:41:50 -0400 Subject: [PATCH 13/26] fix: phpcs comparison --- src/Comment_Command.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index d589883b..8b604feb 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -475,14 +475,12 @@ public function delete( $args, $assoc_args ) { if ( ! $result ) { $response = [ 'error', "Failed deleting comment {$comment_id}." ]; + $status = $this->success_or_failure( $response ); + // Keep status as 1 (error) if any deletion fails } else { $verb = ( $force || 'trash' === $comment_status ) ? 'Deleted' : 'Trashed'; $response = [ 'success', "{$verb} comment {$comment_id}." ]; - ++$successfully_deleted; - } - - $status = $this->success_or_failure( $response ); - if ( $status ) { + $this->success_or_failure( $response ); ++$successfully_deleted; } } @@ -491,18 +489,14 @@ public function delete( $args, $assoc_args ) { wp_defer_term_counting( false ); } - if ( $status ) { + if ( 0 === $status ) { WP_CLI::success( "Deleted {$successfully_deleted} comments." ); } else { $error_count = $total - $successfully_deleted; WP_CLI::error( "Failed deleting {$error_count} comments." ); } - if ( $status ) { - exit( 0 ); - } else { - exit( 1 ); - } + exit( $status ); } private function call( $args, $status, $success, $failure ) { From 1e396e856f7aa1b674cc14bdb62241fd12779f0c Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 16:55:46 -0400 Subject: [PATCH 14/26] fix: behat tests. Add checks for multiple success lines --- features/comment.feature | 27 +++++++++++++++++++++++++++ src/Comment_Command.php | 4 +++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/features/comment.feature b/features/comment.feature index c970e2c9..dc6256f9 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -555,6 +555,33 @@ Feature: Manage WordPress comments Success: No comments deleted. """ + Scenario: Delete multiple comments shows summary message + Given a WP install + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 1' --porcelain` + And save STDOUT as {COMMENT_ID_1} + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 2' --porcelain` + And save STDOUT as {COMMENT_ID_2} + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 3' --porcelain` + And save STDOUT as {COMMENT_ID_3} + + When I run `wp comment delete {COMMENT_ID_1} {COMMENT_ID_2} {COMMENT_ID_3}` + Then STDOUT should contain: + """ + Success: Trashed comment {COMMENT_ID_1}. + """ + And STDOUT should contain: + """ + Success: Trashed comment {COMMENT_ID_2}. + """ + And STDOUT should contain: + """ + Success: Trashed comment {COMMENT_ID_3}. + """ + And STDOUT should contain: + """ + Success: Deleted 3 comments. + """ + Scenario: Error when no comment IDs and no --all flag provided Given a WP install diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 8b604feb..99e69da1 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -490,7 +490,9 @@ public function delete( $args, $assoc_args ) { } if ( 0 === $status ) { - WP_CLI::success( "Deleted {$successfully_deleted} comments." ); + if ( $total > 1 ) { + WP_CLI::success( "Deleted {$successfully_deleted} comments." ); + } } else { $error_count = $total - $successfully_deleted; WP_CLI::error( "Failed deleting {$error_count} comments." ); From a7849ca429de5fce309a13d180c2c375f2ff19e9 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 17:05:39 -0400 Subject: [PATCH 15/26] fix: behat tests. Add checks for multiple success lines --- features/comment.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/features/comment.feature b/features/comment.feature index dc6256f9..4ffbb525 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -55,6 +55,7 @@ Feature: Manage WordPress comments """ Success: Trashed comment 3. Success: Trashed comment 4. + Success: Deleted 2 comments. """ When I run `wp comment delete 3` From 669caaeb5f324b04b2ba22830e46502886824358 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 19:42:35 -0400 Subject: [PATCH 16/26] test: Delete comments with explicit defer-term-counting flag --- features/comment.feature | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/features/comment.feature b/features/comment.feature index 4ffbb525..cb36a6bd 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -583,6 +583,27 @@ Feature: Manage WordPress comments Success: Deleted 3 comments. """ + Scenario: Delete comments with explicit defer-term-counting flag + Given a WP install + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 1' --porcelain` + And save STDOUT as {COMMENT_ID_1} + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 2' --porcelain` + And save STDOUT as {COMMENT_ID_2} + + When I run `wp comment delete {COMMENT_ID_1} {COMMENT_ID_2} --defer-term-counting` + Then STDOUT should contain: + """ + Success: Trashed comment {COMMENT_ID_1}. + """ + And STDOUT should contain: + """ + Success: Trashed comment {COMMENT_ID_2}. + """ + And STDOUT should contain: + """ + Success: Deleted 2 comments. + """ + Scenario: Error when no comment IDs and no --all flag provided Given a WP install From 8a3df5b4fa73b6745527e815051a1a561379a137 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 19:46:24 -0400 Subject: [PATCH 17/26] test: Success/Error returns --- features/comment.feature | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/features/comment.feature b/features/comment.feature index cb36a6bd..ee649ec4 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -604,6 +604,32 @@ Feature: Manage WordPress comments Success: Deleted 2 comments. """ + Scenario: Delete comments with mixed success and failure + Given a WP install + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 1' --porcelain` + And save STDOUT as {COMMENT_ID_1} + And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 2' --porcelain` + And save STDOUT as {COMMENT_ID_2} + + When I run `wp comment delete {COMMENT_ID_1} {COMMENT_ID_2} 99999` + Then STDOUT should contain: + """ + Success: Trashed comment {COMMENT_ID_1}. + """ + And STDOUT should contain: + """ + Success: Trashed comment {COMMENT_ID_2}. + """ + And STDERR should contain: + """ + Warning: Failed deleting comment 99999. + """ + And STDERR should contain: + """ + Error: Failed deleting 1 comments. + """ + And the return code should be 1 + Scenario: Error when no comment IDs and no --all flag provided Given a WP install From db908895849b57b3d7e690ff037c93e1041b40a9 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 20:04:37 -0400 Subject: [PATCH 18/26] fix: remove --defer-comment-count flag, not referenced in coommand def --- features/comment.feature | 21 --------------------- src/Comment_Command.php | 13 ++++--------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/features/comment.feature b/features/comment.feature index ee649ec4..4806463f 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -583,27 +583,6 @@ Feature: Manage WordPress comments Success: Deleted 3 comments. """ - Scenario: Delete comments with explicit defer-term-counting flag - Given a WP install - And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 1' --porcelain` - And save STDOUT as {COMMENT_ID_1} - And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 2' --porcelain` - And save STDOUT as {COMMENT_ID_2} - - When I run `wp comment delete {COMMENT_ID_1} {COMMENT_ID_2} --defer-term-counting` - Then STDOUT should contain: - """ - Success: Trashed comment {COMMENT_ID_1}. - """ - And STDOUT should contain: - """ - Success: Trashed comment {COMMENT_ID_2}. - """ - And STDOUT should contain: - """ - Success: Deleted 2 comments. - """ - Scenario: Delete comments with mixed success and failure Given a WP install And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 1' --porcelain` diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 99e69da1..6806ed06 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -451,15 +451,10 @@ public function delete( $args, $assoc_args ) { return; } - $defer_term_counting = Utils\get_flag_value( $assoc_args, 'defer-term-counting', false ); - - if ( $all && ! $defer_term_counting ) { - $assoc_args['defer-term-counting'] = true; - } - $status = 0; - if ( $defer_term_counting ) { + $defer_term_counting = wp_defer_comment_counting(); + if ( $all ) { wp_defer_term_counting( true ); } @@ -485,8 +480,8 @@ public function delete( $args, $assoc_args ) { } } - if ( $defer_term_counting ) { - wp_defer_term_counting( false ); + if ( $all ) { + wp_defer_term_counting( $defer_term_counting ); } if ( 0 === $status ) { From 1c8144ceb8249d48a51ab02b619be103e0c26bf3 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 20:23:46 -0400 Subject: [PATCH 19/26] test: return to STDERR --- features/comment.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/comment.feature b/features/comment.feature index 4806463f..3a950c74 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -603,7 +603,7 @@ Feature: Manage WordPress comments """ Warning: Failed deleting comment 99999. """ - And STDERR should contain: + And STDOUT should contain: """ Error: Failed deleting 1 comments. """ From 37c0ba617959fe07f113357b71941baf7d0aa1ef Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 20:37:51 -0400 Subject: [PATCH 20/26] test: combined success/warning output to STDOUT --- features/comment.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/comment.feature b/features/comment.feature index 3a950c74..d7111e84 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -599,7 +599,7 @@ Feature: Manage WordPress comments """ Success: Trashed comment {COMMENT_ID_2}. """ - And STDERR should contain: + And STDOUT should contain: """ Warning: Failed deleting comment 99999. """ From 61f74b6bada8df1e600a0b9cbb0f918bf025ec10 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 20:49:05 -0400 Subject: [PATCH 21/26] test: trying to get combined success/fail ouput --- features/comment.feature | 9 --------- 1 file changed, 9 deletions(-) diff --git a/features/comment.feature b/features/comment.feature index d7111e84..b6530416 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -594,17 +594,8 @@ Feature: Manage WordPress comments Then STDOUT should contain: """ Success: Trashed comment {COMMENT_ID_1}. - """ - And STDOUT should contain: - """ Success: Trashed comment {COMMENT_ID_2}. - """ - And STDOUT should contain: - """ Warning: Failed deleting comment 99999. - """ - And STDOUT should contain: - """ Error: Failed deleting 1 comments. """ And the return code should be 1 From d33e0b8da1b5c14b0d8553f507d21007ecdbb050 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 21:08:38 -0400 Subject: [PATCH 22/26] test: add blank line to return --- features/comment.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/features/comment.feature b/features/comment.feature index b6530416..d681103d 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -595,6 +595,7 @@ Feature: Manage WordPress comments """ Success: Trashed comment {COMMENT_ID_1}. Success: Trashed comment {COMMENT_ID_2}. + Warning: Failed deleting comment 99999. Error: Failed deleting 1 comments. """ From fc0e2a20f9d375f2b223b20793ebfe58ff4f2040 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 21:25:24 -0400 Subject: [PATCH 23/26] test: could it be STDERR, now that we have the foramtting fixed? --- features/comment.feature | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/features/comment.feature b/features/comment.feature index d681103d..cb6f9df2 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -591,11 +591,13 @@ Feature: Manage WordPress comments And save STDOUT as {COMMENT_ID_2} When I run `wp comment delete {COMMENT_ID_1} {COMMENT_ID_2} 99999` - Then STDOUT should contain: + Then STDOUT should be: """ Success: Trashed comment {COMMENT_ID_1}. Success: Trashed comment {COMMENT_ID_2}. - + """ + And STDERR should be: + """ Warning: Failed deleting comment 99999. Error: Failed deleting 1 comments. """ From fb2d6bec8304306010d434e7079e9323465658fb Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 21:39:02 -0400 Subject: [PATCH 24/26] test: Separates STDOUT and STDERR --- features/comment.feature | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/features/comment.feature b/features/comment.feature index cb6f9df2..4806463f 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -591,14 +591,20 @@ Feature: Manage WordPress comments And save STDOUT as {COMMENT_ID_2} When I run `wp comment delete {COMMENT_ID_1} {COMMENT_ID_2} 99999` - Then STDOUT should be: + Then STDOUT should contain: """ Success: Trashed comment {COMMENT_ID_1}. + """ + And STDOUT should contain: + """ Success: Trashed comment {COMMENT_ID_2}. """ - And STDERR should be: + And STDERR should contain: """ Warning: Failed deleting comment 99999. + """ + And STDERR should contain: + """ Error: Failed deleting 1 comments. """ And the return code should be 1 From d0dd60a2d7c0d0f8a7ea5e1bf41d5c7bb2090308 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 22:44:31 -0400 Subject: [PATCH 25/26] Last try on STDOUT --- features/comment.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/comment.feature b/features/comment.feature index 4806463f..d7111e84 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -599,11 +599,11 @@ Feature: Manage WordPress comments """ Success: Trashed comment {COMMENT_ID_2}. """ - And STDERR should contain: + And STDOUT should contain: """ Warning: Failed deleting comment 99999. """ - And STDERR should contain: + And STDOUT should contain: """ Error: Failed deleting 1 comments. """ From a8bdff2bd9c812516a314530d5568b297e689078 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Mon, 20 Oct 2025 23:33:27 -0400 Subject: [PATCH 26/26] test: ah, the problem was I try vs I run --- features/comment.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/comment.feature b/features/comment.feature index d7111e84..a1cc7c0b 100644 --- a/features/comment.feature +++ b/features/comment.feature @@ -590,7 +590,7 @@ Feature: Manage WordPress comments And I run `wp comment create --comment_post_ID=1 --comment_content='Comment 2' --porcelain` And save STDOUT as {COMMENT_ID_2} - When I run `wp comment delete {COMMENT_ID_1} {COMMENT_ID_2} 99999` + When I try `wp comment delete {COMMENT_ID_1} {COMMENT_ID_2} 99999` Then STDOUT should contain: """ Success: Trashed comment {COMMENT_ID_1}. @@ -599,11 +599,11 @@ Feature: Manage WordPress comments """ Success: Trashed comment {COMMENT_ID_2}. """ - And STDOUT should contain: + And STDERR should contain: """ Warning: Failed deleting comment 99999. """ - And STDOUT should contain: + And STDERR should contain: """ Error: Failed deleting 1 comments. """