mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Modernize ReleephProjectQuery ordering/paging
Summary: Ref T7803. Continue removing implementations of getPagingColumn() and getReversePaging(). Test Plan: Browsed and paged through Releeph projects, Maniphest tasks, Diffusion repositories. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7803 Differential Revision: https://secure.phabricator.com/D12358
This commit is contained in:
parent
d496f4d28c
commit
a4a198342e
5 changed files with 42 additions and 41 deletions
|
@ -861,14 +861,6 @@ final class DifferentialRevisionQuery
|
|||
}
|
||||
}
|
||||
|
||||
private function loadCursorObject($id) {
|
||||
$results = id(new DifferentialRevisionQuery())
|
||||
->setViewer($this->getPagingViewer())
|
||||
->withIDs(array((int)$id))
|
||||
->execute();
|
||||
return head($results);
|
||||
}
|
||||
|
||||
protected function buildPagingClause(AphrontDatabaseConnection $conn_r) {
|
||||
$default = parent::buildPagingClause($conn_r);
|
||||
|
||||
|
|
|
@ -949,14 +949,6 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
return array_mergev($phids);
|
||||
}
|
||||
|
||||
private function loadCursorObject($id) {
|
||||
$results = id(new ManiphestTaskQuery())
|
||||
->setViewer($this->getPagingViewer())
|
||||
->withIDs(array((int)$id))
|
||||
->execute();
|
||||
return head($results);
|
||||
}
|
||||
|
||||
protected function getPagingValue($result) {
|
||||
$id = $result->getID();
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ final class ReleephProductQuery
|
|||
|
||||
private $needArcanistProjects;
|
||||
|
||||
private $order = 'order-id';
|
||||
const ORDER_ID = 'order-id';
|
||||
const ORDER_NAME = 'order-name';
|
||||
|
||||
|
@ -20,7 +19,16 @@ final class ReleephProductQuery
|
|||
}
|
||||
|
||||
public function setOrder($order) {
|
||||
$this->order = $order;
|
||||
switch ($order) {
|
||||
case self::ORDER_ID:
|
||||
$this->setOrderVector(array('id'));
|
||||
break;
|
||||
case self::ORDER_NAME:
|
||||
$this->setOrderVector(array('name'));
|
||||
break;
|
||||
default:
|
||||
throw new Exception(pht('Order "%s" not supported.', $order));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -139,31 +147,24 @@ final class ReleephProductQuery
|
|||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
protected function getReversePaging() {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_NAME:
|
||||
return true;
|
||||
}
|
||||
return parent::getReversePaging();
|
||||
public function getOrderableColumns() {
|
||||
return parent::getOrderableColumns() + array(
|
||||
'name' => array(
|
||||
'column' => 'name',
|
||||
'unique' => true,
|
||||
'reverse' => true,
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getPagingValue($result) {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_NAME:
|
||||
return $result->getName();
|
||||
}
|
||||
return parent::getPagingValue();
|
||||
}
|
||||
protected function getPagingValueMap($cursor, array $keys) {
|
||||
$product = $this->loadCursorObject($cursor);
|
||||
|
||||
protected function getPagingColumn() {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_NAME:
|
||||
return 'name';
|
||||
case self::ORDER_ID:
|
||||
return parent::getPagingColumn();
|
||||
default:
|
||||
throw new Exception("Uknown order '{$this->order}'!");
|
||||
}
|
||||
return array(
|
||||
'id' => $product->getID(),
|
||||
'name' => $product->getName(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getQueryApplicationClass() {
|
||||
|
|
|
@ -340,7 +340,7 @@ final class PhabricatorRepositoryQuery
|
|||
return $this->formatOrderClause($conn, $parts);
|
||||
}
|
||||
|
||||
private function loadCursorObject($id) {
|
||||
protected function loadCursorObject($id) {
|
||||
$query = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($this->getPagingViewer())
|
||||
->withIDs(array((int)$id));
|
||||
|
|
|
@ -244,6 +244,22 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
|||
);
|
||||
}
|
||||
|
||||
protected function loadCursorObject($cursor) {
|
||||
$query = newv(get_class($this), array())
|
||||
->setViewer($this->getPagingViewer())
|
||||
->withIDs(array((int)$cursor));
|
||||
|
||||
$object = $query->executeOne();
|
||||
if (!$object) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Cursor "%s" does not identify a valid object.',
|
||||
$cursor));
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simplifies the task of constructing a paging clause across multiple
|
||||
|
|
Loading…
Reference in a new issue