From fcb4cf57d7f871c9f8aaba359f3296ae03e7a232 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 20 Feb 2011 20:37:50 -0800 Subject: [PATCH] Project search, plus "Up For Grabs". Summary: Test Plan: Reviewers: CC: --- .../data/PhabricatorObjectHandleData.php | 35 ++++++++++++------- .../PhabricatorSearchRelationship.php | 1 + .../search/PhabricatorSearchController.php | 24 +++++++++++-- .../mysql/PhabricatorSearchMySQLExecutor.php | 6 ++++ .../PhabricatorSearchManiphestIndexer.php | 16 +++++++++ ...torTypeaheadCommonDatasourceController.php | 11 ++++++ 6 files changed, 78 insertions(+), 15 deletions(-) diff --git a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php index 02f4e14e6d..72433f3315 100644 --- a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php @@ -38,6 +38,23 @@ class PhabricatorObjectHandleData { foreach ($types as $type => $phids) { switch ($type) { + case '!!!!': + // Black magic! + foreach ($phids as $phid) { + $handle = new PhabricatorObjectHandle(); + $handle->setPHID($phid); + $handle->setType($type); + switch ($phid) { + case 'PHID-!!!!-UP-FOR-GRABS': + $handle->setName('Up For Grabs'); + break; + default: + $handle->setName('Foul Magicks'); + break; + } + $handles[$phid] = $handle; + } + break; case 'USER': $class = 'PhabricatorUser'; PhutilSymbolLoader::loadClass($class); @@ -49,12 +66,11 @@ class PhabricatorObjectHandleData { foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); + $handle->setType($type); if (empty($users[$phid])) { - $handle->setType(self::TYPE_UNKNOWN); $handle->setName('Unknown User'); } else { $user = $users[$phid]; - $handle->setType($type); $handle->setName($user->getUsername()); $handle->setURI('/p/'.$user->getUsername().'/'); $handle->setEmail($user->getEmail()); @@ -82,12 +98,11 @@ class PhabricatorObjectHandleData { foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); + $handle->setType($type); if (empty($lists[$phid])) { - $handle->setType(self::TYPE_UNKNOWN); $handle->setName('Unknown Mailing List'); } else { $list = $lists[$phid]; - $handle->setType($type); $handle->setEmail($list->getEmail()); $handle->setName($list->getName()); $handle->setURI($list->getURI()); @@ -107,12 +122,11 @@ class PhabricatorObjectHandleData { foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); + $handle->setType($type); if (empty($revs[$phid])) { - $handle->setType(self::TYPE_UNKNOWN); $handle->setName('Unknown Revision'); } else { $rev = $revs[$phid]; - $handle->setType($type); $handle->setName($rev->getTitle()); $handle->setURI('/D'.$rev->getID()); $handle->setFullName('D'.$rev->getID().': '.$rev->getTitle()); @@ -131,12 +145,11 @@ class PhabricatorObjectHandleData { foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); + $handle->setType($type); if (empty($tasks[$phid])) { - $handle->setType(self::TYPE_UNKNOWN); $handle->setName('Unknown Revision'); } else { $task = $tasks[$phid]; - $handle->setType($type); $handle->setName($task->getTitle()); $handle->setURI('/T'.$task->getID()); $handle->setFullName('T'.$task->getID().': '.$task->getTitle()); @@ -155,12 +168,11 @@ class PhabricatorObjectHandleData { foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); + $handle->setType($type); if (empty($files[$phid])) { - $handle->setType(self::TYPE_UNKNOWN); $handle->setName('Unknown File'); } else { $file = $files[$phid]; - $handle->setType($type); $handle->setName($file->getName()); $handle->setURI($file->getViewURI()); } @@ -178,12 +190,11 @@ class PhabricatorObjectHandleData { foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); + $handle->setType($type); if (empty($projects[$phid])) { - $handle->setType(self::TYPE_UNKNOWN); $handle->setName('Unknown Project'); } else { $project = $projects[$phid]; - $handle->setType($type); $handle->setName($project->getName()); $handle->setURI('/project/view/'.$project->getID().'/'); } diff --git a/src/applications/search/constants/relationship/PhabricatorSearchRelationship.php b/src/applications/search/constants/relationship/PhabricatorSearchRelationship.php index 488acfa445..695543e372 100644 --- a/src/applications/search/constants/relationship/PhabricatorSearchRelationship.php +++ b/src/applications/search/constants/relationship/PhabricatorSearchRelationship.php @@ -23,6 +23,7 @@ final class PhabricatorSearchRelationship { const RELATIONSHIP_SUBSCRIBER = 'subs'; const RELATIONSHIP_COMMENTER = 'comm'; const RELATIONSHIP_OWNER = 'ownr'; + const RELATIONSHIP_PROJECT = 'proj'; const RELATIONSHIP_OPEN = 'open'; const RELATIONSHIP_TOUCH = 'poke'; diff --git a/src/applications/search/controller/search/PhabricatorSearchController.php b/src/applications/search/controller/search/PhabricatorSearchController.php index b5d88de20e..4898f01df4 100644 --- a/src/applications/search/controller/search/PhabricatorSearchController.php +++ b/src/applications/search/controller/search/PhabricatorSearchController.php @@ -55,6 +55,10 @@ class PhabricatorSearchController extends PhabricatorSearchBaseController { $query->setParameter('open', $request->getInt('open')); } + if ($request->getArr('project')) { + $query->setParameter('project', $request->getArr('project')); + } + $query->save(); return id(new AphrontRedirectResponse()) ->setURI('/search/'.$query->getID().'/'); @@ -74,7 +78,8 @@ class PhabricatorSearchController extends PhabricatorSearchBaseController { $phids = array_merge( $query->getParameter('author', array()), - $query->getParameter('owner', array()) + $query->getParameter('owner', array()), + $query->getParameter('project', array()) ); $handles = id(new PhabricatorObjectHandleData($phids)) @@ -90,6 +95,11 @@ class PhabricatorSearchController extends PhabricatorSearchBaseController { $query->getParameter('owner', array())); $owner_value = mpull($owner_value, 'getFullName', 'getPHID'); + $project_value = array_select_keys( + $handles, + $query->getParameter('project', array())); + $project_value = mpull($project_value, 'getFullName', 'getPHID'); + $search_form = new AphrontFormView(); $search_form ->setUser($user) @@ -121,8 +131,16 @@ class PhabricatorSearchController extends PhabricatorSearchBaseController { id(new AphrontFormTokenizerControl()) ->setName('owner') ->setLabel('Owner') - ->setDatasource('/typeahead/common/users/') - ->setValue($owner_value)) + ->setDatasource('/typeahead/common/searchowner/') + ->setValue($owner_value) + ->setCaption( + 'Tip: search for "Up For Grabs" to find unowned documents.')) + ->appendChild( + id(new AphrontFormTokenizerControl()) + ->setName('project') + ->setLabel('Project') + ->setDatasource('/typeahead/common/projects/') + ->setValue($project_value)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue('Search')); diff --git a/src/applications/search/execute/mysql/PhabricatorSearchMySQLExecutor.php b/src/applications/search/execute/mysql/PhabricatorSearchMySQLExecutor.php index 673a518d52..41b2dc8a0b 100644 --- a/src/applications/search/execute/mysql/PhabricatorSearchMySQLExecutor.php +++ b/src/applications/search/execute/mysql/PhabricatorSearchMySQLExecutor.php @@ -92,6 +92,12 @@ class PhabricatorSearchMySQLExecutor extends PhabricatorSearchExecutor { 'owner', PhabricatorSearchRelationship::RELATIONSHIP_OWNER); + $join[] = $this->joinRelationship( + $conn_r, + $query, + 'project', + PhabricatorSearchRelationship::RELATIONSHIP_PROJECT); + /* $join[] = $this->joinRelationship( $conn_r, diff --git a/src/applications/search/index/indexer/maniphest/PhabricatorSearchManiphestIndexer.php b/src/applications/search/index/indexer/maniphest/PhabricatorSearchManiphestIndexer.php index c548b39263..b6e0af88e6 100644 --- a/src/applications/search/index/indexer/maniphest/PhabricatorSearchManiphestIndexer.php +++ b/src/applications/search/index/indexer/maniphest/PhabricatorSearchManiphestIndexer.php @@ -83,12 +83,28 @@ class PhabricatorSearchManiphestIndexer } } + foreach ($task->getProjectPHIDs() as $phid) { + $doc->addRelationship( + PhabricatorSearchRelationship::RELATIONSHIP_PROJECT, + $phid, + 'PROJ', + $task->getDateModified()); // Bogus. + } + if ($owner && $owner->getNewValue()) { $doc->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $owner->getNewValue(), 'USER', $owner->getDateCreated()); + } else { + $doc->addRelationship( + PhabricatorSearchRelationship::RELATIONSHIP_OWNER, + 'PHID-!!!!-UP-FOR-GRABS', + '!!!!', + $owner + ? $owner->getDateCreated() + : $task->getDateCreated()); } foreach ($touches as $touch => $time) { diff --git a/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php b/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php index ac5ba5e201..98c2ed37ba 100644 --- a/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php +++ b/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php @@ -28,7 +28,11 @@ class PhabricatorTypeaheadCommonDatasourceController $need_users = false; $need_lists = false; $need_projs = false; + $need_upforgrabs = false; switch ($this->type) { + case 'searchowner': + $need_users = true; + $need_upforgrabs = true; case 'users': $need_users = true; break; @@ -43,6 +47,13 @@ class PhabricatorTypeaheadCommonDatasourceController $data = array(); + if ($need_upforgrabs) { + $data[] = array( + 'Up For Grabs', + null, + 'PHID-!!!!-UP-FOR-GRABS', + ); + } if ($need_users) { $users = id(new PhabricatorUser())->loadAll();