Skip to content

Commit 5ccae29

Browse files
committedDec 5, 2011
Allow getting/setting tags as part of the mc_issue(get/set/add) methods
Fixes #13446: Add tags support to soap api
1 parent 633d1d0 commit 5ccae29

File tree

5 files changed

+142
-2
lines changed

5 files changed

+142
-2
lines changed
 

‎api/soap/mantisconnect.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@
288288
'notes' => array( 'name' => 'notes', 'type' => 'tns:IssueNoteDataArray', 'minOccurs' => '0' ),
289289
'custom_fields' => array( 'name' => 'custom_fields', 'type' => 'tns:CustomFieldValueForIssueDataArray', 'minOccurs' => '0' ),
290290
'due_date' => array( 'name' => 'due_date', 'type' => 'xsd:dateTime', 'minOccurs' => '0' ),
291-
'monitors' => array( 'name' => 'monitors', 'type' => 'tns:AccountDataArray', 'minOccurs' => '0')
291+
'monitors' => array( 'name' => 'monitors', 'type' => 'tns:AccountDataArray', 'minOccurs' => '0'),
292+
'tags' => array( 'name' => 'tags', 'type' => 'tns:ObjectRefArray', 'minOccurs' => '0')
292293
)
293294
);
294295

‎api/soap/mc_issue_api.php

+29-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function mc_issue_get( $p_username, $p_password, $p_issue_id ) {
111111
$t_issue_data['notes'] = mci_issue_get_notes( $p_issue_id );
112112
$t_issue_data['custom_fields'] = mci_issue_get_custom_fields( $p_issue_id );
113113
$t_issue_data['monitors'] = mci_account_get_array_by_ids( bug_get_monitors ( $p_issue_id ) );
114+
$t_issue_data['tags'] = mci_issue_get_tags_for_bug_id( $p_issue_id , $t_user_id );
114115

115116
return $t_issue_data;
116117
}
@@ -669,6 +670,10 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
669670
bugnote_add( $t_issue_id, $t_note['text'], mci_get_time_tracking_from_note( $t_issue_id, $t_note ), $t_view_state_id == VS_PRIVATE, $note_type, $note_attr, $t_user_id, FALSE );
670671
}
671672
}
673+
674+
if ( isset ( $p_issue['tags']) && is_array ( $p_issue['tags']) ) {
675+
mci_tag_set_for_issue( $t_issue_id, $p_issue['tags'] );
676+
}
672677

673678
email_new_bug( $t_issue_id );
674679

@@ -872,7 +877,11 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
872877
}
873878
}
874879
}
875-
880+
881+
if ( isset ( $p_issue['tags']) && is_array ( $p_issue['tags']) ) {
882+
mci_tag_set_for_issue( $p_issue_id, $p_issue['tags'] );
883+
}
884+
876885
# submit the issue
877886
return $t_bug_data->update( /* update_extended */ true, /* bypass_email */ true );
878887

@@ -1272,6 +1281,25 @@ function mci_issue_data_as_array( $p_issue_data, $p_user_id, $p_lang ) {
12721281
$t_issue['relationships'] = mci_issue_get_relationships( $p_issue_data->id, $p_user_id );
12731282
$t_issue['notes'] = mci_issue_get_notes( $p_issue_data->id );
12741283
$t_issue['custom_fields'] = mci_issue_get_custom_fields( $p_issue_data->id );
1284+
$t_issue['tags'] = mci_issue_get_tags_for_bug_id( $p_issue_data->id, $p_user_id );
12751285

12761286
return $t_issue;
12771287
}
1288+
1289+
function mci_issue_get_tags_for_bug_id( $p_bug_id, $p_user_id ) {
1290+
1291+
if ( !access_has_global_level( config_get( 'tag_view_threshold' ), $p_user_id ) )
1292+
return array();
1293+
1294+
$t_tag_rows = tag_bug_get_attached( $p_bug_id );
1295+
$t_result = array();
1296+
1297+
foreach ( $t_tag_rows as $t_tag_row ) {
1298+
$t_result[] = array (
1299+
'id' => $t_tag_row['id'],
1300+
'name' => $t_tag_row['name']
1301+
);
1302+
}
1303+
1304+
return $t_result;
1305+
}

‎api/soap/mc_tag_api.php

+38
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,41 @@ function mc_tag_delete( $p_username, $p_password, $p_tag_id ) {
115115

116116
return tag_delete( $p_tag_id );
117117
}
118+
119+
function mci_tag_set_for_issue ( $p_issue_id, $p_tags ) {
120+
121+
$t_tag_ids_to_attach = array();
122+
$t_tag_ids_to_detach = array();
123+
124+
$t_submitted_tag_ids = array();
125+
$t_attached_tags = tag_bug_get_attached( $p_issue_id );
126+
$t_attached_tag_ids = array();
127+
foreach ( $t_attached_tags as $t_attached_tag )
128+
$t_attached_tag_ids[] = $t_attached_tag['id'];
129+
130+
foreach ( $p_tags as $t_tag ) {
131+
132+
$t_submitted_tag_ids[] = $t_tag['id'];
133+
134+
if ( in_array( $t_tag['id'], $t_attached_tag_ids) ) {
135+
continue;
136+
} else {
137+
$t_tag_ids_to_attach[] = $t_tag['id'];
138+
}
139+
}
140+
141+
foreach ( $t_attached_tag_ids as $t_attached_tag_id ) {
142+
143+
if ( in_array ( $t_attached_tag_id, $t_submitted_tag_ids) ) {
144+
continue;
145+
} else {
146+
$t_tag_ids_to_detach[] = $t_attached_tag_id;
147+
}
148+
}
149+
150+
foreach ( $t_tag_ids_to_detach as $t_tag_id )
151+
tag_bug_detach( $t_tag_id, $p_issue_id, true);
152+
153+
foreach ( $t_tag_ids_to_attach as $t_tag_id )
154+
tag_bug_attach( $t_tag_id, $p_issue_id, true);
155+
}

