Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/query/PhabricatorAuthSessionQuery.php
12262 views
1
<?php
2
3
final class PhabricatorAuthSessionQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $identityPHIDs;
9
private $sessionKeys;
10
private $sessionTypes;
11
12
public function withIdentityPHIDs(array $identity_phids) {
13
$this->identityPHIDs = $identity_phids;
14
return $this;
15
}
16
17
public function withSessionKeys(array $keys) {
18
$this->sessionKeys = $keys;
19
return $this;
20
}
21
22
public function withSessionTypes(array $types) {
23
$this->sessionTypes = $types;
24
return $this;
25
}
26
27
public function withIDs(array $ids) {
28
$this->ids = $ids;
29
return $this;
30
}
31
32
public function withPHIDs(array $phids) {
33
$this->phids = $phids;
34
return $this;
35
}
36
37
public function newResultObject() {
38
return new PhabricatorAuthSession();
39
}
40
41
protected function willFilterPage(array $sessions) {
42
$identity_phids = mpull($sessions, 'getUserPHID');
43
44
$identity_objects = id(new PhabricatorObjectQuery())
45
->setViewer($this->getViewer())
46
->setParentQuery($this)
47
->withPHIDs($identity_phids)
48
->execute();
49
$identity_objects = mpull($identity_objects, null, 'getPHID');
50
51
foreach ($sessions as $key => $session) {
52
$identity_object = idx($identity_objects, $session->getUserPHID());
53
if (!$identity_object) {
54
unset($sessions[$key]);
55
} else {
56
$session->attachIdentityObject($identity_object);
57
}
58
}
59
60
return $sessions;
61
}
62
63
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
64
$where = parent::buildWhereClauseParts($conn);
65
66
if ($this->ids !== null) {
67
$where[] = qsprintf(
68
$conn,
69
'id IN (%Ld)',
70
$this->ids);
71
}
72
73
if ($this->phids !== null) {
74
$where[] = qsprintf(
75
$conn,
76
'phid IN (%Ls)',
77
$this->phids);
78
}
79
80
if ($this->identityPHIDs !== null) {
81
$where[] = qsprintf(
82
$conn,
83
'userPHID IN (%Ls)',
84
$this->identityPHIDs);
85
}
86
87
if ($this->sessionKeys !== null) {
88
$hashes = array();
89
foreach ($this->sessionKeys as $session_key) {
90
$hashes[] = PhabricatorAuthSession::newSessionDigest(
91
new PhutilOpaqueEnvelope($session_key));
92
}
93
$where[] = qsprintf(
94
$conn,
95
'sessionKey IN (%Ls)',
96
$hashes);
97
}
98
99
if ($this->sessionTypes !== null) {
100
$where[] = qsprintf(
101
$conn,
102
'type IN (%Ls)',
103
$this->sessionTypes);
104
}
105
106
return $where;
107
}
108
109
public function getQueryApplicationClass() {
110
return 'PhabricatorAuthApplication';
111
}
112
113
}
114
115