Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / auth / query / PhabricatorAuthSessionQuery.php
blob00a663e964a92ff4005e8b4ae058f600e52787dd
1 <?php
3 final class PhabricatorAuthSessionQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $identityPHIDs;
9 private $sessionKeys;
10 private $sessionTypes;
12 public function withIdentityPHIDs(array $identity_phids) {
13 $this->identityPHIDs = $identity_phids;
14 return $this;
17 public function withSessionKeys(array $keys) {
18 $this->sessionKeys = $keys;
19 return $this;
22 public function withSessionTypes(array $types) {
23 $this->sessionTypes = $types;
24 return $this;
27 public function withIDs(array $ids) {
28 $this->ids = $ids;
29 return $this;
32 public function withPHIDs(array $phids) {
33 $this->phids = $phids;
34 return $this;
37 public function newResultObject() {
38 return new PhabricatorAuthSession();
41 protected function loadPage() {
42 return $this->loadStandardPage($this->newResultObject());
45 protected function willFilterPage(array $sessions) {
46 $identity_phids = mpull($sessions, 'getUserPHID');
48 $identity_objects = id(new PhabricatorObjectQuery())
49 ->setViewer($this->getViewer())
50 ->setParentQuery($this)
51 ->withPHIDs($identity_phids)
52 ->execute();
53 $identity_objects = mpull($identity_objects, null, 'getPHID');
55 foreach ($sessions as $key => $session) {
56 $identity_object = idx($identity_objects, $session->getUserPHID());
57 if (!$identity_object) {
58 unset($sessions[$key]);
59 } else {
60 $session->attachIdentityObject($identity_object);
64 return $sessions;
67 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
68 $where = parent::buildWhereClauseParts($conn);
70 if ($this->ids !== null) {
71 $where[] = qsprintf(
72 $conn,
73 'id IN (%Ld)',
74 $this->ids);
77 if ($this->phids !== null) {
78 $where[] = qsprintf(
79 $conn,
80 'phid IN (%Ls)',
81 $this->phids);
84 if ($this->identityPHIDs !== null) {
85 $where[] = qsprintf(
86 $conn,
87 'userPHID IN (%Ls)',
88 $this->identityPHIDs);
91 if ($this->sessionKeys !== null) {
92 $hashes = array();
93 foreach ($this->sessionKeys as $session_key) {
94 $hashes[] = PhabricatorAuthSession::newSessionDigest(
95 new PhutilOpaqueEnvelope($session_key));
97 $where[] = qsprintf(
98 $conn,
99 'sessionKey IN (%Ls)',
100 $hashes);
103 if ($this->sessionTypes !== null) {
104 $where[] = qsprintf(
105 $conn,
106 'type IN (%Ls)',
107 $this->sessionTypes);
110 return $where;
113 public function getQueryApplicationClass() {
114 return 'PhabricatorAuthApplication';