Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate all Redmine\Api\*::getIdBy...() methods #422

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f6a3d5c
extract CustomField::listing()
Art4 Jul 8, 2024
10768a9
Deprecate CustomField::getIdByName()
Art4 Jul 8, 2024
f09ec28
extract IssueCategory::listing()
Art4 Jul 8, 2024
71655dc
Replace IssueCategory::getIdByName() with listNamesByProject()
Art4 Jul 8, 2024
5cc6d37
Merge branch 'v2.x' into 417-deprecate-all-redmineapigetidbyname-methods
Art4 Jul 8, 2024
2edd582
fix tests
Art4 Jul 8, 2024
0f8257a
Fix support with PHPUnit 9
Art4 Jul 8, 2024
0142a0c
Deprecate IssueCategory::getIdByName()
Art4 Jul 9, 2024
3194e30
Extract IssueStatus::listing()
Art4 Jul 9, 2024
057de97
Replace IssueStatus::getIdByName() with IssueStatus::listNames()
Art4 Jul 9, 2024
56bdb6b
Deprecate IssueStatus::getIdByName()
Art4 Jul 9, 2024
aa78b81
Update CHANGELOG.md
Art4 Jul 9, 2024
516115e
Extract Project::listing()
Art4 Jul 9, 2024
4dddac4
Replace Project::getIdByName() with listNames()
Art4 Jul 9, 2024
97fa124
Deprecate Project::getIdByName()
Art4 Jul 9, 2024
60d4b07
Extract TimeEntryActivity::listing()
Art4 Jul 9, 2024
8132e67
Deprecate TimeEntryActivity::getIdByName()
Art4 Jul 9, 2024
70f385b
Extract Tracker::listing()
Art4 Jul 9, 2024
b1e725a
Replace Tracker::getIdByName() with Tracker::listNames()
Art4 Jul 9, 2024
1bacd63
Deprecate Tracker::getIdByName()
Art4 Jul 9, 2024
057a289
Extract User::listing()
Art4 Jul 9, 2024
5913938
Replace User::getIdByUsername() with User::listLogins()
Art4 Jul 9, 2024
4441921
Deprecate User::getIdByUsername()
Art4 Jul 9, 2024
64e8df4
Extract Version::listing()
Art4 Jul 9, 2024
b11e318
Deprecate Version::getIdByName()
Art4 Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated

