Skip to content

Commit d1f1d3e

Browse files
author
epriestley
committedDec 27, 2015
Implement a basic project.search third-generation API method
Summary: Ref T10010. This still needs support for attachments (to get members) and more constraints (like slugs), but mostly works. Test Plan: Ran query, saw basically sensible results. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10010 Differential Revision: https://secure.phabricator.com/D14889
1 parent 211a6c0 commit d1f1d3e

5 files changed

+85
-3
lines changed
 

‎src/__phutil_library_map__.php

+3
Original file line numberDiff line numberDiff line change
@@ -3747,6 +3747,7 @@
37473747
'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php',
37483748
'ProjectRemarkupRuleTestCase' => 'applications/project/remarkup/__tests__/ProjectRemarkupRuleTestCase.php',
37493749
'ProjectReplyHandler' => 'applications/project/mail/ProjectReplyHandler.php',
3750+
'ProjectSearchConduitAPIMethod' => 'applications/project/conduit/ProjectSearchConduitAPIMethod.php',
37503751
'QueryFormattingTestCase' => 'infrastructure/storage/__tests__/QueryFormattingTestCase.php',
37513752
'ReleephAuthorFieldSpecification' => 'applications/releeph/field/specification/ReleephAuthorFieldSpecification.php',
37523753
'ReleephBranch' => 'applications/releeph/storage/ReleephBranch.php',
@@ -7146,6 +7147,7 @@
71467147
'PhabricatorCustomFieldInterface',
71477148
'PhabricatorDestructibleInterface',
71487149
'PhabricatorFulltextInterface',
7150+
'PhabricatorConduitResultInterface',
71497151
),
71507152
'PhabricatorProjectAddHeraldAction' => 'PhabricatorProjectHeraldAction',
71517153
'PhabricatorProjectApplication' => 'PhabricatorApplication',
@@ -8296,6 +8298,7 @@
82968298
'ProjectRemarkupRule' => 'PhabricatorObjectRemarkupRule',
82978299
'ProjectRemarkupRuleTestCase' => 'PhabricatorTestCase',
82988300
'ProjectReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
8301+
'ProjectSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
82998302
'QueryFormattingTestCase' => 'PhabricatorTestCase',
83008303
'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification',
83018304
'ReleephBranch' => array(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
final class ProjectSearchConduitAPIMethod
4+
extends PhabricatorSearchEngineAPIMethod {
5+
6+
public function getAPIMethodName() {
7+
return 'project.search';
8+
}
9+
10+
public function newSearchEngine() {
11+
return new PhabricatorProjectSearchEngine();
12+
}
13+
14+
public function getMethodSummary() {
15+
return pht('Read information about projects.');
16+
}
17+
18+
protected function getCustomQueryMaps($query) {
19+
return array(
20+
'slugMap' => $query->getSlugMap(),
21+
);
22+
}
23+
24+
}

‎src/applications/project/storage/PhabricatorProject.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ final class PhabricatorProject extends PhabricatorProjectDAO
99
PhabricatorSubscribableInterface,
1010
PhabricatorCustomFieldInterface,
1111
PhabricatorDestructibleInterface,
12-
PhabricatorFulltextInterface {
12+
PhabricatorFulltextInterface,
13+
PhabricatorConduitResultInterface {
1314

1415
protected $name;
1516
protected $status = PhabricatorProjectStatus::STATUS_ACTIVE;
@@ -525,4 +526,32 @@ public function newFulltextEngine() {
525526
return new PhabricatorProjectFulltextEngine();
526527
}
527528

529+
530+
/* -( PhabricatorConduitResultInterface )---------------------------------- */
531+
532+
533+
public function getFieldSpecificationsForConduit() {
534+
return array(
535+
id(new PhabricatorConduitSearchFieldSpecification())
536+
->setKey('name')
537+
->setType('string')
538+
->setDescription(pht('The name of the project.')),
539+
id(new PhabricatorConduitSearchFieldSpecification())
540+
->setKey('slug')
541+
->setType('string')
542+
->setDescription(pht('Primary slug/hashtag.')),
543+
);
544+
}
545+
546+
public function getFieldValuesForConduit() {
547+
return array(
548+
'name' => $this->getName(),
549+
'slug' => $this->getPrimarySlug(),
550+
);
551+
}
552+
553+
public function getConduitSearchAttachments() {
554+
return array();
555+
}
556+
528557
}

‎src/applications/search/engine/PhabricatorApplicationSearchEngine.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,9 @@ public function getSearchFieldsForConduit() {
10811081
return $fields;
10821082
}
10831083

1084-
public function buildConduitResponse(ConduitAPIRequest $request) {
1084+
public function buildConduitResponse(
1085+
ConduitAPIRequest $request,
1086+
ConduitAPIMethod $method) {
10851087
$viewer = $this->requireViewer();
10861088

10871089
$query_key = $request->getValue('queryKey');
@@ -1172,6 +1174,12 @@ public function buildConduitResponse(ConduitAPIRequest $request) {
11721174
$attachment_specs[$key]);
11731175
}
11741176

1177+
// If this is empty, we still want to emit a JSON object, not a
1178+
// JSON list.
1179+
if (!$attachment_map) {
1180+
$attachment_map = (object)$attachment_map;
1181+
}
1182+
11751183
$id = (int)$object->getID();
11761184
$phid = $object->getPHID();
11771185

@@ -1187,6 +1195,7 @@ public function buildConduitResponse(ConduitAPIRequest $request) {
11871195

11881196
return array(
11891197
'data' => $data,
1198+
'maps' => $method->getQueryMaps($query),
11901199
'query' => array(
11911200
'queryKey' => $saved_query->getQueryKey(),
11921201
),

‎src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ abstract class PhabricatorSearchEngineAPIMethod
55

66
abstract public function newSearchEngine();
77

8+
final public function getQueryMaps($query) {
9+
$maps = $this->getCustomQueryMaps($query);
10+
11+
// Make sure we emit empty maps as objects, not lists.
12+
foreach ($maps as $key => $map) {
13+
if (!$map) {
14+
$maps[$key] = (object)$map;
15+
}
16+
}
17+
18+
return $maps;
19+
}
20+
21+
protected function getCustomQueryMaps($query) {
22+
return array();
23+
}
24+
825
public function getApplication() {
926
$engine = $this->newSearchEngine();
1027
$class = $engine->getApplicationClassName();
@@ -36,7 +53,7 @@ final protected function execute(ConduitAPIRequest $request) {
3653
$engine = $this->newSearchEngine()
3754
->setViewer($request->getUser());
3855

39-
return $engine->buildConduitResponse($request);
56+
return $engine->buildConduitResponse($request, $this);
4057
}
4158

4259
final public function getMethodDescription() {

0 commit comments

Comments
 (0)
Failed to load comments.