2014-01-14 20:05:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorAuthSessionQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $identityPHIDs;
|
2014-01-14 22:22:27 +01:00
|
|
|
private $sessionKeys;
|
|
|
|
private $sessionTypes;
|
2014-01-14 20:05:45 +01:00
|
|
|
|
|
|
|
public function withIdentityPHIDs(array $identity_phids) {
|
|
|
|
$this->identityPHIDs = $identity_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:22:27 +01:00
|
|
|
public function withSessionKeys(array $keys) {
|
|
|
|
$this->sessionKeys = $keys;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withSessionTypes(array $types) {
|
|
|
|
$this->sessionTypes = $types;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-01-14 20:05:45 +01:00
|
|
|
protected function loadPage() {
|
|
|
|
$table = new PhabricatorAuthSession();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'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 willFilterPage(array $sessions) {
|
|
|
|
$identity_phids = mpull($sessions, 'getUserPHID');
|
|
|
|
|
|
|
|
$identity_objects = id(new PhabricatorObjectQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->setParentQuery($this)
|
|
|
|
->withPHIDs($identity_phids)
|
|
|
|
->execute();
|
|
|
|
$identity_objects = mpull($identity_objects, null, 'getPHID');
|
|
|
|
|
|
|
|
foreach ($sessions as $key => $session) {
|
|
|
|
$identity_object = idx($identity_objects, $session->getUserPHID());
|
|
|
|
if (!$identity_object) {
|
|
|
|
unset($sessions[$key]);
|
|
|
|
} else {
|
|
|
|
$session->attachIdentityObject($identity_object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sessions;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->identityPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'userPHID IN (%Ls)',
|
|
|
|
$this->identityPHIDs);
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:22:27 +01:00
|
|
|
if ($this->sessionKeys) {
|
|
|
|
$hashes = array();
|
|
|
|
foreach ($this->sessionKeys as $session_key) {
|
|
|
|
$hashes[] = PhabricatorHash::digest($session_key);
|
|
|
|
}
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'sessionKey IN (%Ls)',
|
|
|
|
$hashes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->sessionTypes) {
|
2014-01-16 02:27:59 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'type IN (%Ls)',
|
|
|
|
$this->sessionTypes);
|
2014-01-14 22:22:27 +01:00
|
|
|
}
|
|
|
|
|
2014-01-14 20:05:45 +01:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getQueryApplicationClass() {
|
|
|
|
return 'PhabricatorApplicationAuth';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|