Skip to content

Commit

Permalink
Fix return values from relationship APIs
Browse files Browse the repository at this point in the history
Fixes #22360
  • Loading branch information
vboctor committed Feb 20, 2017
1 parent 3b75893 commit 8934574
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
6 changes: 1 addition & 5 deletions api/soap/mc_issue_api.php
Expand Up @@ -1435,11 +1435,7 @@ function mc_issue_relationship_add( $p_username, $p_password, $p_issue_id, stdCl

if( $t_old_id_relationship == 0 ) {
log_event( LOG_WEBSERVICE, 'adding relationship type \'' . $t_rel_type['id'] . '\' between \'' . $p_issue_id . '\' and \'' . $t_dest_issue_id . '\'' );
relationship_add( $p_issue_id, $t_dest_issue_id, $t_rel_type['id'] );

# The above function call into MantisBT does not seem to return a valid BugRelationshipData object.
# So we call db_insert_id in order to find the id of the created relationship.
$t_relationship_id = db_insert_id( db_get_table( 'bug_relationship' ) );
$t_relationship_id = relationship_add( $p_issue_id, $t_dest_issue_id, $t_rel_type['id'] );

# Add log line to the history (both bugs)
history_log_event_special( $p_issue_id, BUG_ADD_RELATIONSHIP, $t_rel_type['id'], $t_dest_issue_id );
Expand Down
26 changes: 5 additions & 21 deletions core/relationship_api.php
Expand Up @@ -205,7 +205,7 @@ function relationship_get_complementary_type( $p_relationship_type ) {
* @param integer $p_src_bug_id Source Bug Id.
* @param integer $p_dest_bug_id Destination Bug Id.
* @param integer $p_relationship_type Relationship type.
* @return BugRelationshipData Bug Relationship
* @return integer The new bug relationship id.
*/
function relationship_add( $p_src_bug_id, $p_dest_bug_id, $p_relationship_type ) {
global $g_relationships;
Expand All @@ -224,16 +224,9 @@ function relationship_add( $p_src_bug_id, $p_dest_bug_id, $p_relationship_type )
( source_bug_id, destination_bug_id, relationship_type )
VALUES
( ' . db_param() . ',' . db_param() . ',' . db_param() . ')';
$t_result = db_query( $t_query, array( $c_src_bug_id, $c_dest_bug_id, $c_relationship_type ) );
$t_relationship = db_fetch_array( $t_result );

$t_bug_relationship_data = new BugRelationshipData;
$t_bug_relationship_data->id = $t_relationship['id'];
$t_bug_relationship_data->src_bug_id = $t_relationship['source_bug_id'];
$t_bug_relationship_data->dest_bug_id = $t_relationship['destination_bug_id'];
$t_bug_relationship_data->type = $t_relationship['relationship_type'];
db_query( $t_query, array( $c_src_bug_id, $c_dest_bug_id, $c_relationship_type ) );

return $t_bug_relationship_data;
return db_insert_id( db_get_table( 'bug_relationship' ) );
}

/**
Expand All @@ -242,7 +235,7 @@ function relationship_add( $p_src_bug_id, $p_dest_bug_id, $p_relationship_type )
* @param integer $p_src_bug_id Source Bug Id.
* @param integer $p_dest_bug_id Destination Bug Id.
* @param integer $p_relationship_type Relationship type.
* @return BugRelationshipData Bug Relationship
* @return void
*/
function relationship_update( $p_relationship_id, $p_src_bug_id, $p_dest_bug_id, $p_relationship_type ) {
global $g_relationships;
Expand All @@ -262,16 +255,7 @@ function relationship_update( $p_relationship_id, $p_src_bug_id, $p_dest_bug_id,
destination_bug_id=' . db_param() . ',
relationship_type=' . db_param() . '
WHERE id=' . db_param();
$t_result = db_query( $t_query, array( $c_src_bug_id, $c_dest_bug_id, $c_relationship_type, (int)$p_relationship_id ) );
$t_relationship = db_fetch_array( $t_result );

$t_bug_relationship_data = new BugRelationshipData;
$t_bug_relationship_data->id = $t_relationship['id'];
$t_bug_relationship_data->src_bug_id = $t_relationship['source_bug_id'];
$t_bug_relationship_data->dest_bug_id = $t_relationship['destination_bug_id'];
$t_bug_relationship_data->type = $t_relationship['relationship_type'];

return $t_bug_relationship_data;
db_query( $t_query, array( $c_src_bug_id, $c_dest_bug_id, $c_relationship_type, (int)$p_relationship_id ) );
}

/**
Expand Down

0 comments on commit 8934574

Please sign in to comment.