From fcdd4a533f144475b2980a899b3f9b4ea9bfa7d7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 13 Oct 2014 11:14:02 -0700 Subject: [PATCH] Allow Fund initiatives to be searched for Summary: Ref T5835. Dump these into global search so you can find them. Test Plan: {F216290} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5835 Differential Revision: https://secure.phabricator.com/D10682 --- src/__phutil_library_map__.php | 2 + .../fund/editor/FundInitiativeEditor.php | 4 +- .../fund/search/FundInitiativeIndexer.php | 58 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/applications/fund/search/FundInitiativeIndexer.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 4834084f46..61750b2245 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -684,6 +684,7 @@ phutil_register_library_map(array( 'FundInitiativeCloseController' => 'applications/fund/controller/FundInitiativeCloseController.php', 'FundInitiativeEditController' => 'applications/fund/controller/FundInitiativeEditController.php', 'FundInitiativeEditor' => 'applications/fund/editor/FundInitiativeEditor.php', + 'FundInitiativeIndexer' => 'applications/fund/search/FundInitiativeIndexer.php', 'FundInitiativeListController' => 'applications/fund/controller/FundInitiativeListController.php', 'FundInitiativePHIDType' => 'applications/fund/phid/FundInitiativePHIDType.php', 'FundInitiativeQuery' => 'applications/fund/query/FundInitiativeQuery.php', @@ -3579,6 +3580,7 @@ phutil_register_library_map(array( 'FundInitiativeCloseController' => 'FundController', 'FundInitiativeEditController' => 'FundController', 'FundInitiativeEditor' => 'PhabricatorApplicationTransactionEditor', + 'FundInitiativeIndexer' => 'PhabricatorSearchDocumentIndexer', 'FundInitiativeListController' => 'FundController', 'FundInitiativePHIDType' => 'PhabricatorPHIDType', 'FundInitiativeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', diff --git a/src/applications/fund/editor/FundInitiativeEditor.php b/src/applications/fund/editor/FundInitiativeEditor.php index b1e32d4db8..45b747006c 100644 --- a/src/applications/fund/editor/FundInitiativeEditor.php +++ b/src/applications/fund/editor/FundInitiativeEditor.php @@ -277,6 +277,8 @@ final class FundInitiativeEditor return true; } - + protected function supportsSearch() { + return true; + } } diff --git a/src/applications/fund/search/FundInitiativeIndexer.php b/src/applications/fund/search/FundInitiativeIndexer.php new file mode 100644 index 0000000000..a5be183980 --- /dev/null +++ b/src/applications/fund/search/FundInitiativeIndexer.php @@ -0,0 +1,58 @@ +setViewer($this->getViewer()) + ->withPHIDs(array($phid)) + ->executeOne(); + if (!$object) { + throw new Exception("Unable to load object by phid '{$phid}'!"); + } + return $object; + } + + protected function buildAbstractDocumentByPHID($phid) { + $initiative = $this->loadDocumentByPHID($phid); + + $doc = id(new PhabricatorSearchAbstractDocument()) + ->setPHID($initiative->getPHID()) + ->setDocumentType(FundInitiativePHIDType::TYPECONST) + ->setDocumentTitle($initiative->getName()) + ->setDocumentCreated($initiative->getDateCreated()) + ->setDocumentModified($initiative->getDateModified()); + + $doc->addRelationship( + PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, + $initiative->getOwnerPHID(), + PhabricatorPeopleUserPHIDType::TYPECONST, + $initiative->getDateCreated()); + + $doc->addRelationship( + PhabricatorSearchRelationship::RELATIONSHIP_OWNER, + $initiative->getOwnerPHID(), + PhabricatorPeopleUserPHIDType::TYPECONST, + $initiative->getDateCreated()); + + $doc->addRelationship( + $initiative->isClosed() + ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED + : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, + $initiative->getPHID(), + FundInitiativePHIDType::TYPECONST, + time()); + + $this->indexTransactions( + $doc, + new FundInitiativeTransactionQuery(), + array($initiative->getPHID())); + + return $doc; + } +}