Summary: Depends on D20291. Ref T13259. Move all the simple cases (where paging depends only on the partial object and does not depend on keys) to a simple wrapper. This leaves a smaller set of more complex cases where we care about external data or which keys were requested that I'll convert in followups. Test Plan: Poked at things, but a lot of stuff is still broken until everything is converted. Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13259 Differential Revision: https://secure.phabricator.com/D20292
146 lines
3.0 KiB
PHP
146 lines
3.0 KiB
PHP
<?php
|
|
|
|
final class AlmanacDeviceQuery
|
|
extends AlmanacQuery {
|
|
|
|
private $ids;
|
|
private $phids;
|
|
private $names;
|
|
private $namePrefix;
|
|
private $nameSuffix;
|
|
private $isClusterDevice;
|
|
|
|
public function withIDs(array $ids) {
|
|
$this->ids = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function withPHIDs(array $phids) {
|
|
$this->phids = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withNames(array $names) {
|
|
$this->names = $names;
|
|
return $this;
|
|
}
|
|
|
|
public function withNamePrefix($prefix) {
|
|
$this->namePrefix = $prefix;
|
|
return $this;
|
|
}
|
|
|
|
public function withNameSuffix($suffix) {
|
|
$this->nameSuffix = $suffix;
|
|
return $this;
|
|
}
|
|
|
|
public function withNameNgrams($ngrams) {
|
|
return $this->withNgramsConstraint(
|
|
new AlmanacDeviceNameNgrams(),
|
|
$ngrams);
|
|
}
|
|
|
|
public function withIsClusterDevice($is_cluster_device) {
|
|
$this->isClusterDevice = $is_cluster_device;
|
|
return $this;
|
|
}
|
|
|
|
public function newResultObject() {
|
|
return new AlmanacDevice();
|
|
}
|
|
|
|
protected function loadPage() {
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
}
|
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
$where = parent::buildWhereClauseParts($conn);
|
|
|
|
if ($this->ids !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.id IN (%Ld)',
|
|
$this->ids);
|
|
}
|
|
|
|
if ($this->phids !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.phid IN (%Ls)',
|
|
$this->phids);
|
|
}
|
|
|
|
if ($this->names !== null) {
|
|
$hashes = array();
|
|
foreach ($this->names as $name) {
|
|
$hashes[] = PhabricatorHash::digestForIndex($name);
|
|
}
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.nameIndex IN (%Ls)',
|
|
$hashes);
|
|
}
|
|
|
|
if ($this->namePrefix !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.name LIKE %>',
|
|
$this->namePrefix);
|
|
}
|
|
|
|
if ($this->nameSuffix !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.name LIKE %<',
|
|
$this->nameSuffix);
|
|
}
|
|
|
|
if ($this->isClusterDevice !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.isBoundToClusterService = %d',
|
|
(int)$this->isClusterDevice);
|
|
}
|
|
|
|
return $where;
|
|
}
|
|
|
|
protected function getPrimaryTableAlias() {
|
|
return 'device';
|
|
}
|
|
|
|
public function getOrderableColumns() {
|
|
return parent::getOrderableColumns() + array(
|
|
'name' => array(
|
|
'table' => $this->getPrimaryTableAlias(),
|
|
'column' => 'name',
|
|
'type' => 'string',
|
|
'unique' => true,
|
|
'reverse' => true,
|
|
),
|
|
);
|
|
}
|
|
|
|
protected function newPagingMapFromPartialObject($object) {
|
|
return array(
|
|
'id' => (int)$object->getID(),
|
|
'name' => $object->getName(),
|
|
);
|
|
}
|
|
|
|
public function getBuiltinOrders() {
|
|
return array(
|
|
'name' => array(
|
|
'vector' => array('name'),
|
|
'name' => pht('Device Name'),
|
|
),
|
|
) + parent::getBuiltinOrders();
|
|
}
|
|
|
|
public function getQueryApplicationClass() {
|
|
return 'PhabricatorAlmanacApplication';
|
|
}
|
|
|
|
}
|