1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Slightly modernize ConduitTokenQuery

Summary: Ref T11954. This old query class can use slightly more modern code.

Test Plan: Ran Conduit methods, verified results are unchanged.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11954

Differential Revision: https://secure.phabricator.com/D16996
This commit is contained in:
epriestley 2016-12-06 04:16:49 -08:00
parent 55a54facd5
commit bfbf75a872

View file

@ -34,48 +34,41 @@ final class PhabricatorConduitTokenQuery
return $this; return $this;
} }
protected function loadPage() { public function newResultObject() {
$table = new PhabricatorConduitToken(); return new PhabricatorConduitToken();
$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 buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function loadPage() {
$where = array(); return $this->loadStandardPage($this->newResultObject());
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$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->objectPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'objectPHID IN (%Ls)', 'objectPHID IN (%Ls)',
$this->objectPHIDs); $this->objectPHIDs);
} }
if ($this->tokens !== null) { if ($this->tokens !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'token IN (%Ls)', 'token IN (%Ls)',
$this->tokens); $this->tokens);
} }
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);
} }
@ -83,20 +76,18 @@ final class PhabricatorConduitTokenQuery
if ($this->expired !== null) { if ($this->expired !== null) {
if ($this->expired) { if ($this->expired) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'expires <= %d', 'expires <= %d',
PhabricatorTime::getNow()); PhabricatorTime::getNow());
} else { } else {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'expires IS NULL OR expires > %d', 'expires IS NULL OR expires > %d',
PhabricatorTime::getNow()); PhabricatorTime::getNow());
} }
} }
$where[] = $this->buildPagingClause($conn_r); return $where;
return $this->formatWhereClause($where);
} }
protected function willFilterPage(array $tokens) { protected function willFilterPage(array $tokens) {