Skip to content

Commit

Permalink
Email related issues when issue is deleted
Browse files Browse the repository at this point in the history
Similar to when a child/parent issue is resolved/closed,
notifications should be sent to related issues when an issue is deleted.

Fixes #22361
  • Loading branch information
vboctor committed Feb 20, 2017
1 parent 5ebaa96 commit c18e286
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/bug_api.php
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions core/email_api.php
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions core/relationship_api.php
Expand Up @@ -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();
Expand All @@ -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 );
}
}

/**
Expand All @@ -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 );
}
}

Expand Down
1 change: 1 addition & 0 deletions lang/strings_english.txt
Expand Up @@ -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';
Expand Down

0 comments on commit c18e286

Please sign in to comment.