From c18e28610e43d51ca512bbcfd7b76082cbc74051 Mon Sep 17 00:00:00 2001 From: Victor Boctor Date: Sat, 11 Feb 2017 17:50:00 -0800 Subject: [PATCH] Email related issues when issue is deleted Similar to when a child/parent issue is resolved/closed, notifications should be sent to related issues when an issue is deleted. Fixes #22361 --- core/bug_api.php | 1 + core/email_api.php | 25 +++++++++++++++++++++++++ core/relationship_api.php | 10 ++++++---- lang/strings_english.txt | 1 + 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/core/bug_api.php b/core/bug_api.php index e5a981fe75..9c6d4e0190 100644 --- a/core/bug_api.php +++ b/core/bug_api.php @@ -1357,6 +1357,7 @@ function bug_delete( $p_bug_id ) { history_log_event_special( $p_bug_id, BUG_DELETED, bug_format_id( $p_bug_id ) ); email_bug_deleted( $p_bug_id ); + email_relationship_bug_deleted( $p_bug_id ); # call post-deletion custom function. We call this here to allow the custom function to access the details of the bug before # they are deleted from the database given it's id. The other option would be to move this to the end of the function and diff --git a/core/email_api.php b/core/email_api.php index f86693f436..305ac4e357 100644 --- a/core/email_api.php +++ b/core/email_api.php @@ -825,6 +825,31 @@ function email_relationship_deleted( $p_bug_id, $p_related_bug_id, $p_rel_type, } } +/** + * Email related issues when a bug is deleted. This should be deleted before the bug is deleted. + * + * @param $p_bug_id The id of the bug to be deleted. + * @return void + */ +function email_relationship_bug_deleted( $p_bug_id ) { + $t_ignore = false; + $t_relationships = relationship_get_all( $p_bug_id, $t_ignore ); + if( empty( $t_relationships ) ) { + return; + } + + log_event( LOG_EMAIL, sprintf( 'Issue #%d has been deleted, sending notifications to related issues', $p_bug_id ) ); + + foreach( $t_relationships as $t_relationship ) { + $t_related_bug_id = $p_bug_id == $t_relationship->src_bug_id ? + $t_relationship->dest_bug_id : $t_relationship->src_bug_id; + + $t_opt = array(); + $t_opt[] = bug_format_id( $p_bug_id ); + email_generic( $t_related_bug_id, 'handler', 'email_notification_title_for_action_related_issue_deleted', $t_opt ); + } +} + /** * send notices to all the handlers of the parent bugs when a child bug is RESOLVED * @param integer $p_bug_id A bug identifier. diff --git a/core/relationship_api.php b/core/relationship_api.php index 161abce1c1..8766742aae 100644 --- a/core/relationship_api.php +++ b/core/relationship_api.php @@ -307,10 +307,10 @@ function relationship_upsert( $p_src_bug_id, $p_dest_bug_id, $p_relationship_typ /** * Delete a relationship * @param integer $p_relationship_id Relationship Id to update. - * @param integer $p_skip_email_for_issue_id Skip email for specified issue, otherwise 0. + * @param bool $p_send_email Send email? * @return void */ -function relationship_delete( $p_relationship_id, $p_skip_email_for_issue_id = 0 ) { +function relationship_delete( $p_relationship_id, $p_send_email = true ) { $t_relationship = relationship_get( $p_relationship_id ); db_param_push(); @@ -334,7 +334,9 @@ function relationship_delete( $p_relationship_id, $p_skip_email_for_issue_id = 0 $t_src_bug_id ); } - email_relationship_deleted( $t_src_bug_id, $t_dest_bug_id, $t_rel_type ); + if( $p_send_email ) { + email_relationship_deleted( $t_src_bug_id, $t_dest_bug_id, $t_rel_type ); + } } /** @@ -346,7 +348,7 @@ function relationship_delete_all( $p_bug_id ) { $t_is_different_projects = false; $t_relationships = relationship_get_all( $p_bug_id, $t_is_different_projects ); foreach( $t_relationships as $t_relationship ) { - relationship_delete( $t_relationship->id, /* skip_email_for_issue_id */ $p_bug_id ); + relationship_delete( $t_relationship->id, /* send_email */ false ); } } diff --git a/lang/strings_english.txt b/lang/strings_english.txt index 889963f753..2279a297c8 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -322,6 +322,7 @@ $s_email_notification_title_for_action_dependant_on_relationship_deleted = 'The $s_email_notification_title_for_action_blocks_relationship_deleted = 'The following issue has been removed as the CHILD OF issue %1$s.'; $s_email_notification_title_for_action_relationship_child_resolved = 'The RELATED issue %1$s has been RESOLVED.'; $s_email_notification_title_for_action_relationship_child_closed = 'The RELATED issue %1$s has been CLOSED.'; +$s_email_notification_title_for_action_related_issue_deleted = 'The RELATED issue %1$s has been DELETED.'; $s_email_notification_title_for_action_monitor = 'Issue %1$s is now monitored by user %2$s.'; $s_email_reporter = 'Reported By';