Skip to content

Commit e36ce44

Browse files
committed
impl add attachement
1 parent 8217553 commit e36ce44

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,32 @@ try {
130130
?>
131131
````
132132

133+
## Add Attachment
134+
135+
````php
136+
<?php
137+
require 'vendor/autoload.php';
138+
require_once 'config.jira.php';
139+
140+
use JiraRestApi\Issue\IssueService;
141+
use JiraRestApi\Issue\IssueField;
142+
try {
143+
$issueService = new IssueService();
144+
145+
$ret = $issueService->addAttachments("TEST-879", 'screen_capture.png');
146+
147+
print_r($ret);
148+
} catch (JIRAException $e) {
149+
$this->assertTrue(FALSE, "Attach Failed : " . $e->getMessage());
150+
}
151+
152+
?>
153+
````
154+
133155
# License
134156

135157
Apache V2 License
136158

137159
# JIRA Rest API Documents
138160
* 6.2 - https://docs.atlassian.com/jira/REST/6.2/
139-
* latest - https://docs.atlassian.com/jira/REST/latest/
161+
* latest - https://docs.atlassian.com/jira/REST/latest/

src/JiraClient.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,16 @@ public function upload($context, $upload_file) {
168168
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
169169
curl_setopt($ch, CURLOPT_URL, $url);
170170

171+
/*
171172
$attachments = array(
172173
'file' => '@' . realpath($upload_file)
173174
);
175+
*/
176+
$attachments = new \CURLFile(realpath($upload_file));
174177

175178
// send file
176179
curl_setopt($ch, CURLOPT_POST, true);
177-
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachments);
180+
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => $attachments));
178181

179182
curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password");
180183

src/issue/IssueService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function addAttachments($issueIdOrKey, $filePath) {
6969

7070
$ret = $this->upload($this->uri . "/$issueIdOrKey/attachments", $filePath);
7171

72-
$issue = $this->json_mapper->map(
73-
json_decode($ret), new Issue()
72+
$issue = $this->json_mapper->mapArray(
73+
json_decode($ret), new \ArrayObject(), '\JiraRestApi\Issue\Attachment'
7474
);
7575

7676
return $issue;

tests/IssueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testCreateIssue()
5858

5959
public function testAddAttachment()
6060
{
61-
$this->markTestIncomplete();
61+
//$this->markTestIncomplete();
6262
try {
6363

6464
$issueService = new IssueService();

0 commit comments

Comments
 (0)