diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a024d493e8..86c7b3156a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3747,6 +3747,7 @@ phutil_register_library_map(array( 'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php', 'ProjectRemarkupRuleTestCase' => 'applications/project/remarkup/__tests__/ProjectRemarkupRuleTestCase.php', 'ProjectReplyHandler' => 'applications/project/mail/ProjectReplyHandler.php', + 'ProjectSearchConduitAPIMethod' => 'applications/project/conduit/ProjectSearchConduitAPIMethod.php', 'QueryFormattingTestCase' => 'infrastructure/storage/__tests__/QueryFormattingTestCase.php', 'ReleephAuthorFieldSpecification' => 'applications/releeph/field/specification/ReleephAuthorFieldSpecification.php', 'ReleephBranch' => 'applications/releeph/storage/ReleephBranch.php', @@ -7146,6 +7147,7 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldInterface', 'PhabricatorDestructibleInterface', 'PhabricatorFulltextInterface', + 'PhabricatorConduitResultInterface', ), 'PhabricatorProjectAddHeraldAction' => 'PhabricatorProjectHeraldAction', 'PhabricatorProjectApplication' => 'PhabricatorApplication', @@ -8296,6 +8298,7 @@ phutil_register_library_map(array( 'ProjectRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'ProjectRemarkupRuleTestCase' => 'PhabricatorTestCase', 'ProjectReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', + 'ProjectSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'QueryFormattingTestCase' => 'PhabricatorTestCase', 'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification', 'ReleephBranch' => array( diff --git a/src/applications/project/conduit/ProjectSearchConduitAPIMethod.php b/src/applications/project/conduit/ProjectSearchConduitAPIMethod.php new file mode 100644 index 0000000000..c6b27d5288 --- /dev/null +++ b/src/applications/project/conduit/ProjectSearchConduitAPIMethod.php @@ -0,0 +1,24 @@ + $query->getSlugMap(), + ); + } + +} diff --git a/src/applications/project/storage/PhabricatorProject.php b/src/applications/project/storage/PhabricatorProject.php index 223333809f..afb4a32e61 100644 --- a/src/applications/project/storage/PhabricatorProject.php +++ b/src/applications/project/storage/PhabricatorProject.php @@ -9,7 +9,8 @@ final class PhabricatorProject extends PhabricatorProjectDAO PhabricatorSubscribableInterface, PhabricatorCustomFieldInterface, PhabricatorDestructibleInterface, - PhabricatorFulltextInterface { + PhabricatorFulltextInterface, + PhabricatorConduitResultInterface { protected $name; protected $status = PhabricatorProjectStatus::STATUS_ACTIVE; @@ -525,4 +526,32 @@ final class PhabricatorProject extends PhabricatorProjectDAO return new PhabricatorProjectFulltextEngine(); } + +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + + public function getFieldSpecificationsForConduit() { + return array( + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('name') + ->setType('string') + ->setDescription(pht('The name of the project.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('slug') + ->setType('string') + ->setDescription(pht('Primary slug/hashtag.')), + ); + } + + public function getFieldValuesForConduit() { + return array( + 'name' => $this->getName(), + 'slug' => $this->getPrimarySlug(), + ); + } + + public function getConduitSearchAttachments() { + return array(); + } + } diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php index df79a4e0a5..702af44c40 100644 --- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php +++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php @@ -1081,7 +1081,9 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { return $fields; } - public function buildConduitResponse(ConduitAPIRequest $request) { + public function buildConduitResponse( + ConduitAPIRequest $request, + ConduitAPIMethod $method) { $viewer = $this->requireViewer(); $query_key = $request->getValue('queryKey'); @@ -1172,6 +1174,12 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { $attachment_specs[$key]); } + // If this is empty, we still want to emit a JSON object, not a + // JSON list. + if (!$attachment_map) { + $attachment_map = (object)$attachment_map; + } + $id = (int)$object->getID(); $phid = $object->getPHID(); @@ -1187,6 +1195,7 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { return array( 'data' => $data, + 'maps' => $method->getQueryMaps($query), 'query' => array( 'queryKey' => $saved_query->getQueryKey(), ), diff --git a/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php b/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php index a299d90018..998a77126b 100644 --- a/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php +++ b/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php @@ -5,6 +5,23 @@ abstract class PhabricatorSearchEngineAPIMethod abstract public function newSearchEngine(); + final public function getQueryMaps($query) { + $maps = $this->getCustomQueryMaps($query); + + // Make sure we emit empty maps as objects, not lists. + foreach ($maps as $key => $map) { + if (!$map) { + $maps[$key] = (object)$map; + } + } + + return $maps; + } + + protected function getCustomQueryMaps($query) { + return array(); + } + public function getApplication() { $engine = $this->newSearchEngine(); $class = $engine->getApplicationClassName(); @@ -36,7 +53,7 @@ abstract class PhabricatorSearchEngineAPIMethod $engine = $this->newSearchEngine() ->setViewer($request->getUser()); - return $engine->buildConduitResponse($request); + return $engine->buildConduitResponse($request, $this); } final public function getMethodDescription() {