From 8101bf74e9ce8935808a615f4581f0821c8aa876 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 15 Feb 2018 06:08:52 -0800 Subject: [PATCH] Introduce a "phriction.content.search" API method to replace "phriction.history" Summary: Depends on D19096. Ref T13077. Adds a new "v3" API method for Phriction document content, to replace the existing "phriction.history" call. Test Plan: Made various calls via web API console. Maniphest Tasks: T13077 Differential Revision: https://secure.phabricator.com/D19097 --- src/__phutil_library_map__.php | 5 ++ ...PhrictionContentSearchConduitAPIMethod.php | 18 +++++ .../query/PhrictionContentSearchEngine.php | 76 +++++++++++++++++++ .../phriction/storage/PhrictionContent.php | 36 ++++++++- 4 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/applications/phriction/conduit/PhrictionContentSearchConduitAPIMethod.php create mode 100644 src/applications/phriction/query/PhrictionContentSearchEngine.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 2eb9a1893b..3f42c58c66 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4847,6 +4847,8 @@ phutil_register_library_map(array( 'PhrictionContent' => 'applications/phriction/storage/PhrictionContent.php', 'PhrictionContentPHIDType' => 'applications/phriction/phid/PhrictionContentPHIDType.php', 'PhrictionContentQuery' => 'applications/phriction/query/PhrictionContentQuery.php', + 'PhrictionContentSearchConduitAPIMethod' => 'applications/phriction/conduit/PhrictionContentSearchConduitAPIMethod.php', + 'PhrictionContentSearchEngine' => 'applications/phriction/query/PhrictionContentSearchEngine.php', 'PhrictionController' => 'applications/phriction/controller/PhrictionController.php', 'PhrictionCreateConduitAPIMethod' => 'applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php', 'PhrictionDAO' => 'applications/phriction/storage/PhrictionDAO.php', @@ -10759,9 +10761,12 @@ phutil_register_library_map(array( 'PhrictionDAO', 'PhabricatorPolicyInterface', 'PhabricatorDestructibleInterface', + 'PhabricatorConduitResultInterface', ), 'PhrictionContentPHIDType' => 'PhabricatorPHIDType', 'PhrictionContentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhrictionContentSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', + 'PhrictionContentSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhrictionController' => 'PhabricatorController', 'PhrictionCreateConduitAPIMethod' => 'PhrictionConduitAPIMethod', 'PhrictionDAO' => 'PhabricatorLiskDAO', diff --git a/src/applications/phriction/conduit/PhrictionContentSearchConduitAPIMethod.php b/src/applications/phriction/conduit/PhrictionContentSearchConduitAPIMethod.php new file mode 100644 index 0000000000..2f40130782 --- /dev/null +++ b/src/applications/phriction/conduit/PhrictionContentSearchConduitAPIMethod.php @@ -0,0 +1,18 @@ +newQuery(); + + if ($map['documentPHIDs']) { + $query->withDocumentPHIDs($map['documentPHIDs']); + } + + if ($map['versions']) { + $query->withVersions($map['versions']); + } + + return $query; + } + + protected function buildCustomSearchFields() { + return array( + id(new PhabricatorPHIDsSearchField()) + ->setKey('documentPHIDs') + ->setAliases(array('document', 'documents', 'documentPHID')) + ->setLabel(pht('Documents')), + id(new PhabricatorIDsSearchField()) + ->setKey('versions') + ->setAliases(array('version')), + ); + } + + protected function getURI($path) { + // There's currently no web UI for this search interface, it exists purely + // to power the Conduit API. + throw new PhutilMethodNotImplementedException(); + } + + protected function getBuiltinQueryNames() { + return array( + 'all' => pht('All Content'), + ); + } + + public function buildSavedQueryFromBuiltin($query_key) { + $query = $this->newSavedQuery(); + $query->setQueryKey($query_key); + + switch ($query_key) { + case 'all': + return $query; + } + + return parent::buildSavedQueryFromBuiltin($query_key); + } + + protected function renderResultList( + array $contents, + PhabricatorSavedQuery $query, + array $handles) { + assert_instances_of($contents, 'PhrictionContent'); + throw new PhutilMethodNotImplementedException(); + } + +} diff --git a/src/applications/phriction/storage/PhrictionContent.php b/src/applications/phriction/storage/PhrictionContent.php index 390da64682..dc6bf19faa 100644 --- a/src/applications/phriction/storage/PhrictionContent.php +++ b/src/applications/phriction/storage/PhrictionContent.php @@ -4,7 +4,8 @@ final class PhrictionContent extends PhrictionDAO implements PhabricatorPolicyInterface, - PhabricatorDestructibleInterface { + PhabricatorDestructibleInterface, + PhabricatorConduitResultInterface { protected $documentID; protected $version; @@ -103,4 +104,37 @@ final class PhrictionContent $this->delete(); } + +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + + public function getFieldSpecificationsForConduit() { + return array( + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('documentPHID') + ->setType('phid') + ->setDescription(pht('Document this content is for.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('version') + ->setType('int') + ->setDescription(pht('Content version.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('authorPHID') + ->setType('phid') + ->setDescription(pht('Author of this version of the content.')), + ); + } + + public function getFieldValuesForConduit() { + return array( + 'documentPHID' => $this->getDocument()->getPHID(), + 'version' => (int)$this->getVersion(), + 'authorPHID' => $this->getAuthorPHID(), + ); + } + + public function getConduitSearchAttachments() { + return array(); + } + }