Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/query/PhabricatorAuthSessionQuery.php
<?php | <?php | ||||
final class PhabricatorAuthSessionQuery | final class PhabricatorAuthSessionQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | |||||
private $identityPHIDs; | private $identityPHIDs; | ||||
private $sessionKeys; | private $sessionKeys; | ||||
private $sessionTypes; | private $sessionTypes; | ||||
public function withIdentityPHIDs(array $identity_phids) { | public function withIdentityPHIDs(array $identity_phids) { | ||||
$this->identityPHIDs = $identity_phids; | $this->identityPHIDs = $identity_phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withSessionKeys(array $keys) { | public function withSessionKeys(array $keys) { | ||||
$this->sessionKeys = $keys; | $this->sessionKeys = $keys; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withSessionTypes(array $types) { | public function withSessionTypes(array $types) { | ||||
$this->sessionTypes = $types; | $this->sessionTypes = $types; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
$this->ids = $ids; | $this->ids = $ids; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function loadPage() { | public function withPHIDs(array $phids) { | ||||
$table = new PhabricatorAuthSession(); | $this->phids = $phids; | ||||
$conn_r = $table->establishConnection('r'); | return $this; | ||||
} | |||||
$data = queryfx_all( | public function newResultObject() { | ||||
$conn_r, | return new PhabricatorAuthSession(); | ||||
'SELECT * FROM %T %Q %Q %Q', | } | ||||
$table->getTableName(), | |||||
$this->buildWhereClause($conn_r), | |||||
$this->buildOrderClause($conn_r), | |||||
$this->buildLimitClause($conn_r)); | |||||
return $table->loadAllFromArray($data); | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | |||||
} | } | ||||
protected function willFilterPage(array $sessions) { | protected function willFilterPage(array $sessions) { | ||||
$identity_phids = mpull($sessions, 'getUserPHID'); | $identity_phids = mpull($sessions, 'getUserPHID'); | ||||
$identity_objects = id(new PhabricatorObjectQuery()) | $identity_objects = id(new PhabricatorObjectQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->withPHIDs($identity_phids) | ->withPHIDs($identity_phids) | ||||
->execute(); | ->execute(); | ||||
$identity_objects = mpull($identity_objects, null, 'getPHID'); | $identity_objects = mpull($identity_objects, null, 'getPHID'); | ||||
foreach ($sessions as $key => $session) { | foreach ($sessions as $key => $session) { | ||||
$identity_object = idx($identity_objects, $session->getUserPHID()); | $identity_object = idx($identity_objects, $session->getUserPHID()); | ||||
if (!$identity_object) { | if (!$identity_object) { | ||||
unset($sessions[$key]); | unset($sessions[$key]); | ||||
} else { | } else { | ||||
$session->attachIdentityObject($identity_object); | $session->attachIdentityObject($identity_object); | ||||
} | } | ||||
} | } | ||||
return $sessions; | return $sessions; | ||||
} | } | ||||
protected function buildWhereClause(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'id IN (%Ld)', | 'id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->phids !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'phid IN (%Ls)', | |||||
$this->phids); | |||||
} | |||||
if ($this->identityPHIDs !== null) { | if ($this->identityPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'userPHID IN (%Ls)', | 'userPHID IN (%Ls)', | ||||
$this->identityPHIDs); | $this->identityPHIDs); | ||||
} | } | ||||
if ($this->sessionKeys !== null) { | if ($this->sessionKeys !== null) { | ||||
Show All 9 Lines | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
if ($this->sessionTypes !== null) { | if ($this->sessionTypes !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'type IN (%Ls)', | 'type IN (%Ls)', | ||||
$this->sessionTypes); | $this->sessionTypes); | ||||
} | } | ||||
$where[] = $this->buildPagingClause($conn); | return $where; | ||||
return $this->formatWhereClause($conn, $where); | |||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorAuthApplication'; | return 'PhabricatorAuthApplication'; | ||||
} | } | ||||
} | } |