Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conduit/query/PhabricatorConduitTokenQuery.php
12256 views
1
<?php
2
3
final class PhabricatorConduitTokenQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $objectPHIDs;
8
private $expired;
9
private $tokens;
10
private $tokenTypes;
11
12
public function withExpired($expired) {
13
$this->expired = $expired;
14
return $this;
15
}
16
17
public function withIDs(array $ids) {
18
$this->ids = $ids;
19
return $this;
20
}
21
22
public function withObjectPHIDs(array $phids) {
23
$this->objectPHIDs = $phids;
24
return $this;
25
}
26
27
public function withTokens(array $tokens) {
28
$this->tokens = $tokens;
29
return $this;
30
}
31
32
public function withTokenTypes(array $types) {
33
$this->tokenTypes = $types;
34
return $this;
35
}
36
37
public function newResultObject() {
38
return new PhabricatorConduitToken();
39
}
40
41
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
42
$where = parent::buildWhereClauseParts($conn);
43
44
if ($this->ids !== null) {
45
$where[] = qsprintf(
46
$conn,
47
'id IN (%Ld)',
48
$this->ids);
49
}
50
51
if ($this->objectPHIDs !== null) {
52
$where[] = qsprintf(
53
$conn,
54
'objectPHID IN (%Ls)',
55
$this->objectPHIDs);
56
}
57
58
if ($this->tokens !== null) {
59
$where[] = qsprintf(
60
$conn,
61
'token IN (%Ls)',
62
$this->tokens);
63
}
64
65
if ($this->tokenTypes !== null) {
66
$where[] = qsprintf(
67
$conn,
68
'tokenType IN (%Ls)',
69
$this->tokenTypes);
70
}
71
72
if ($this->expired !== null) {
73
if ($this->expired) {
74
$where[] = qsprintf(
75
$conn,
76
'expires <= %d',
77
PhabricatorTime::getNow());
78
} else {
79
$where[] = qsprintf(
80
$conn,
81
'expires IS NULL OR expires > %d',
82
PhabricatorTime::getNow());
83
}
84
}
85
86
return $where;
87
}
88
89
protected function willFilterPage(array $tokens) {
90
$object_phids = mpull($tokens, 'getObjectPHID');
91
$objects = id(new PhabricatorObjectQuery())
92
->setViewer($this->getViewer())
93
->setParentQuery($this)
94
->withPHIDs($object_phids)
95
->execute();
96
$objects = mpull($objects, null, 'getPHID');
97
98
foreach ($tokens as $key => $token) {
99
$object = idx($objects, $token->getObjectPHID(), null);
100
if (!$object) {
101
$this->didRejectResult($token);
102
unset($tokens[$key]);
103
continue;
104
}
105
$token->attachObject($object);
106
}
107
108
return $tokens;
109
}
110
111
public function getQueryApplicationClass() {
112
return 'PhabricatorConduitApplication';
113
}
114
115
}
116
117