Skip to content

Commit ad68956

Browse files
authored
Draft: Fix search (#555)
* Fix PHP syntax error * Use correct result class for returning results from search We need to switch back to IssueSearchResult, as it contains sthe nextPageToken which is required for paged searches. * Add searchApproximateCount as the new search endpoint does not provide that info anymore
1 parent 2e79233 commit ad68956

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

src/Issue/IssueSearchResult.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Created by PhpStorm.
45
* User: keanor
@@ -82,7 +83,7 @@ public function getIssue($ndx)
8283
/**
8384
* @return ?string
8485
*/
85-
public function getExpand() : ?$string
86+
public function getExpand(): ?string
8687
{
8788
return $this->expand;
8889
}

src/Issue/IssueService.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public function transition($issueIdOrKey, $transition): ?string
534534
*
535535
* @return IssueSearchResult
536536
*/
537-
public function search(string $jql, string $nextPageToken = '', int $maxResults = 50, array $fields = [], string $expand = '', array $reconcileIssues = []): IssueBulkResult
537+
public function search(string $jql, string $nextPageToken = '', int $maxResults = 50, array $fields = [], string $expand = '', array $reconcileIssues = []): IssueSearchResult
538538
{
539539
$data = [
540540
'jql' => $jql,
@@ -548,12 +548,39 @@ public function search(string $jql, string $nextPageToken = '', int $maxResults
548548
$data['nextPageToken'] = $nextPageToken;
549549
}
550550

551-
$ret = $this->exec('search//jql', json_encode($data), 'POST');
551+
$ret = $this->exec('search/jql', json_encode($data), 'POST');
552552
$json = json_decode($ret);
553553

554554
$result = $this->json_mapper->map(
555555
$json,
556-
new IssueBulkResult()
556+
new IssueSearchResult()
557+
);
558+
559+
return $result;
560+
}
561+
562+
/**
563+
* Get an approximate count of issues that match a JQL query.
564+
*
565+
* @param string $jql The JQL query string
566+
*
567+
* @throws \JsonMapper_Exception
568+
* @throws JiraException
569+
*
570+
* @return JQLCountResult
571+
*/
572+
public function searchApproximateCount(string $jql): JQLCountResult
573+
{
574+
$data = [
575+
'jql' => $jql,
576+
];
577+
578+
$ret = $this->exec('search/approximate-count', json_encode($data), 'POST');
579+
$json = json_decode($ret);
580+
581+
$result = $this->json_mapper->map(
582+
$json,
583+
new JQLCountResult()
557584
);
558585

559586
return $result;

src/Issue/JQLCountResult.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace JiraRestApi\Issue;
4+
5+
/**
6+
* JQL Count result for approximate count API.
7+
*/
8+
class JQLCountResult implements \JsonSerializable
9+
{
10+
/**
11+
* @var int The approximate count of issues matching the JQL query
12+
*/
13+
public int $count;
14+
15+
/**
16+
* Get the count of issues.
17+
*
18+
* @return int
19+
*/
20+
public function getCount(): int
21+
{
22+
return $this->count;
23+
}
24+
25+
/**
26+
* Set the count of issues.
27+
*
28+
* @param int $count
29+
*/
30+
public function setCount(int $count): void
31+
{
32+
$this->count = $count;
33+
}
34+
35+
#[\ReturnTypeWillChange]
36+
public function jsonSerialize(): array
37+
{
38+
return [
39+
'count' => $this->count
40+
];
41+
}
42+
}

0 commit comments

Comments
 (0)