Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / conduit / query / PhabricatorConduitTokenQuery.php
blobef35b006a7becff48b576d6a66d28557c4f9fa6d
1 <?php
3 final class PhabricatorConduitTokenQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $objectPHIDs;
8 private $expired;
9 private $tokens;
10 private $tokenTypes;
12 public function withExpired($expired) {
13 $this->expired = $expired;
14 return $this;
17 public function withIDs(array $ids) {
18 $this->ids = $ids;
19 return $this;
22 public function withObjectPHIDs(array $phids) {
23 $this->objectPHIDs = $phids;
24 return $this;
27 public function withTokens(array $tokens) {
28 $this->tokens = $tokens;
29 return $this;
32 public function withTokenTypes(array $types) {
33 $this->tokenTypes = $types;
34 return $this;
37 public function newResultObject() {
38 return new PhabricatorConduitToken();
41 protected function loadPage() {
42 return $this->loadStandardPage($this->newResultObject());
45 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
46 $where = parent::buildWhereClauseParts($conn);
48 if ($this->ids !== null) {
49 $where[] = qsprintf(
50 $conn,
51 'id IN (%Ld)',
52 $this->ids);
55 if ($this->objectPHIDs !== null) {
56 $where[] = qsprintf(
57 $conn,
58 'objectPHID IN (%Ls)',
59 $this->objectPHIDs);
62 if ($this->tokens !== null) {
63 $where[] = qsprintf(
64 $conn,
65 'token IN (%Ls)',
66 $this->tokens);
69 if ($this->tokenTypes !== null) {
70 $where[] = qsprintf(
71 $conn,
72 'tokenType IN (%Ls)',
73 $this->tokenTypes);
76 if ($this->expired !== null) {
77 if ($this->expired) {
78 $where[] = qsprintf(
79 $conn,
80 'expires <= %d',
81 PhabricatorTime::getNow());
82 } else {
83 $where[] = qsprintf(
84 $conn,
85 'expires IS NULL OR expires > %d',
86 PhabricatorTime::getNow());
90 return $where;
93 protected function willFilterPage(array $tokens) {
94 $object_phids = mpull($tokens, 'getObjectPHID');
95 $objects = id(new PhabricatorObjectQuery())
96 ->setViewer($this->getViewer())
97 ->setParentQuery($this)
98 ->withPHIDs($object_phids)
99 ->execute();
100 $objects = mpull($objects, null, 'getPHID');
102 foreach ($tokens as $key => $token) {
103 $object = idx($objects, $token->getObjectPHID(), null);
104 if (!$object) {
105 $this->didRejectResult($token);
106 unset($tokens[$key]);
107 continue;
109 $token->attachObject($object);
112 return $tokens;
115 public function getQueryApplicationClass() {
116 return 'PhabricatorConduitApplication';