Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / tokens / query / PhabricatorTokenGivenQuery.php
blobb4a86428c122ecfb59cc0428097aa67ed0fd1473
1 <?php
3 final class PhabricatorTokenGivenQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $authorPHIDs;
7 private $objectPHIDs;
8 private $tokenPHIDs;
10 public function withTokenPHIDs(array $token_phids) {
11 $this->tokenPHIDs = $token_phids;
12 return $this;
15 public function withObjectPHIDs(array $object_phids) {
16 $this->objectPHIDs = $object_phids;
17 return $this;
20 public function withAuthorPHIDs(array $author_phids) {
21 $this->authorPHIDs = $author_phids;
22 return $this;
25 public function newResultObject() {
26 return new PhabricatorTokenGiven();
29 protected function loadPage() {
30 return $this->loadStandardPage($this->newResultObject());
33 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
34 $where = parent::buildWhereClauseParts($conn);
36 if ($this->authorPHIDs !== null) {
37 $where[] = qsprintf(
38 $conn,
39 'authorPHID IN (%Ls)',
40 $this->authorPHIDs);
43 if ($this->objectPHIDs !== null) {
44 $where[] = qsprintf(
45 $conn,
46 'objectPHID IN (%Ls)',
47 $this->objectPHIDs);
50 if ($this->tokenPHIDs !== null) {
51 $where[] = qsprintf(
52 $conn,
53 'tokenPHID IN (%Ls)',
54 $this->tokenPHIDs);
57 return $where;
60 protected function willFilterPage(array $results) {
61 $viewer = $this->getViewer();
63 $object_phids = mpull($results, 'getObjectPHID');
65 $objects = id(new PhabricatorObjectQuery())
66 ->setViewer($viewer)
67 ->withPHIDs($object_phids)
68 ->execute();
69 $objects = mpull($objects, null, 'getPHID');
71 foreach ($results as $key => $result) {
72 $object = idx($objects, $result->getObjectPHID());
74 if ($object) {
75 if ($object instanceof PhabricatorTokenReceiverInterface) {
76 $result->attachObject($object);
77 continue;
81 $this->didRejectResult($result);
82 unset($results[$key]);
85 if (!$results) {
86 return $results;
89 $token_phids = mpull($results, 'getTokenPHID');
91 $tokens = id(new PhabricatorTokenQuery())
92 ->setViewer($viewer)
93 ->withPHIDs($token_phids)
94 ->execute();
95 $tokens = mpull($tokens, null, 'getPHID');
97 foreach ($results as $key => $result) {
98 $token_phid = $result->getTokenPHID();
100 $token = idx($tokens, $token_phid);
101 if (!$token) {
102 $this->didRejectResult($result);
103 unset($results[$key]);
104 continue;
107 $result->attachToken($token);
110 return $results;
113 public function getQueryApplicationClass() {
114 return 'PhabricatorTokensApplication';