Skip to content

Commit

Permalink
Trigger email notifications for relationship_delete_all()
Browse files Browse the repository at this point in the history
When an issue is deleted and all its relationships are deleted,
email notifications should be triggered for the other issues.
  • Loading branch information
vboctor committed Feb 20, 2017
1 parent f49c6ae commit 042f147
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
4 changes: 1 addition & 3 deletions core/bug_api.php
Expand Up @@ -1375,11 +1375,9 @@ function bug_delete( $p_bug_id ) {
# Delete all sponsorships
sponsorship_delete_all( $p_bug_id );

# MASC RELATIONSHIP
# we delete relationships even if the feature is currently off.
# Delete all relationships
relationship_delete_all( $p_bug_id );

# MASC RELATIONSHIP
# Delete files
file_delete_attachments( $p_bug_id );

Expand Down
40 changes: 22 additions & 18 deletions core/relationship_api.php
Expand Up @@ -317,9 +317,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.
* @return void
*/
function relationship_delete( $p_relationship_id ) {
function relationship_delete( $p_relationship_id, $p_skip_email_for_issue_id = 0 ) {
$t_relationship = relationship_get( $p_relationship_id );

db_param_push();
Expand All @@ -335,7 +336,10 @@ function relationship_delete( $p_relationship_id ) {

# send email and update the history for the src issue
history_log_event_special( $t_src_bug_id, BUG_DEL_RELATIONSHIP, $t_rel_type, $t_dest_bug_id );
email_relationship_deleted( $t_src_bug_id, $t_dest_bug_id, $t_rel_type );

if( $t_src_bug_id != $p_skip_email_for_issue_id ) {
email_relationship_deleted( $t_src_bug_id, $t_dest_bug_id, $t_rel_type );
}

if( bug_exists( $t_dest_bug_id ) ) {
history_log_event_special(
Expand All @@ -344,7 +348,9 @@ function relationship_delete( $p_relationship_id ) {
relationship_get_complementary_type( $t_rel_type ),
$t_src_bug_id );

email_relationship_deleted( $t_dest_bug_id, $t_src_bug_id, $t_rel_type );
if( $t_dest_bug_id != $p_skip_email_for_issue_id ) {
email_relationship_deleted( $t_dest_bug_id, $t_src_bug_id, $t_rel_type );
}
}
}

Expand All @@ -354,11 +360,11 @@ function relationship_delete( $p_relationship_id ) {
* @return void
*/
function relationship_delete_all( $p_bug_id ) {
db_param_push();
$t_query = 'DELETE FROM {bug_relationship}
WHERE source_bug_id=' . db_param() . ' OR
destination_bug_id=' . db_param();
db_query( $t_query, array( (int)$p_bug_id, (int)$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 );
}
}

/**
Expand All @@ -368,23 +374,21 @@ function relationship_delete_all( $p_bug_id ) {
* @return void
*/
function relationship_copy_all( $p_bug_id, $p_new_bug_id ) {
$t_relationship = relationship_get_all_src( $p_bug_id );
$t_relationship_count = count( $t_relationship );
for( $i = 0;$i < $t_relationship_count;$i++ ) {
$t_relationships = relationship_get_all_src( $p_bug_id );
foreach( $t_relationships as $t_relationship ) {
relationship_add(
$p_new_bug_id,
$t_relationship[$i]->dest_bug_id,
$t_relationship[$i]->type,
$t_relationship->dest_bug_id,
$t_relationship->type,
/* email_for_source */ false );
}

$t_relationship = relationship_get_all_dest( $p_bug_id );
$t_relationship_count = count( $t_relationship );
for( $i = 0;$i < $t_relationship_count;$i++ ) {
$t_relationships = relationship_get_all_dest( $p_bug_id );
foreach( $t_relationships as $t_relationship ) {
relationship_add(
$p_new_bug_id,
$t_relationship[$i]->src_bug_id,
relationship_get_complementary_type( $t_relationship[$i]->type ),
$t_relationship->src_bug_id,
relationship_get_complementary_type( $t_relationship->type ),
/* email_for_source */ false );
}
}
Expand Down

0 comments on commit 042f147

Please sign in to comment.