- `Redmine\Api\CustomField::listing()` is deprecated, use `\Redmine\Api\CustomField::listNames()` instead.
- `Redmine\Api\CustomField::getIdByName()` is deprecated, use `\Redmine\Api\CustomField::listNames()` instead.
- `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead.
- `Redmine\Api\IssueCategory::listing()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead.
- `Redmine\Api\IssueCategory::getIdByName()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead.
- `Redmine\Api\IssueStatus::listing()` is deprecated, use `\Redmine\Api\IssueStatus::listNames()` instead.
- `Redmine\Api\IssueStatus::getIdByName()` is deprecated, use `\Redmine\Api\IssueStatus::listNames()` instead.
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNames()` instead.
- `Redmine\Api\Project::getIdByName()` is deprecated, use `\Redmine\Api\Project::listNames()` instead.
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNames()` instead.
- `Redmine\Api\TimeEntryActivity::listing()` is deprecated, use `\Redmine\Api\TimeEntryActivity::listNames()` instead.
- `Redmine\Api\TimeEntryActivity::getIdByName()` is deprecated, use `\Redmine\Api\TimeEntryActivity::listNames()` instead.
- `Redmine\Api\Tracker::listing()` is deprecated, use `\Redmine\Api\Tracker::listNames()` instead.
- `Redmine\Api\Tracker::getIdByName()` is deprecated, use `\Redmine\Api\Tracker::listNames()` instead.
- `Redmine\Api\User::listing()` is deprecated, use `\Redmine\Api\User::listLogins()` instead.
- `Redmine\Api\User::getIdByUsername()` is deprecated, use `\Redmine\Api\User::listLogins()` instead.
- `Redmine\Api\Version::listing()` is deprecated, use `\Redmine\Api\Version::listNamesByProject()` instead.
- `Redmine\Api\Version::getIdByName()` is deprecated, use `\Redmine\Api\Version::listNamesByProject()` instead.

## [v2.6.0](https://github.com/kbsali/php-redmine-api/compare/v2.5.0...v2.6.0) - 2024-03-25

Expand Down
35 changes: 24 additions & 11 deletions src/Redmine/Api/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,14 @@ public function listing($forceUpdate = false, array $params = [])
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

if (empty($this->customFields) || $forceUpdate) {
$this->customFields = $this->list($params);
}
$ret = [];
foreach ($this->customFields['custom_fields'] as $e) {
$ret[$e['name']] = (int) $e['id'];
}

return $ret;
return $this->doListing($forceUpdate, $params);
}

/**
* Get a tracket id given its name.
* Get a custom field id given its name.
*
* @deprecated v2.7.0 Use listNames() instead.
* @see CustomField::listNames()
*
* @param string|int $name customer field name
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
Expand All @@ -132,11 +127,29 @@ public function listing($forceUpdate = false, array $params = [])
*/
public function getIdByName($name, array $params = [])
{
$arr = $this->listing(false, $params);
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

$arr = $this->doListing(false, $params);

if (!isset($arr[$name])) {
return false;
}

return $arr[(string) $name];
}

private function doListing(bool $forceUpdate, array $params)
{
if (empty($this->customFields) || $forceUpdate) {
$this->customFields = $this->list($params);
}

$ret = [];

foreach ($this->customFields['custom_fields'] as $e) {
$ret[$e['name']] = (int) $e['id'];
}

return $ret;
}
}
39 changes: 32 additions & 7 deletions src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function setIssueStatus($id, $status)
$issueStatusApi = $this->getIssueStatusApi();

return $this->update($id, [
'status_id' => $issueStatusApi->getIdByName($status),
'status_id' => array_search($status, $issueStatusApi->listNames(), true),
]);
}

Expand Down Expand Up @@ -348,42 +348,67 @@ private function cleanParams(array $params = [])
if (isset($params['project'])) {
$projectApi = $this->getProjectApi();

$params['project_id'] = $projectApi->getIdByName($params['project']);
// TODO: project names are not unique; there could be collisions
$params['project_id'] = array_search(
$params['project'],
$projectApi->listNames(),
true,
);
unset($params['project']);
}

if (isset($params['category']) && isset($params['project_id'])) {
$issueCategoryApi = $this->getIssueCategoryApi();

$params['category_id'] = $issueCategoryApi->getIdByName($params['project_id'], $params['category']);
$params['category_id'] = array_search(
$params['category'],
$issueCategoryApi->listNamesByProject($params['project_id']),
true,
);
unset($params['category']);
}

if (isset($params['status'])) {
$issueStatusApi = $this->getIssueStatusApi();

$params['status_id'] = $issueStatusApi->getIdByName($params['status']);
$params['status_id'] = array_search(
$params['status'],
$issueStatusApi->listNames(),
true,
);
unset($params['status']);
}

if (isset($params['tracker'])) {
$trackerApi = $this->getTrackerApi();

$params['tracker_id'] = $trackerApi->getIdByName($params['tracker']);
$params['tracker_id'] = array_search(
$params['tracker'],
$trackerApi->listNames(),
true,
);
unset($params['tracker']);
}

if (isset($params['assigned_to'])) {
$userApi = $this->getUserApi();

$params['assigned_to_id'] = $userApi->getIdByUsername($params['assigned_to']);
$params['assigned_to_id'] = array_search(
$params['assigned_to'],
$userApi->listLogins(),
true,
);
unset($params['assigned_to']);
}

if (isset($params['author'])) {
$userApi = $this->getUserApi();

$params['author_id'] = $userApi->getIdByUsername($params['author']);
$params['author_id'] = array_search(
$params['author'],
$userApi->listLogins(),
true,
);
unset($params['author']);
}

Expand Down
33 changes: 23 additions & 10 deletions src/Redmine/Api/IssueCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,26 @@ public function listing($project, $forceUpdate = false)
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED);

if (true === $forceUpdate || empty($this->issueCategories)) {
$this->issueCategories = $this->listByProject($project);
}
$ret = [];
foreach ($this->issueCategories['issue_categories'] as $e) {
$ret[$e['name']] = (int) $e['id'];
}

return $ret;
return $this->doListing($project, $forceUpdate);
}

/**
* Get a category id given its name and related project.
*
* @deprecated v2.7.0 Use listNamesByProject() instead.
* @see IssueCategory::listNamesByProject()
*
* @param string|int $project project id or literal identifier
* @param string $name
*
* @return int|false
*/
public function getIdByName($project, $name)
{
$arr = $this->listing($project);
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED);

$arr = $this->doListing($project, false);

if (!isset($arr[$name])) {
return false;
}
Expand Down Expand Up @@ -283,4 +281,19 @@ public function remove($id, array $params = [])

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

private function doListing($project, bool $forceUpdate)
{
if (true === $forceUpdate || empty($this->issueCategories)) {
$this->issueCategories = $this->listByProject($project);
}

$ret = [];

foreach ($this->issueCategories['issue_categories'] as $e) {
$ret[$e['name']] = (int) $e['id'];
}

return $ret;
}
}
33 changes: 23 additions & 10 deletions src/Redmine/Api/IssueStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,44 @@ public function listing($forceUpdate = false)
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

if (empty($this->issueStatuses) || $forceUpdate) {
$this->issueStatuses = $this->list();
}
$ret = [];
foreach ($this->issueStatuses['issue_statuses'] as $e) {
$ret[$e['name']] = (int) $e['id'];
}

return $ret;
return $this->doListing($forceUpdate);
}

/**
* Get a status id given its name.
*
* @deprecated v2.7.0 Use listNames() instead.
* @see IssueStatus::listNames()
*
* @param string $name
*
* @return int|false
*/
public function getIdByName($name)
{
$arr = $this->listing();
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

$arr = $this->doListing(false);

if (!isset($arr[$name])) {
return false;
}

return $arr[(string) $name];
}

private function doListing(bool $forceUpdate)
{
if (empty($this->issueStatuses) || $forceUpdate) {
$this->issueStatuses = $this->list();
}

$ret = [];

foreach ($this->issueStatuses['issue_statuses'] as $e) {
$ret[$e['name']] = (int) $e['id'];
}

return $ret;
}
}
33 changes: 23 additions & 10 deletions src/Redmine/Api/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,26 @@ public function listing($forceUpdate = false, $reverse = true, array $params = [
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

if (true === $forceUpdate || empty($this->projects)) {
$this->projects = $this->list($params);
}
$ret = [];
foreach ($this->projects['projects'] as $e) {
$ret[(int) $e['id']] = $e['name'];
}

return $reverse ? array_flip($ret) : $ret;
return $this->doListing($forceUpdate, $reverse, $params);
}

/**
* Get a project id given its name.
*
* @deprecated v2.7.0 Use listNames() instead.
* @see Project::listNames()
*
* @param string $name
* @param array $params to allow offset/limit (and more) to be passed
*
* @return int|bool
*/
public function getIdByName($name, array $params = [])
{
$arr = $this->listing(false, true, $params);
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

$arr = $this->doListing(false, true, $params);

if (!isset($arr[$name])) {
return false;
}
Expand Down Expand Up @@ -447,4 +445,19 @@ public function remove($id)

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

private function doListing(bool $forceUpdate, bool $reverse, array $params)
{
if (true === $forceUpdate || empty($this->projects)) {
$this->projects = $this->list($params);
}

$ret = [];

foreach ($this->projects['projects'] as $e) {
$ret[(int) $e['id']] = $e['name'];
}

return $reverse ? array_flip($ret) : $ret;
}
}
33 changes: 23 additions & 10 deletions src/Redmine/Api/TimeEntryActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,44 @@ public function listing($forceUpdate = false)
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

if (empty($this->timeEntryActivities) || $forceUpdate) {
$this->timeEntryActivities = $this->list();
}
$ret = [];
foreach ($this->timeEntryActivities['time_entry_activities'] as $e) {
$ret[$e['name']] = (int) $e['id'];
}

return $ret;
return $this->doListing((bool) $forceUpdate);
}

/**
* Get a activities id given its name.
*
* @deprecated v2.7.0 Use listNames() instead.
* @see Project::listNames()
*
* @param string $name
*
* @return int|false
*/
public function getIdByName($name)
{
$arr = $this->listing();
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

$arr = $this->doListing(false);

if (!isset($arr[$name])) {
return false;
}

return $arr[(string) $name];
}

private function doListing(bool $forceUpdate)
{
if (empty($this->timeEntryActivities) || $forceUpdate) {
$this->timeEntryActivities = $this->list();
}

$ret = [];

foreach ($this->timeEntryActivities['time_entry_activities'] as $e) {
$ret[$e['name']] = (int) $e['id'];
}

return $ret;
}
}
Loading
Loading