Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0a8bbbd

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 009db42 commit 0a8bbbd

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

+28
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
}
@@ -670,6 +671,10 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
670671
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 );
671672
}
672673
}
674+
675+
if ( isset ( $p_issue['tags']) && is_array ( $p_issue['tags']) ) {
676+
mci_tag_set_for_issue( $t_issue_id, $p_issue['tags'] );
677+
}
673678

674679
email_new_bug( $t_issue_id );
675680

@@ -874,6 +879,10 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
874879
}
875880
}
876881

882+
if ( isset ( $p_issue['tags']) && is_array ( $p_issue['tags']) ) {
883+
mci_tag_set_for_issue( $p_issue_id, $p_issue['tags'] );
884+
}
885+
877886
# submit the issue
878887
return $t_is_success = $t_bug_data->update( /* update_extended */ true, /* bypass_email */ false);
879888
}
@@ -1302,6 +1311,25 @@ function mci_issue_data_as_array( $p_issue_data, $p_user_id, $p_lang ) {
13021311
$t_issue['relationships'] = mci_issue_get_relationships( $p_issue_data->id, $p_user_id );
13031312
$t_issue['notes'] = mci_issue_get_notes( $p_issue_data->id );
13041313
$t_issue['custom_fields'] = mci_issue_get_custom_fields( $p_issue_data->id );
1314+
$t_issue['tags'] = mci_issue_get_tags_for_bug_id( $p_issue_data->id, $p_user_id );
13051315

13061316
return $t_issue;
13071317
}
1318+
1319+
function mci_issue_get_tags_for_bug_id( $p_bug_id, $p_user_id ) {
1320+
1321+
if ( !access_has_global_level( config_get( 'tag_view_threshold' ), $p_user_id ) )
1322+
return array();
1323+
1324+
$t_tag_rows = tag_bug_get_attached( $p_bug_id );
1325+
$t_result = array();
1326+
1327+
foreach ( $t_tag_rows as $t_tag_row ) {
1328+
$t_result[] = array (
1329+
'id' => $t_tag_row['id'],
1330+
'name' => $t_tag_row['name']
1331+
);
1332+
}
1333+
1334+
return $t_result;
1335+
}

‎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

+51-1
Original file line numberDiff line numberDiff line change
@@ -457,5 +457,55 @@ public function testUpdateWithRareFields() {
457457
$this->assertEquals( 'platform', $retrievedIssue->platform );
458458
$this->assertEquals( 'os', $retrievedIssue->os );
459459
$this->assertEquals( 'os_build', $retrievedIssue->os_build);
460-
}
460+
}
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.