@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorAuthTemporaryToken>
5 */
6final class PhabricatorAuthTemporaryTokenQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $tokenResources;
11 private $tokenTypes;
12 private $userPHIDs;
13 private $expired;
14 private $tokenCodes;
15
16 public function withIDs(array $ids) {
17 $this->ids = $ids;
18 return $this;
19 }
20
21 public function withTokenResources(array $resources) {
22 $this->tokenResources = $resources;
23 return $this;
24 }
25
26 public function withTokenTypes(array $types) {
27 $this->tokenTypes = $types;
28 return $this;
29 }
30
31 public function withExpired($expired) {
32 $this->expired = $expired;
33 return $this;
34 }
35
36 public function withTokenCodes(array $codes) {
37 $this->tokenCodes = $codes;
38 return $this;
39 }
40
41 public function withUserPHIDs(array $phids) {
42 $this->userPHIDs = $phids;
43 return $this;
44 }
45
46 public function newResultObject() {
47 return new PhabricatorAuthTemporaryToken();
48 }
49
50 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
51 $where = parent::buildWhereClauseParts($conn);
52
53 if ($this->ids !== null) {
54 $where[] = qsprintf(
55 $conn,
56 'id IN (%Ld)',
57 $this->ids);
58 }
59
60 if ($this->tokenResources !== null) {
61 $where[] = qsprintf(
62 $conn,
63 'tokenResource IN (%Ls)',
64 $this->tokenResources);
65 }
66
67 if ($this->tokenTypes !== null) {
68 $where[] = qsprintf(
69 $conn,
70 'tokenType IN (%Ls)',
71 $this->tokenTypes);
72 }
73
74 if ($this->expired !== null) {
75 if ($this->expired) {
76 $where[] = qsprintf(
77 $conn,
78 'tokenExpires <= %d',
79 time());
80 } else {
81 $where[] = qsprintf(
82 $conn,
83 'tokenExpires > %d',
84 time());
85 }
86 }
87
88 if ($this->tokenCodes !== null) {
89 $where[] = qsprintf(
90 $conn,
91 'tokenCode IN (%Ls)',
92 $this->tokenCodes);
93 }
94
95 if ($this->userPHIDs !== null) {
96 $where[] = qsprintf(
97 $conn,
98 'userPHID IN (%Ls)',
99 $this->userPHIDs);
100 }
101
102 return $where;
103 }
104
105 public function getQueryApplicationClass() {
106 return PhabricatorAuthApplication::class;
107 }
108
109}