1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +01:00

Make ManiphestTaskQuery a (mostly) policy-aware query

Summary: Ref T603.

Test Plan: Viewed home and maniphest, fiddled all the knobs.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D6930
This commit is contained in:
epriestley 2013-09-10 07:53:27 -07:00
parent a2571de575
commit 1e42c62b8f
2 changed files with 20 additions and 53 deletions

View file

@ -2792,7 +2792,7 @@ phutil_register_library_map(array(
'ManiphestTaskPriority' => 'ManiphestConstants', 'ManiphestTaskPriority' => 'ManiphestConstants',
'ManiphestTaskProject' => 'ManiphestDAO', 'ManiphestTaskProject' => 'ManiphestDAO',
'ManiphestTaskProjectsView' => 'ManiphestView', 'ManiphestTaskProjectsView' => 'ManiphestView',
'ManiphestTaskQuery' => 'PhabricatorQuery', 'ManiphestTaskQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'ManiphestTaskStatus' => 'ManiphestConstants', 'ManiphestTaskStatus' => 'ManiphestConstants',
'ManiphestTaskSubscriber' => 'ManiphestDAO', 'ManiphestTaskSubscriber' => 'ManiphestDAO',
'ManiphestTransaction' => 'ManiphestTransaction' =>

View file

@ -6,7 +6,8 @@
* *
* @group maniphest * @group maniphest
*/ */
final class ManiphestTaskQuery extends PhabricatorQuery { final class ManiphestTaskQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $taskIDs = array(); private $taskIDs = array();
private $taskPHIDs = array(); private $taskPHIDs = array();
@ -59,16 +60,6 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
private $rowCount = null; private $rowCount = null;
private $groupByProjectResults = null; // See comment at bottom for details private $groupByProjectResults = null; // See comment at bottom for details
private $viewer;
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function withAuthors(array $authors) { public function withAuthors(array $authors) {
$this->authorPHIDs = $authors; $this->authorPHIDs = $authors;
@ -151,16 +142,6 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
return $this; return $this;
} }
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function setOffset($offset) {
$this->offset = $offset;
return $this;
}
public function setCalculateRows($calculate_rows) { public function setCalculateRows($calculate_rows) {
$this->calculateRows = $calculate_rows; $this->calculateRows = $calculate_rows;
return $this; return $this;
@ -189,31 +170,16 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
return $this; return $this;
} }
/** public function loadPage() {
* This is a wrapper until we finish T603. The newer query class this class
* will inherit from handles catching this exception already.
*/
public function execute() {
try {
$result = $this->executeManiphestQuery();
} catch (PhabricatorEmptyQueryException $ex) {
$result = array();
if ($this->calculateRows) {
$this->rowCount = 0;
}
}
return $result;
}
private function executeManiphestQuery() {
$task_dao = new ManiphestTask(); $task_dao = new ManiphestTask();
$conn = $task_dao->establishConnection('r'); $conn = $task_dao->establishConnection('r');
if ($this->calculateRows) { if ($this->calculateRows) {
$calc = 'SQL_CALC_FOUND_ROWS'; $calc = 'SQL_CALC_FOUND_ROWS';
// Make sure we end up in the right state if we throw a
// PhabricatorEmptyQueryException.
$this->rowCount = 0;
} else { } else {
$calc = ''; $calc = '';
} }
@ -271,19 +237,21 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
count($this->projectPHIDs)); count($this->projectPHIDs));
} }
$order = $this->buildOrderClause($conn); $order = $this->buildCustomOrderClause($conn);
$offset = (int)nonempty($this->offset, 0); // TODO: Clean up this nonstandardness.
$limit = (int)nonempty($this->limit, self::DEFAULT_PAGE_SIZE); if (!$this->getLimit()) {
$this->setLimit(self::DEFAULT_PAGE_SIZE);
}
if ($this->groupBy == self::GROUP_PROJECT) { if ($this->groupBy == self::GROUP_PROJECT) {
$limit = PHP_INT_MAX; $this->setLimit(PHP_INT_MAX);
$offset = 0; $this->setOffset(0);
} }
$data = queryfx_all( $data = queryfx_all(
$conn, $conn,
'SELECT %Q * %Q FROM %T task %Q %Q %Q %Q %Q LIMIT %d, %d', 'SELECT %Q * %Q FROM %T task %Q %Q %Q %Q %Q %Q',
$calc, $calc,
$count, $count,
$task_dao->getTableName(), $task_dao->getTableName(),
@ -292,8 +260,7 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
$group, $group,
$having, $having,
$order, $order,
$offset, $this->buildLimitClause($conn));
$limit);
if ($this->calculateRows) { if ($this->calculateRows) {
$count = queryfx_one( $count = queryfx_one(
@ -569,7 +536,7 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
$subscriber_dao->getTableName()); $subscriber_dao->getTableName());
} }
private function buildOrderClause(AphrontDatabaseConnection $conn) { private function buildCustomOrderClause(AphrontDatabaseConnection $conn) {
$order = array(); $order = array();
switch ($this->groupBy) { switch ($this->groupBy) {
@ -704,8 +671,8 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
$items = isort($items, 'seq'); $items = isort($items, 'seq');
$items = array_slice( $items = array_slice(
$items, $items,
nonempty($this->offset), nonempty($this->getOffset()),
nonempty($this->limit, self::DEFAULT_PAGE_SIZE)); nonempty($this->getLimit(), self::DEFAULT_PAGE_SIZE));
$result = array(); $result = array();
$projects = array(); $projects = array();