From d6d8598d68c2642bc07de4a10179772a5021c85a Mon Sep 17 00:00:00 2001 From: tuomaspelkonen Date: Tue, 5 Apr 2011 22:32:37 -0700 Subject: [PATCH] Tasks can be searched with task id in differential Task Selector Summary: Task selector didn't support searching tasks with their IDs, e.g., 'T17'. This was confusing, because in the task list the task ID was visible, but you could not search them. Test Plan: * Checked that searching 'T' works with all the filters * Checked that using multiple task IDs in the same query works * Check that mixing task IDs and free text works Reviewers: epriestley CC: jungejason Differential Revision: 105 --- .../ManiphestTaskSelectorSearchController.php | 35 +++++++++++++++++-- .../taskselectorsearch/__init__.php | 1 + 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/applications/maniphest/controller/taskselectorsearch/ManiphestTaskSelectorSearchController.php b/src/applications/maniphest/controller/taskselectorsearch/ManiphestTaskSelectorSearchController.php index f547f5e592..499d5bafcd 100644 --- a/src/applications/maniphest/controller/taskselectorsearch/ManiphestTaskSelectorSearchController.php +++ b/src/applications/maniphest/controller/taskselectorsearch/ManiphestTaskSelectorSearchController.php @@ -23,7 +23,18 @@ class ManiphestTaskSelectorSearchController extends ManiphestController { $user = $request->getUser(); $query = new PhabricatorSearchQuery(); - $query->setQuery($request->getStr('query')); + + $query_str = $request->getStr('query'); + $matches = array(); + $task_ids = array(); + + // Collect all task IDs, e.g., T12 T651 T631, from the query string + preg_match_all('/\bT(\d+)\b/', $query_str, $matches); + if ($matches) { + $task_ids = $matches[1]; + } + + $query->setQuery($query_str); $query->setParameter('type', PhabricatorPHIDConstants::PHID_TYPE_TASK); switch ($request->getStr('filter')) { @@ -42,9 +53,27 @@ class ManiphestTaskSelectorSearchController extends ManiphestController { $exec = new PhabricatorSearchMySQLExecutor(); $results = $exec->executeSearch($query); - $results = ipull($results, 'phid'); - $handles = id(new PhabricatorObjectHandleData($results)) + $phids = array(); + + foreach ($results as $result) { + $phids[$result['phid']] = true; + } + + // Do a separate query for task IDs if the query had them + if ($task_ids) { + $task_object = new ManiphestTask(); + + // It's OK to ignore filters, if user wants specific task IDs + $tasks = $task_object->loadAllWhere('id IN (%Ls)', $task_ids); + + foreach ($tasks as $task) { + $phids[$task->getPHID()] = true; + } + } + + $phids = array_keys($phids); + $handles = id(new PhabricatorObjectHandleData($phids)) ->loadHandles(); $data = array(); diff --git a/src/applications/maniphest/controller/taskselectorsearch/__init__.php b/src/applications/maniphest/controller/taskselectorsearch/__init__.php index 3475c1e17b..6d45ca9abc 100644 --- a/src/applications/maniphest/controller/taskselectorsearch/__init__.php +++ b/src/applications/maniphest/controller/taskselectorsearch/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'aphront/response/ajax'); phutil_require_module('phabricator', 'applications/maniphest/controller/base'); +phutil_require_module('phabricator', 'applications/maniphest/storage/task'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/phid/handle/data'); phutil_require_module('phabricator', 'applications/phid/handle/view/selector');