‎tests/soap/IssueAddTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,27 @@ public function testCreateIssueWithMiscNote() {
489489
$this->assertEquals( 2, $note->note_type );
490490
$this->assertEquals( 'attr_value', $note->note_attr );
491491
}
492+
493+
public function testCreateIssueWithTags() {
494+
495+
// initialise tags
496+
$tagId1 = $this->client->mc_tag_add( $this->userName, $this->password, array (
497+
'name' => 'IssueCreateTest.createIssueWithTags'
498+
));
499+
$this->deleteTagAfterRun( $tagId1 );
500+
501+
$tagId2 = $this->client->mc_tag_add( $this->userName, $this->password, array (
502+
'name' => 'IssueCreateTest.createIssueWithTags2'
503+
));
504+
$this->deleteTagAfterRun( $tagId2 );
505+
506+
// create issue
507+
$issueToAdd = $this->getIssueToAdd( 'IssueCreateTest.createIssueWithTags' );
508+
$issueToAdd['tags'] = array ( array( 'id' => $tagId1), array('id' => $tagId2 ) );
509+
$issueId = $this->client->mc_issue_add( $this->userName, $this->password, $issueToAdd);
510+
$this->deleteAfterRun( $issueId );
511+
$issue = $this->client->mc_issue_get( $this->userName, $this->password, $issueId );
512+
513+
self::assertEquals ( 2, count ( $issue->tags ) );
514+
}
492515
}

‎tests/soap/IssueUpdateTest.php

+50
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,54 @@ public function testUpdateWithRareFields() {
458458
$this->assertEquals( 'os', $retrievedIssue->os );
459459
$this->assertEquals( 'os_build', $retrievedIssue->os_build);
460460
}
461+
462+
public function testUpdateWithTagOperations() {
463+
464+
// initialise tags
465+
$tagId1 = $this->client->mc_tag_add( $this->userName, $this->password, array (
466+
'name' => 'IssueUpdateTest.testUpdateWithTagAdditions'
467+
));
468+
$this->deleteTagAfterRun( $tagId1 );
469+
470+
$tagId2 = $this->client->mc_tag_add( $this->userName, $this->password, array (
471+
'name' => 'IssueUpdateTest.testUpdateWithTagAdditions2'
472+
));
473+
$this->deleteTagAfterRun( $tagId2 );
474+
475+
$tag1 = new stdClass();
476+
$tag1->id = $tagId1;
477+
478+
$tag2 = new stdClass();
479+
$tag2->id = $tagId2;
480+
481+
// create issue
482+
$issueToAdd = $this->getIssueToAdd( 'IssueUpdateTest.testUpdateWithRareFields' );
483+
$issueId = $this->client->mc_issue_add( $this->userName, $this->password, $issueToAdd);
484+
$this->deleteAfterRun( $issueId );
485+
$issue = $this->client->mc_issue_get( $this->userName, $this->password, $issueId );
486+
487+
// update from 0 to 2 tags -> test attaching tags
488+
$issue->tags = array ( $tag1, $tag2 );
489+
$this->client->mc_issue_update( $this->userName, $this->password, $issueId, $issue);
490+
$issue = $this->client->mc_issue_get( $this->userName, $this->password, $issueId );
491+
self::assertEquals(2, count ( $issue->tags ) );
492+
493+
// update from 2 to 1 tags -> test partially detaching tags
494+
$issue->tags = array ( $tag1 );
495+
$this->client->mc_issue_update( $this->userName, $this->password, $issueId, $issue);
496+
$issue = $this->client->mc_issue_get( $this->userName, $this->password, $issueId );
497+
self::assertEquals(1, count ( $issue->tags ) );
498+
499+
// update from 1 to 2 tags -> test partially attaching tags
500+
$issue->tags = array ( $tag1, $tag2 );
501+
$this->client->mc_issue_update( $this->userName, $this->password, $issueId, $issue);
502+
$issue = $this->client->mc_issue_get( $this->userName, $this->password, $issueId );
503+
self::assertEquals(2, count ( $issue->tags ) );
504+
505+
// update from 2 to 0 tags -> test detaching tags
506+
$issue->tags = array();
507+
$this->client->mc_issue_update( $this->userName, $this->password, $issueId, $issue);
508+
$issue = $this->client->mc_issue_get( $this->userName, $this->password, $issueId );
509+
self::assertEquals(0, count ( $issue->tags ) );
510+
}
461511
}

0 commit comments

Comments
 (0)
Please sign in to comment.