Skip to content

Commit 6f0a512

Browse files
authored
Merge pull request #354 from kbsali/353-do-not-use-temporary-cache-in-redmineapilist-methods
Do not use temporary cache in `Redmine\Api\...::list()` methods
2 parents c132efc + 77e3adc commit 6f0a512

18 files changed

+81
-85
lines changed

src/Redmine/Api/CustomField.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ class CustomField extends AbstractApi
3131
final public function list(array $params = []): array
3232
{
3333
try {
34-
$this->customFields = $this->retrieveData('/custom_fields.json', $params);
34+
return $this->retrieveData('/custom_fields.json', $params);
3535
} catch (SerializerException $th) {
3636
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
3737
}
38-
39-
return $this->customFields;
4038
}
4139

4240
/**
@@ -55,7 +53,7 @@ public function all(array $params = [])
5553
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);
5654

5755
try {
58-
return $this->list($params);
56+
$this->customFields = $this->list($params);
5957
} catch (Exception $e) {
6058
if ($this->client->getLastResponseBody() === '') {
6159
return false;
@@ -67,6 +65,8 @@ public function all(array $params = [])
6765

6866
return $e->getMessage();
6967
}
68+
69+
return $this->customFields;
7070
}
7171

7272
/**
@@ -80,7 +80,7 @@ public function all(array $params = [])
8080
public function listing($forceUpdate = false, array $params = [])
8181
{
8282
if (empty($this->customFields) || $forceUpdate) {
83-
$this->list($params);
83+
$this->customFields = $this->list($params);
8484
}
8585
$ret = [];
8686
foreach ($this->customFields['custom_fields'] as $e) {

src/Redmine/Api/Group.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ class Group extends AbstractApi
3434
final public function list(array $params = []): array
3535
{
3636
try {
37-
$this->groups = $this->retrieveData('/groups.json', $params);
37+
return $this->retrieveData('/groups.json', $params);
3838
} catch (SerializerException $th) {
3939
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
4040
}
41-
42-
return $this->groups;
4341
}
4442

4543
/**
@@ -58,7 +56,7 @@ public function all(array $params = [])
5856
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);
5957

6058
try {
61-
return $this->list($params);
59+
$this->groups = $this->list($params);
6260
} catch (Exception $e) {
6361
if ($this->client->getLastResponseBody() === '') {
6462
return false;
@@ -70,6 +68,8 @@ public function all(array $params = [])
7068

7169
return $e->getMessage();
7270
}
71+
72+
return $this->groups;
7373
}
7474

7575
/**
@@ -82,7 +82,7 @@ public function all(array $params = [])
8282
public function listing($forceUpdate = false)
8383
{
8484
if (empty($this->groups) || $forceUpdate) {
85-
$this->list();
85+
$this->groups = $this->list();
8686
}
8787
$ret = [];
8888
foreach ($this->groups['groups'] as $e) {

src/Redmine/Api/IssueCategory.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ final public function listByProject($projectIdentifier, array $params = []): arr
4444
}
4545

4646
try {
47-
$this->issueCategories = $this->retrieveData('/projects/'.strval($projectIdentifier).'/issue_categories.json', $params);
47+
return $this->retrieveData('/projects/'.strval($projectIdentifier).'/issue_categories.json', $params);
4848
} catch (SerializerException $th) {
4949
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
5050
}
51-
52-
return $this->issueCategories;
5351
}
5452

5553
/**
@@ -94,7 +92,7 @@ public function all($project, array $params = [])
9492
public function listing($project, $forceUpdate = false)
9593
{
9694
if (true === $forceUpdate || empty($this->issueCategories)) {
97-
$this->listByProject($project);
95+
$this->issueCategories = $this->listByProject($project);
9896
}
9997
$ret = [];
10098
foreach ($this->issueCategories['issue_categories'] as $e) {

src/Redmine/Api/IssuePriority.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ class IssuePriority extends AbstractApi
3131
final public function list(array $params = []): array
3232
{
3333
try {
34-
$this->issuePriorities = $this->retrieveData('/enumerations/issue_priorities.json', $params);
34+
return $this->retrieveData('/enumerations/issue_priorities.json', $params);
3535
} catch (SerializerException $th) {
3636
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
3737
}
38-
39-
return $this->issuePriorities;
4038
}
4139

4240
/**
@@ -55,7 +53,7 @@ public function all(array $params = [])
5553
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);
5654

5755
try {
58-
return $this->list($params);
56+
$this->issuePriorities = $this->list($params);
5957
} catch (Exception $e) {
6058
if ($this->client->getLastResponseBody() === '') {
6159
return false;
@@ -67,5 +65,7 @@ public function all(array $params = [])
6765

6866
return $e->getMessage();
6967
}
68+
69+
return $this->issuePriorities;
7070
}
7171
}

src/Redmine/Api/IssueRelation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ class IssueRelation extends AbstractApi
3333
final public function listByIssueId(int $issueId, array $params = []): array
3434
{
3535
try {
36-
$this->relations = $this->retrieveData('/issues/'.strval($issueId).'/relations.json', $params);
36+
return $this->retrieveData('/issues/'.strval($issueId).'/relations.json', $params);
3737
} catch (SerializerException $th) {
3838
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
3939
}
40-
41-
return $this->relations;
4240
}
4341

4442
/**
@@ -58,7 +56,7 @@ public function all($issueId, array $params = [])
5856
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::listByIssueId()` instead.', E_USER_DEPRECATED);
5957

6058
try {
61-
return $this->listByIssueId($issueId, $params);
59+
$this->relations = $this->listByIssueId($issueId, $params);
6260
} catch (Exception $e) {
6361
if ($this->client->getLastResponseBody() === '') {
6462
return false;
@@ -70,6 +68,8 @@ public function all($issueId, array $params = [])
7068

7169
return $e->getMessage();
7270
}
71+
72+
return $this->relations;
7373
}
7474

7575
/**

src/Redmine/Api/IssueStatus.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ class IssueStatus extends AbstractApi
3131
final public function list(array $params = []): array
3232
{
3333
try {
34-
$this->issueStatuses = $this->retrieveData('/issue_statuses.json', $params);
34+
return $this->retrieveData('/issue_statuses.json', $params);
3535
} catch (SerializerException $th) {
3636
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
3737
}
38-
39-
return $this->issueStatuses;
4038
}
4139

4240
/**
@@ -55,7 +53,7 @@ public function all(array $params = [])
5553
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);
5654

5755
try {
58-
return $this->list($params);
56+
$this->issueStatuses = $this->list($params);
5957
} catch (Exception $e) {
6058
if ($this->client->getLastResponseBody() === '') {
6159
return false;
@@ -67,6 +65,8 @@ public function all(array $params = [])
6765

6866
return $e->getMessage();
6967
}
68+
69+
return $this->issueStatuses;
7070
}
7171

7272
/**
@@ -79,7 +79,7 @@ public function all(array $params = [])
7979
public function listing($forceUpdate = false)
8080
{
8181
if (empty($this->issueStatuses) || $forceUpdate) {
82-
$this->list();
82+
$this->issueStatuses = $this->list();
8383
}
8484
$ret = [];
8585
foreach ($this->issueStatuses['issue_statuses'] as $e) {

src/Redmine/Api/Membership.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ final public function listByProject($projectIdentifier, array $params = []): arr
4343
}
4444

4545
try {
46-
$this->memberships = $this->retrieveData('/projects/'.strval($projectIdentifier).'/memberships.json', $params);
46+
return $this->retrieveData('/projects/'.strval($projectIdentifier).'/memberships.json', $params);
4747
} catch (SerializerException $th) {
4848
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
4949
}
50-
51-
return $this->memberships;
5250
}
5351

5452
/**
@@ -68,7 +66,7 @@ public function all($project, array $params = [])
6866
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::listByProject()` instead.', E_USER_DEPRECATED);
6967

7068
try {
71-
return $this->listByProject(strval($project), $params);
69+
$this->memberships = $this->listByProject(strval($project), $params);
7270
} catch (Exception $e) {
7371
if ($this->client->getLastResponseBody() === '') {
7472
return false;
@@ -80,6 +78,8 @@ public function all($project, array $params = [])
8078

8179
return $e->getMessage();
8280
}
81+
82+
return $this->memberships;
8383
}
8484

8585
/**

src/Redmine/Api/News.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ final public function listByProject($projectIdentifier, array $params = []): arr
3939
}
4040

4141
try {
42-
$this->news = $this->retrieveData('/projects/'.strval($projectIdentifier).'/news.json', $params);
42+
return $this->retrieveData('/projects/'.strval($projectIdentifier).'/news.json', $params);
4343
} catch (SerializerException $th) {
4444
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
4545
}
46-
47-
return $this->news;
4846
}
4947

5048
/**
@@ -61,12 +59,10 @@ final public function listByProject($projectIdentifier, array $params = []): arr
6159
final public function list(array $params = []): array
6260
{
6361
try {
64-
$this->news = $this->retrieveData('/news.json', $params);
62+
return $this->retrieveData('/news.json', $params);
6563
} catch (SerializerException $th) {
6664
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
6765
}
68-
69-
return $this->news;
7066
}
7167

7268
/**
@@ -87,9 +83,9 @@ public function all($project = null, array $params = [])
8783

8884
try {
8985
if (null === $project) {
90-
return $this->list($params);
86+
$this->news = $this->list($params);
9187
} else {
92-
return $this->listByProject(strval($project), $params);
88+
$this->news = $this->listByProject(strval($project), $params);
9389
}
9490
} catch (Exception $e) {
9591
if ($this->client->getLastResponseBody() === '') {
@@ -102,5 +98,7 @@ public function all($project = null, array $params = [])
10298

10399
return $e->getMessage();
104100
}
101+
102+
return $this->news;
105103
}
106104
}

src/Redmine/Api/Project.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ class Project extends AbstractApi
3434
final public function list(array $params = []): array
3535
{
3636
try {
37-
$this->projects = $this->retrieveData('/projects.json', $params);
37+
return $this->retrieveData('/projects.json', $params);
3838
} catch (SerializerException $th) {
3939
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
4040
}
41-
42-
return $this->projects;
4341
}
4442

4543
/**
@@ -58,7 +56,7 @@ public function all(array $params = [])
5856
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);
5957

6058
try {
61-
return $this->list($params);
59+
$this->projects = $this->list($params);
6260
} catch (Exception $e) {
6361
if ($this->client->getLastResponseBody() === '') {
6462
return false;
@@ -70,6 +68,8 @@ public function all(array $params = [])
7068

7169
return $e->getMessage();
7270
}
71+
72+
return $this->projects;
7373
}
7474

7575
/**
@@ -84,7 +84,7 @@ public function all(array $params = [])
8484
public function listing($forceUpdate = false, $reverse = true, array $params = [])
8585
{
8686
if (true === $forceUpdate || empty($this->projects)) {
87-
$this->list($params);
87+
$this->projects = $this->list($params);
8888
}
8989
$ret = [];
9090
foreach ($this->projects['projects'] as $e) {

src/Redmine/Api/Query.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ class Query extends AbstractApi
3131
final public function list(array $params = []): array
3232
{
3333
try {
34-
$this->query = $this->retrieveData('/queries.json', $params);
34+
return $this->retrieveData('/queries.json', $params);
3535
} catch (SerializerException $th) {
3636
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
3737
}
38-
39-
return $this->query;
4038
}
4139

4240
/**
@@ -55,7 +53,7 @@ public function all(array $params = [])
5553
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);
5654

5755
try {
58-
return $this->list($params);
56+
$this->query = $this->list($params);
5957
} catch (Exception $e) {
6058
if ($this->client->getLastResponseBody() === '') {
6159
return false;
@@ -67,5 +65,7 @@ public function all(array $params = [])
6765

6866
return $e->getMessage();
6967
}
68+
69+
return $this->query;
7070
}
7171
}

0 commit comments

Comments
 (0)