1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JiraRestApi\Version; |
4
|
|
|
|
5
|
|
|
use JiraRestApi\Issue\Version; |
6
|
|
|
use JiraRestApi\JiraException; |
7
|
|
|
use JiraRestApi\Project\ProjectService; |
8
|
|
|
|
9
|
|
|
class VersionService extends \JiraRestApi\JiraClient |
10
|
|
|
{ |
11
|
|
|
private $uri = '/version'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Function to create a new project version. |
15
|
|
|
* |
16
|
|
|
* @param Version|array $version |
17
|
|
|
* |
18
|
|
|
* @throws \JiraRestApi\JiraException |
19
|
|
|
* @throws \JsonMapper_Exception |
20
|
|
|
* |
21
|
|
|
* @return Version|object Version class |
22
|
|
|
*/ |
23
|
|
|
public function create($version) |
24
|
|
|
{ |
25
|
|
|
if ($version->releaseDate instanceof \DateTime) { |
26
|
|
|
$version->releaseDate = $version->releaseDate->format('Y-m-d'); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
$data = json_encode($version); |
29
|
|
|
|
30
|
|
|
$this->log->addInfo("Create Version=\n".$data); |
31
|
|
|
|
32
|
|
|
$ret = $this->exec($this->uri, $data, 'POST'); |
33
|
|
|
|
34
|
|
|
return $this->json_mapper->map( |
35
|
|
|
json_decode($ret), new Version() |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Modify a version's sequence within a project. |
41
|
|
|
* |
42
|
|
|
* @param $version |
43
|
|
|
* |
44
|
|
|
* @throws JiraException |
45
|
|
|
*/ |
46
|
|
|
public function move($version) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
throw new JiraException('move version not yet implemented'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* get project version. |
53
|
|
|
* |
54
|
|
|
* @param $id version id |
55
|
|
|
* |
56
|
|
|
* @return Version |
57
|
|
|
* |
58
|
|
|
* @see ProjectService::getVersions() |
59
|
|
|
*/ |
60
|
|
|
public function get($id) |
61
|
|
|
{ |
62
|
|
|
$ret = $this->exec($this->uri.'/'.$id); |
63
|
|
|
|
64
|
|
|
$this->log->addInfo('Result='.$ret); |
65
|
|
|
|
66
|
|
|
$json = json_decode($ret); |
67
|
|
|
$results = array_map(function ($elem) { |
68
|
|
|
return $this->json_mapper->map($elem, new ProjectType()); |
|
|
|
|
69
|
|
|
}, $json); |
70
|
|
|
|
71
|
|
|
return $results; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @author Martijn Smidt <[email protected]> |
76
|
|
|
* |
77
|
|
|
* @param Version $version |
78
|
|
|
* |
79
|
|
|
* @throws JiraException |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function update(Version $version) |
84
|
|
|
{ |
85
|
|
|
if (!$version->id || !is_numeric($version->id)) { |
86
|
|
|
throw new JiraException($version->id.' is not a valid version id.'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if ($version->releaseDate instanceof \DateTime) { |
90
|
|
|
$version->releaseDate = $version->releaseDate->format('Y-m-d'); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$data = json_encode($version); |
94
|
|
|
$ret = $this->exec($this->uri.'/'.$version->id, $data, 'PUT'); |
95
|
|
|
|
96
|
|
|
return $ret; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @author Martijn Smidt <[email protected]> |
101
|
|
|
* |
102
|
|
|
* @param Version $version |
103
|
|
|
* @param Version|bool $moveAffectedIssuesTo |
104
|
|
|
* @param Version|bool $moveFixIssuesTo |
105
|
|
|
* |
106
|
|
|
* @throws JiraException |
107
|
|
|
* |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public function delete(Version $version, $moveAffectedIssuesTo = false, $moveFixIssuesTo = false) |
111
|
|
|
{ |
112
|
|
|
if (!$version->id || !is_numeric($version->id)) { |
113
|
|
|
throw new JiraException($version->id.' is not a valid version id.'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$data = []; |
117
|
|
|
|
118
|
|
|
if ($moveAffectedIssuesTo && $moveAffectedIssuesTo instanceof Version) { |
119
|
|
|
$data['moveAffectedIssuesTo'] = $moveAffectedIssuesTo->name; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if ($moveFixIssuesTo && $moveFixIssuesTo instanceof Version) { |
123
|
|
|
$data['moveFixIssuesTo'] = $moveFixIssuesTo->name; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$ret = $this->exec($this->uri.'/'.$version->id, json_encode($data), 'DELETE'); |
127
|
|
|
|
128
|
|
|
return $ret; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function merge($ver) |
|
|
|
|
132
|
|
|
{ |
133
|
|
|
throw new JiraException('merge version not yet implemented'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Returns a bean containing the number of fixed in and affected issues for the given version. |
138
|
|
|
* |
139
|
|
|
* @param $id int version id |
140
|
|
|
* |
141
|
|
|
* @throws JiraException |
142
|
|
|
* |
143
|
|
|
* @see https://docs.atlassian.com/jira/REST/server/#api/2/version-getVersionRelatedIssues |
144
|
|
|
*/ |
145
|
|
|
public function getRelatedIssues($id) |
|
|
|
|
146
|
|
|
{ |
147
|
|
|
throw new JiraException('get version Related Issues not yet implemented'); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..