Skip to content

Commit

Permalink
Merge pull request #392 from Art4/deprecate-abstractapi-delete
Browse files Browse the repository at this point in the history
Deprecate `AbstractApi::delete()`
  • Loading branch information
Art4 authored Mar 25, 2024
2 parents 3940781 + eab16f5 commit e340e09
Show file tree
Hide file tree
Showing 61 changed files with 1,287 additions and 611 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Redmine\Api\AbstractApi::get()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
- `Redmine\Api\AbstractApi::post()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
- `Redmine\Api\AbstractApi::put()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
- `Redmine\Api\AbstractApi::delete()` is deprecated, use `\Redmine\Http\HttpClient::request()` instead.
- The constant `Redmine\Api\Issue::PRIO_LOW` is deprecated.
- The constant `Redmine\Api\Issue::PRIO_NORMAL` is deprecated.
- The constant `Redmine\Api\Issue::PRIO_HIGH` is deprecated.
Expand Down
5 changes: 5 additions & 0 deletions src/Redmine/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,17 @@ protected function put($path, $data)
/**
* Perform the client delete() method.
*
* @deprecated v2.6.0 Use `\Redmine\Http\HttpClient::request()` instead
* @see \Redmine\Http\HttpClient::request()
*
* @param string $path
*
* @return string
*/
protected function delete($path)
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.6.0, use `\Redmine\Http\HttpClient::request()` instead.', E_USER_DEPRECATED);

$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeRequest(
'DELETE',
strval($path),
Expand Down
9 changes: 7 additions & 2 deletions src/Redmine/Api/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,15 @@ public function upload($attachment, $params = [])
*
* @param int $id id of the attachment
*
* @return false|SimpleXMLElement|string
* @return string empty string on success
*/
public function remove($id)
{
return $this->delete('/attachments/' . urlencode(strval($id)) . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/attachments/' . urlencode(strval($id)) . '.xml'
));

return $this->lastResponse->getContent();
}
}
18 changes: 14 additions & 4 deletions src/Redmine/Api/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,16 @@ public function show($id, array $params = [])
*
* @param int $id id of the group
*
* @return string
* @return string empty string on success
*/
public function remove($id)
{
return $this->delete('/groups/' . $id . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/groups/' . $id . '.xml'
));

return $this->lastResponse->getContent();
}

/**
Expand Down Expand Up @@ -245,10 +250,15 @@ public function addUser($id, $userId)
* @param int $id id of the group
* @param int $userId id of the user
*
* @return string
* @return string empty string on success
*/
public function removeUser($id, $userId)
{
return $this->delete('/groups/' . $id . '/users/' . $userId . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/groups/' . $id . '/users/' . $userId . '.xml'
));

return $this->lastResponse->getContent();
}
}
18 changes: 14 additions & 4 deletions src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,16 @@ public function addWatcher($id, $watcherUserId)
* @param int $id
* @param int $watcherUserId
*
* @return false|SimpleXMLElement|string
* @return string empty string on success
*/
public function removeWatcher($id, $watcherUserId)
{
return $this->delete('/issues/' . urlencode(strval($id)) . '/watchers/' . urlencode(strval($watcherUserId)) . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/issues/' . urlencode(strval($id)) . '/watchers/' . urlencode(strval($watcherUserId)) . '.xml'
));

return $this->lastResponse->getContent();
}

/**
Expand Down Expand Up @@ -434,11 +439,16 @@ public function attachMany($id, array $attachments)
*
* @param int $id the issue number
*
* @return false|SimpleXMLElement|string
* @return string empty string on success
*/
public function remove($id)
{
return $this->delete('/issues/' . urlencode(strval($id)) . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/issues/' . urlencode(strval($id)) . '.xml'
));

return $this->lastResponse->getContent();
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Redmine/Api/IssueCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,15 @@ public function update($id, array $params)
* @param int $id id of the category
* @param array $params extra GET parameters
*
* @return string
* @return string empty string on success
*/
public function remove($id, array $params = [])
{
return $this->delete(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
PathSerializer::create('/issue_categories/' . urlencode(strval($id)) . '.xml', $params)->getPath()
);
));

return $this->lastResponse->getContent();
}
}
9 changes: 7 additions & 2 deletions src/Redmine/Api/IssueRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,16 @@ public function show($id)
*
* @param int $id the relation id
*
* @return string
* @return string empty string on success
*/
public function remove($id)
{
return $this->delete('/relations/' . $id . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/relations/' . $id . '.xml'
));

return $this->lastResponse->getContent();
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Redmine/Api/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ public function update($id, array $params = [])
*
* @param int $id id of the membership
*
* @return false|\SimpleXMLElement|string
* @return string empty string on success
*/
public function remove($id)
{
return $this->delete('/memberships/' . $id . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/memberships/' . $id . '.xml'
));

return $this->lastResponse->getContent();
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Redmine/Api/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,15 @@ protected function prepareParamsXml($params)
*
* @param int $id id of the project
*
* @return false|\SimpleXMLElement|string
* @return string empty string on success
*/
public function remove($id)
{
return $this->delete('/projects/' . $id . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/projects/' . $id . '.xml'
));

