Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/query/PhabricatorAuthTemporaryTokenQuery.php
| <?php | <?php | ||||
| final class PhabricatorAuthTemporaryTokenQuery | final class PhabricatorAuthTemporaryTokenQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $ids; | private $ids; | ||||
| private $objectPHIDs; | private $tokenResources; | ||||
| private $tokenTypes; | private $tokenTypes; | ||||
| private $userPHIDs; | |||||
| private $expired; | private $expired; | ||||
| private $tokenCodes; | private $tokenCodes; | ||||
| public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
| $this->ids = $ids; | $this->ids = $ids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withObjectPHIDs(array $object_phids) { | public function withTokenResources(array $resources) { | ||||
| $this->objectPHIDs = $object_phids; | $this->tokenResources = $resources; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withTokenTypes(array $types) { | public function withTokenTypes(array $types) { | ||||
| $this->tokenTypes = $types; | $this->tokenTypes = $types; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withExpired($expired) { | public function withExpired($expired) { | ||||
| $this->expired = $expired; | $this->expired = $expired; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withTokenCodes(array $codes) { | public function withTokenCodes(array $codes) { | ||||
| $this->tokenCodes = $codes; | $this->tokenCodes = $codes; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function loadPage() { | public function withUserPHIDs(array $phids) { | ||||
| $table = new PhabricatorAuthTemporaryToken(); | $this->userPHIDs = $phids; | ||||
| $conn_r = $table->establishConnection('r'); | return $this; | ||||
| } | |||||
| $data = queryfx_all( | public function newResultObject() { | ||||
| $conn_r, | return new PhabricatorAuthTemporaryToken(); | ||||
| '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 buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
| if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'id IN (%Ld)', | 'id IN (%Ld)', | ||||
| $this->ids); | $this->ids); | ||||
| } | } | ||||
| if ($this->objectPHIDs !== null) { | if ($this->tokenResources !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'objectPHID IN (%Ls)', | 'tokenResource IN (%Ls)', | ||||
| $this->objectPHIDs); | $this->tokenResources); | ||||
| } | } | ||||
| if ($this->tokenTypes !== null) { | if ($this->tokenTypes !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'tokenType IN (%Ls)', | 'tokenType IN (%Ls)', | ||||
| $this->tokenTypes); | $this->tokenTypes); | ||||
| } | } | ||||
| if ($this->expired !== null) { | if ($this->expired !== null) { | ||||
| if ($this->expired) { | if ($this->expired) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'tokenExpires <= %d', | 'tokenExpires <= %d', | ||||
| time()); | time()); | ||||
| } else { | } else { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'tokenExpires > %d', | 'tokenExpires > %d', | ||||
| time()); | time()); | ||||
| } | } | ||||
| } | } | ||||
| if ($this->tokenCodes !== null) { | if ($this->tokenCodes !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'tokenCode IN (%Ls)', | 'tokenCode IN (%Ls)', | ||||
| $this->tokenCodes); | $this->tokenCodes); | ||||
| } | } | ||||
| $where[] = $this->buildPagingClause($conn_r); | if ($this->userPHIDs !== null) { | ||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'userPHID IN (%Ls)', | |||||
| $this->userPHIDs); | |||||
| } | |||||
| return $this->formatWhereClause($where); | return $where; | ||||
| } | } | ||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| return 'PhabricatorAuthApplication'; | return 'PhabricatorAuthApplication'; | ||||
| } | } | ||||
| } | } | ||||