Changeset View
Changeset View
Standalone View
Standalone View
src/applications/maniphest/query/ManiphestTaskQuery.php
<?php | <?php | ||||
/** | /** | ||||
* Query tasks by specific criteria. This class uses the higher-performance | * Query tasks by specific criteria. This class uses the higher-performance | ||||
* but less-general Maniphest indexes to satisfy queries. | * but less-general Maniphest indexes to satisfy queries. | ||||
* | * | ||||
* @group maniphest | * @group maniphest | ||||
*/ | */ | ||||
final class ManiphestTaskQuery | final class ManiphestTaskQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $taskIDs = array(); | private $taskIDs = array(); | ||||
private $taskPHIDs = array(); | private $taskPHIDs = array(); | ||||
private $dependentTaskIDs = array(); | |||||
private $authorPHIDs = array(); | private $authorPHIDs = array(); | ||||
private $ownerPHIDs = array(); | private $ownerPHIDs = array(); | ||||
private $includeUnowned = null; | private $includeUnowned = null; | ||||
private $projectPHIDs = array(); | private $projectPHIDs = array(); | ||||
private $xprojectPHIDs = array(); | private $xprojectPHIDs = array(); | ||||
private $subscriberPHIDs = array(); | private $subscriberPHIDs = array(); | ||||
private $anyProjectPHIDs = array(); | private $anyProjectPHIDs = array(); | ||||
private $anyUserProjectPHIDs = array(); | private $anyUserProjectPHIDs = array(); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | public function withIDs(array $ids) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
$this->taskPHIDs = $phids; | $this->taskPHIDs = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withDependentIDs(array $ids) { | |||||
$this->dependentTaskIDs = $ids; | |||||
return $this; | |||||
} | |||||
public function withOwners(array $owners) { | public function withOwners(array $owners) { | ||||
$this->includeUnowned = false; | $this->includeUnowned = false; | ||||
foreach ($owners as $k => $phid) { | foreach ($owners as $k => $phid) { | ||||
if ($phid == ManiphestTaskOwner::OWNER_UP_FOR_GRABS || $phid === null) { | if ($phid == ManiphestTaskOwner::OWNER_UP_FOR_GRABS || $phid === null) { | ||||
$this->includeUnowned = true; | $this->includeUnowned = true; | ||||
unset($owners[$k]); | unset($owners[$k]); | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | public function loadPage() { | ||||
// can see the project. | // can see the project. | ||||
$task_dao = new ManiphestTask(); | $task_dao = new ManiphestTask(); | ||||
$conn = $task_dao->establishConnection('r'); | $conn = $task_dao->establishConnection('r'); | ||||
$where = array(); | $where = array(); | ||||
$where[] = $this->buildTaskIDsWhereClause($conn); | $where[] = $this->buildTaskIDsWhereClause($conn); | ||||
$where[] = $this->buildTaskPHIDsWhereClause($conn); | $where[] = $this->buildTaskPHIDsWhereClause($conn); | ||||
$where[] = $this->buildDependentTaskIDsWhereClause($conn); | |||||
$where[] = $this->buildStatusWhereClause($conn); | $where[] = $this->buildStatusWhereClause($conn); | ||||
$where[] = $this->buildStatusesWhereClause($conn); | $where[] = $this->buildStatusesWhereClause($conn); | ||||
$where[] = $this->buildPrioritiesWhereClause($conn); | $where[] = $this->buildPrioritiesWhereClause($conn); | ||||
$where[] = $this->buildAuthorWhereClause($conn); | $where[] = $this->buildAuthorWhereClause($conn); | ||||
$where[] = $this->buildOwnerWhereClause($conn); | $where[] = $this->buildOwnerWhereClause($conn); | ||||
$where[] = $this->buildSubscriberWhereClause($conn); | $where[] = $this->buildSubscriberWhereClause($conn); | ||||
$where[] = $this->buildProjectWhereClause($conn); | $where[] = $this->buildProjectWhereClause($conn); | ||||
$where[] = $this->buildAnyProjectWhereClause($conn); | $where[] = $this->buildAnyProjectWhereClause($conn); | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | private function buildTaskPHIDsWhereClause(AphrontDatabaseConnection $conn) { | ||||
} | } | ||||
return qsprintf( | return qsprintf( | ||||
$conn, | $conn, | ||||
'phid in (%Ls)', | 'phid in (%Ls)', | ||||
$this->taskPHIDs); | $this->taskPHIDs); | ||||
} | } | ||||
private function buildDependentTaskIDsWhereClause( | |||||
AphrontDatabaseConnection $conn) { | |||||
if (!$this->dependentTaskIDs) { | |||||
return null; | |||||
} | |||||
$dependent_tasks = id(new ManiphestTaskQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->withIDs($this->dependentTaskIDs) | |||||
->execute(); | |||||
$dependent_task_phids = mpull($dependent_tasks, 'getPHID'); | |||||
return qsprintf( | |||||
$conn, | |||||
'edge.type = %s AND edge.dst IN (%Ls)', | |||||
PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK, | |||||
epriestley: I would expect this to be `TYPE_TASK_DEPENDS_ON_TASK`? | |||||
$dependent_task_phids); | |||||
} | |||||
private function buildStatusWhereClause(AphrontDatabaseConnection $conn) { | private function buildStatusWhereClause(AphrontDatabaseConnection $conn) { | ||||
static $map = array( | static $map = array( | ||||
self::STATUS_RESOLVED => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | self::STATUS_RESOLVED => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, | ||||
self::STATUS_WONTFIX => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | self::STATUS_WONTFIX => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, | ||||
self::STATUS_INVALID => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | self::STATUS_INVALID => ManiphestTaskStatus::STATUS_CLOSED_INVALID, | ||||
self::STATUS_SPITE => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | self::STATUS_SPITE => ManiphestTaskStatus::STATUS_CLOSED_SPITE, | ||||
self::STATUS_DUPLICATE => ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE, | self::STATUS_DUPLICATE => ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE, | ||||
▲ Show 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | private function buildCustomOrderClause(AphrontDatabaseConnection $conn) { | ||||
return 'ORDER BY '.implode(', ', $order); | return 'ORDER BY '.implode(', ', $order); | ||||
} | } | ||||
private function buildJoinsClause(AphrontDatabaseConnection $conn_r) { | private function buildJoinsClause(AphrontDatabaseConnection $conn_r) { | ||||
$project_dao = new ManiphestTaskProject(); | $project_dao = new ManiphestTaskProject(); | ||||
$joins = array(); | $joins = array(); | ||||
if ($this->dependentTaskIDs) { | |||||
$joins[] = qsprintf( | |||||
$conn_r, | |||||
'JOIN edge ON edge.src = task.phid'); | |||||
} | |||||
if ($this->projectPHIDs || $this->includeNoProject) { | if ($this->projectPHIDs || $this->includeNoProject) { | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
$conn_r, | $conn_r, | ||||
'%Q JOIN %T project ON project.taskPHID = task.phid', | '%Q JOIN %T project ON project.taskPHID = task.phid', | ||||
($this->includeNoProject ? 'LEFT' : ''), | ($this->includeNoProject ? 'LEFT' : ''), | ||||
$project_dao->getTableName()); | $project_dao->getTableName()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 293 Lines • Show Last 20 Lines |
I would expect this to be TYPE_TASK_DEPENDS_ON_TASK?