diff --git a/src/applications/maniphest/query/ManiphestTaskQuery.php b/src/applications/maniphest/query/ManiphestTaskQuery.php --- a/src/applications/maniphest/query/ManiphestTaskQuery.php +++ b/src/applications/maniphest/query/ManiphestTaskQuery.php @@ -11,6 +11,7 @@ private $taskIDs = array(); private $taskPHIDs = array(); + private $dependentTaskIDs = array(); private $authorPHIDs = array(); private $ownerPHIDs = array(); private $includeUnowned = null; @@ -70,6 +71,11 @@ return $this; } + public function withDependentIDs(array $ids) { + $this->dependentTaskIDs = $ids; + return $this; + } + public function withOwners(array $owners) { $this->includeUnowned = false; foreach ($owners as $k => $phid) { @@ -195,6 +201,7 @@ $where = array(); $where[] = $this->buildTaskIDsWhereClause($conn); $where[] = $this->buildTaskPHIDsWhereClause($conn); + $where[] = $this->buildDependentTaskIDsWhereClause($conn); $where[] = $this->buildStatusWhereClause($conn); $where[] = $this->buildStatusesWhereClause($conn); $where[] = $this->buildPrioritiesWhereClause($conn); @@ -357,6 +364,26 @@ $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, + $dependent_task_phids); + } + private function buildStatusWhereClause(AphrontDatabaseConnection $conn) { static $map = array( @@ -646,6 +673,12 @@ $joins = array(); + if ($this->dependentTaskIDs) { + $joins[] = qsprintf( + $conn_r, + 'JOIN edge ON edge.src = task.phid'); + } + if ($this->projectPHIDs || $this->includeNoProject) { $joins[] = qsprintf( $conn_r, diff --git a/src/applications/maniphest/query/ManiphestTaskSearchEngine.php b/src/applications/maniphest/query/ManiphestTaskSearchEngine.php --- a/src/applications/maniphest/query/ManiphestTaskSearchEngine.php +++ b/src/applications/maniphest/query/ManiphestTaskSearchEngine.php @@ -77,6 +77,17 @@ } $saved->setParameter('ids', $ids); + $dependent_ids = $request->getStrList('dependentIds'); + foreach ($dependent_ids as $key => $id) { + $id = trim($id, ' Tt'); + if (!$id || !is_numeric($id)) { + unset($ids[$key]); + } else { + $dependent_ids[$key] = $id; + } + } + $saved->setParameter('dependentIds', $dependent_ids); + $saved->setParameter('fulltext', $request->getStr('fulltext')); $saved->setParameter( @@ -168,6 +179,11 @@ $query->withIDs($ids); } + $dependent_ids = $saved->getParameter('dependentIds'); + if ($dependent_ids) { + $query->withDependentIDs($dependent_ids); + } + $fulltext = $saved->getParameter('fulltext'); if (strlen($fulltext)) { $query->withFullTextSearch($fulltext); @@ -301,6 +317,7 @@ } $ids = $saved->getParameter('ids', array()); + $dependent_ids = $saved->getParameter('dependentIds', array()); $form ->appendChild( @@ -394,7 +411,12 @@ id(new AphrontFormTextControl()) ->setName('ids') ->setLabel(pht('Task IDs')) - ->setValue(implode(', ', $ids))); + ->setValue(implode(', ', $ids))) + ->appendChild( + id(new AphrontFormTextControl()) + ->setName('dependentIds') + ->setLabel(pht('Dependent Task IDs')) + ->setValue(implode(', ', $dependent_ids))); $this->appendCustomFieldsToForm($form, $saved);