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
|
|
|
{ |
27
|
|
|
$version->releaseDate = $version->releaseDate->format('Y-m-d'); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
$data = json_encode($version); |
30
|
|
|
|
31
|
|
|
$this->log->addInfo("Create Version=\n".$data); |
32
|
|
|
|
33
|
|
|
$ret = $this->exec($this->uri, $data, 'POST'); |
34
|
|
|
|
35
|
|
|
return $this->json_mapper->map( |
36
|
|
|
json_decode($ret), new Version() |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Modify a version's sequence within a project. |
42
|
|
|
* |
43
|
|
|
* @param $version |
44
|
|
|
* |
45
|
|
|
* @throws JiraException |
46
|
|
|
*/ |
47
|
|
|
public function move($version) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
throw new JiraException('move version not yet implemented'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* get project version. |
54
|
|
|
* |
55
|
|
|
* @param $id version id |
56
|
|
|
* |
57
|
|
|
* @return Version |
58
|
|
|
* |
59
|
|
|
* @see ProjectService::getVersions() |
60
|
|
|
*/ |
61
|
|
|
public function get($id) |
62
|
|
|
{ |
63
|
|
|
$ret = $this->exec($this->uri.'/'.$id); |
64
|
|
|
|
65
|
|
|
$this->log->addInfo('Result='.$ret); |
66
|
|
|
|
67
|
|
|
$json = json_decode($ret); |
68
|
|
|
$results = array_map(function ($elem) { |
69
|
|
|
return $this->json_mapper->map($elem, new ProjectType()); |
|
|
|
|
70
|
|
|
}, $json); |
71
|
|
|
|
72
|
|
|
return $results; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @author Martijn Smidt <[email protected]> |
77
|
|
|
* |
78
|
|
|
* @param Version $version |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
* @throws JiraException |
82
|
|
|
* |
83
|
|
|
*/ |
84
|
|
|
public function update(Version $version) |
85
|
|
|
{ |
86
|
|
|
if(!$version->id || !is_numeric($version->id)) |
87
|
|
|
{ |
88
|
|
|
throw new JiraException($version->id . ' is not a valid version id.'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if($version->releaseDate instanceof \DateTime) |
92
|
|
|
{ |
93
|
|
|
$version->releaseDate = $version->releaseDate->format('Y-m-d'); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$data = json_encode($version); |
97
|
|
|
$ret = $this->exec($this->uri . '/' . $version->id, $data, 'PUT'); |
98
|
|
|
|
99
|
|
|
return $ret; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @author Martijn Smidt <[email protected]> |
104
|
|
|
* |
105
|
|
|
* @param Version $version |
106
|
|
|
* @param Version|bool $moveAffectedIssuesTo |
107
|
|
|
* @param Version|bool $moveFixIssuesTo |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
* @throws JiraException |
111
|
|
|
*/ |
112
|
|
|
|
113
|
|
|
public function delete(Version $version, $moveAffectedIssuesTo = false, $moveFixIssuesTo = false) |
114
|
|
|
{ |
115
|
|
|
if(!$version->id || !is_numeric($version->id)) |
116
|
|
|
{ |
117
|
|
|
throw new JiraException($version->id . ' is not a valid version id.'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$data = []; |
121
|
|
|
|
122
|
|
|
if($moveAffectedIssuesTo && $moveAffectedIssuesTo instanceof Version) |
123
|
|
|
{ |
124
|
|
|
$data['moveAffectedIssuesTo'] = $moveAffectedIssuesTo->name; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if($moveFixIssuesTo && $moveFixIssuesTo instanceof Version) |
128
|
|
|
{ |
129
|
|
|
$data['moveFixIssuesTo'] = $moveFixIssuesTo->name; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$ret = $this->exec($this->uri . '/' . $version->id, json_encode($data), 'DELETE'); |
133
|
|
|
|
134
|
|
|
return $ret; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function merge($ver) |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
throw new JiraException('merge version not yet implemented'); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Returns a bean containing the number of fixed in and affected issues for the given version. |
144
|
|
|
* |
145
|
|
|
* @param $id int version id |
146
|
|
|
* |
147
|
|
|
* @throws JiraException |
148
|
|
|
* |
149
|
|
|
* @see https://docs.atlassian.com/jira/REST/server/#api/2/version-getVersionRelatedIssues |
150
|
|
|
*/ |
151
|
|
|
public function getRelatedIssues($id) |
|
|
|
|
152
|
|
|
{ |
153
|
|
|
throw new JiraException('get version Related Issues not yet implemented'); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
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..