Skip to content

Commit 4765c5e

Browse files
authored
Merge pull request #388 from Art4/deprecate-abstractapi-put
Deprecate `AbstractApi::put()`
2 parents 590d149 + 90f09a3 commit 4765c5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2007
-1347
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828

2929
- `Redmine\Api\AbstractApi::get()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
3030
- `Redmine\Api\AbstractApi::post()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
31+
- `Redmine\Api\AbstractApi::put()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
3132
- The constant `Redmine\Api\Issue::PRIO_LOW` is deprecated.
3233
- The constant `Redmine\Api\Issue::PRIO_NORMAL` is deprecated.
3334
- The constant `Redmine\Api\Issue::PRIO_HIGH` is deprecated.

docs/usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ $client->getApi('group')->update($groupId, [
518518
// Project memberships
519519
$client->getApi('membership')->listByProject($projectId);
520520
$client->getApi('membership')->create($projectId, [
521-
'user_id' => null,
522-
'role_ids' => [],
521+
'user_id' => 1,
522+
'role_ids' => [5],
523523
]);
524524
$client->getApi('membership')->remove($membershipId);
525525

src/Redmine/Api/AbstractApi.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,18 @@ protected function post($path, $data)
175175
/**
176176
* Perform the client put() method.
177177
*
178+
* @deprecated v2.6.0 Use `\Redmine\Http\HttpClient::request()` instead
179+
* @see \Redmine\Http\HttpClient::request()
180+
*
178181
* @param string $path
179182
* @param string $data
180183
*
181184
* @return string|SimpleXMLElement
182185
*/
183186
protected function put($path, $data)
184187
{
188+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead.', E_USER_DEPRECATED);
189+
185190
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeRequest(
186191
'PUT',
187192
strval($path),

src/Redmine/Api/Group.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,13 @@ public function update(int $id, array $params = [])
155155
];
156156
$params = $this->sanitizeParams($defaults, $params);
157157

158-
return $this->put(
158+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
159+
'PUT',
159160
'/groups/' . $id . '.xml',
160161
XmlSerializer::createFromArray(['group' => $params])->getEncoded()
161-
);
162+
));
163+
164+
return $this->lastResponse->getContent();
162165
}
163166

164167
/**

src/Redmine/Api/Issue.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,13 @@ public function update($id, array $params)
260260
$sanitizedParams['assigned_to_id'] = '';
261261
}
262262

263-
return $this->put(
263+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
264+
'PUT',
264265
'/issues/' . urlencode(strval($id)) . '.xml',
265266
XmlSerializer::createFromArray(['issue' => $sanitizedParams])->getEncoded()
266-
);
267+
));
268+
269+
return $this->lastResponse->getContent();
267270
}
268271

269272
/**
@@ -417,10 +420,13 @@ public function attachMany($id, array $attachments)
417420
'uploads' => $attachments,
418421
];
419422

420-
return $this->put(
423+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeJsonRequest(
424+
'PUT',
421425
'/issues/' . urlencode(strval($id)) . '.json',
422426
JsonSerializer::createFromArray(['issue' => $params])->getEncoded()
423-
);
427+
));
428+
429+
return $this->lastResponse->getContent();
424430
}
425431

426432
/**

src/Redmine/Api/IssueCategory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,13 @@ public function update($id, array $params)
211211
];
212212
$params = $this->sanitizeParams($defaults, $params);
213213

214-
return $this->put(
214+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
215+
'PUT',
215216
'/issue_categories/' . urlencode(strval($id)) . '.xml',
216217
XmlSerializer::createFromArray(['issue_category' => $params])->getEncoded()
217-
);
218+
));
219+
220+
return $this->lastResponse->getContent();
218221
}
219222

220223
/**

src/Redmine/Api/Membership.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,16 @@ public function update($id, array $params = [])
144144
$params = $this->sanitizeParams($defaults, $params);
145145

146146
if (!isset($params['role_ids'])) {
147-
throw new MissingParameterException('Missing mandatory parameters');
147+
throw new MissingParameterException('Theses parameters are mandatory: `role_ids`');
148148
}
149149

150-
return $this->put(
150+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
151+
'PUT',
151152
'/memberships/' . $id . '.xml',
152153
XmlSerializer::createFromArray(['membership' => $params])->getEncoded()
153-
);
154+
));
155+
156+
return $this->lastResponse->getContent();
154157
}
155158

156159
/**

src/Redmine/Api/Project.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,13 @@ public function update($id, array $params)
215215
];
216216
$params = $this->sanitizeParams($defaults, $params);
217217

218-
return $this->put(
218+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
219+
'PUT',
219220
'/projects/' . urlencode(strval($id)) . '.xml',
220221
XmlSerializer::createFromArray(['project' => $params])->getEncoded()
221-
);
222+
));
223+
224+
return $this->lastResponse->getContent();
222225
}
223226

224227
/**
@@ -242,10 +245,11 @@ final public function close($projectIdentifier): bool
242245
));
243246
}
244247

245-
$this->put(
248+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
249+
'PUT',
246250
'/projects/' . strval($projectIdentifier) . '/close.xml',
247251
''
248-
);
252+
));
249253

250254
$lastResponse = $this->getLastResponse();
251255

@@ -277,10 +281,11 @@ final public function reopen($projectIdentifier): bool
277281
));
278282
}
279283

280-
$this->put(
284+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
285+
'PUT',
281286
'/projects/' . strval($projectIdentifier) . '/reopen.xml',
282287
''
283-
);
288+
));
284289

285290
$lastResponse = $this->getLastResponse();
286291

@@ -312,10 +317,11 @@ final public function archive($projectIdentifier): bool
312317
));
313318
}
314319

315-
$this->put(
320+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
321+
'PUT',
316322
'/projects/' . strval($projectIdentifier) . '/archive.xml',
317323
''
318-
);
324+
));
319325

320326
$lastResponse = $this->getLastResponse();
321327

@@ -347,10 +353,11 @@ final public function unarchive($projectIdentifier): bool
347353
));
348354
}
349355

350-
$this->put(
356+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
357+
'PUT',
351358
'/projects/' . strval($projectIdentifier) . '/unarchive.xml',
352359
''
353-
);
360+
));
354361

355362
$lastResponse = $this->getLastResponse();
356363

src/Redmine/Api/TimeEntry.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,13 @@ public function update($id, array $params)
171171
];
172172
$params = $this->sanitizeParams($defaults, $params);
173173

174-
return $this->put(
174+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
175+
'PUT',
175176
'/time_entries/' . $id . '.xml',
176177
XmlSerializer::createFromArray(['time_entry' => $params])->getEncoded()
177-
);
178+
));
179+
180+
return $this->lastResponse->getContent();
178181
}
179182

180183
/**

src/Redmine/Api/User.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,13 @@ public function update($id, array $params)
247247
];
248248
$params = $this->sanitizeParams($defaults, $params);
249249

250-
return $this->put(
250+
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
251+
'PUT',
251252
'/users/' . urlencode(strval($id)) . '.xml',
252253
XmlSerializer::createFromArray(['user' => $params])->getEncoded()
253-
);
254+
));
255+
256+
return $this->lastResponse->getContent();
254257
}
255258

256259
/**

0 commit comments

Comments
 (0)