return $this->lastResponse->getContent();
}
}
9 changes: 7 additions & 2 deletions src/Redmine/Api/TimeEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,15 @@ public function update($id, array $params)
*
* @param int $id id of the time entry
*
* @return false|\SimpleXMLElement|string
* @return string empty string on success
*/
public function remove($id)
{
return $this->delete('/time_entries/' . $id . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/time_entries/' . $id . '.xml'
));

return $this->lastResponse->getContent();
}
}
9 changes: 7 additions & 2 deletions src/Redmine/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,15 @@ public function update($id, array $params)
*
* @param int $id id of the user
*
* @return false|\SimpleXMLElement|string
* @return string empty string on success
*/
public function remove($id)
{
return $this->delete('/users/' . $id . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/users/' . $id . '.xml'
));

return $this->lastResponse->getContent();
}
}
9 changes: 7 additions & 2 deletions src/Redmine/Api/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,15 @@ private function validateSharing(array $params = [])
*
* @param int $id id of the version
*
* @return string
* @return string empty string on success
*/
public function remove($id)
{
return $this->delete('/versions/' . $id . '.xml');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/versions/' . $id . '.xml'
));

return $this->lastResponse->getContent();
}
}
9 changes: 6 additions & 3 deletions src/Redmine/Api/Wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,15 @@ public function update($project, $page, array $params = [])
* @param int|string $project the project name
* @param string $page the page name
*
* @return string
* @return string empty string on success
*/
public function remove($project, $page)
{
return $this->delete(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'DELETE',
'/projects/' . $project . '/wiki/' . urlencode($page) . '.xml'
);
));

return $this->lastResponse->getContent();
}
}
14 changes: 14 additions & 0 deletions tests/Behat/Bootstrap/AttachmentContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,18 @@ public function iDownloadTheAttachmentWithTheId(int $attachmentId)
$api->getLastResponse()
);
}

/**
* @When I remove the attachment with the id :attachmentId
*/
public function iRemoveTheAttachmentWithTheId($attachmentId)
{
/** @var Attachment */
$api = $this->getNativeCurlClient()->getApi('attachment');

$this->registerClientResponse(
$api->remove($attachmentId),
$api->getLastResponse()
);
}
}
42 changes: 42 additions & 0 deletions tests/Behat/Bootstrap/GroupContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,46 @@ public function iUpdateTheGroupWithIdWithTheFollowingData(int $groupId, TableNod
$api->getLastResponse()
);
}

/**
* @When I add the user with id :userId to the group with id :groupId
*/
public function iAddTheUserWithIdToTheGroupWithId($userId, $groupId)
{
/** @var Group */
$api = $this->getNativeCurlClient()->getApi('group');

$this->registerClientResponse(
$api->addUser($groupId, $userId),
$api->getLastResponse()
);
}

/**
* @When I remove the user with id :userId from the group with id :groupId
*/
public function iRemoveTheUserWithIdFromTheGroupWithId($userId, $groupId)
{
/** @var Group */
$api = $this->getNativeCurlClient()->getApi('group');

$this->registerClientResponse(
$api->removeUser($groupId, $userId),
$api->getLastResponse()
);
}

/**
* @When I remove the group with id :groupId
*/
public function iRemoveTheGroupWithId($groupId)
{
/** @var Group */
$api = $this->getNativeCurlClient()->getApi('group');

$this->registerClientResponse(
$api->remove($groupId),
$api->getLastResponse()
);
}
}
14 changes: 14 additions & 0 deletions tests/Behat/Bootstrap/IssueCategoryContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@ public function iUpdateTheIssueCategoryWithIdAndTheFollowingData($id, TableNode
$api->getLastResponse()
);
}

/**
* @When I remove the issue category with id :id
*/
public function iRemoveTheIssueCategoryWithId($id)
{
/** @var IssueCategory */
$api = $this->getNativeCurlClient()->getApi('issue_category');

$this->registerClientResponse(
$api->remove($id),
$api->getLastResponse()
);
}
}
42 changes: 42 additions & 0 deletions tests/Behat/Bootstrap/IssueContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,46 @@ public function iShowTheIssueWithId($issueId)
$api->getLastResponse()
);
}

/**
* @When I add the user id :userId as a watcher to the issue with id :issueId
*/
public function iAddTheUserIdAsAWatcherToTheIssueWithId($userId, $issueId)
{
/** @var Issue */
$api = $this->getNativeCurlClient()->getApi('issue');

$this->registerClientResponse(
$api->addWatcher($issueId, $userId),
$api->getLastResponse()
);
}

/**
* @When I remove the user id :userId as a watcher from the issue with id :issueId
*/
public function iRemoveTheUserIdAsAWatcherFromTheIssueWithId($userId, $issueId)
{
/** @var Issue */
$api = $this->getNativeCurlClient()->getApi('issue');

$this->registerClientResponse(
$api->removeWatcher($issueId, $userId),
$api->getLastResponse()
);
}

/**
* @When I remove the issue with id :issueId
*/
public function iRemoveTheIssueWithId($issueId)
{
/** @var Issue */
$api = $this->getNativeCurlClient()->getApi('issue');

$this->registerClientResponse(
$api->remove($issueId),
$api->getLastResponse()
);
}
}
Loading

0 comments on commit e340e09

Please sign in to comment.