mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Include project slugs in the results of a project.query
Conduit call.
Summary: Ref T4418. This feature will be used by D9457 to determine whether the specified slugs exist. Test Plan: Made a conduit call with `arc`: ``` > echo '{"slugs": ["foo"]}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit project.query Waiting for JSON parameters on stdin... {"error":null,"errorMessage":null,"response":{"data":{"PHID-PROJ-ttomlhslujpx5sdpbu2c":{"id":"1","phid":"PHID-PROJ-ttomlhslujpx5sdpbu2c","name":"Foo","members":["PHID-USER-cb5af6p4oepy5tlgqypi"],"slugs":["foo","bar"],"dateCreated":"1402422720","dateModified":"1402422728"}},"slugMap":{"foo":"PHID-PROJ-ttomlhslujpx5sdpbu2c"},"cursor":{"limit":100,"after":null,"before":null}}} ``` Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T4418 Differential Revision: https://secure.phabricator.com/D9619
This commit is contained in:
parent
85e9f8374a
commit
3964336722
2 changed files with 25 additions and 2 deletions
|
@ -27,11 +27,15 @@ abstract class ConduitAPI_project_Method extends ConduitAPIMethod {
|
|||
$member_phids = $project->getMemberPHIDs();
|
||||
$member_phids = array_values($member_phids);
|
||||
|
||||
$project_slugs = $project->getSlugs();
|
||||
$project_slugs = array_values(mpull($project_slugs, 'getSlug'));
|
||||
|
||||
$result[$project->getPHID()] = array(
|
||||
'id' => $project->getID(),
|
||||
'phid' => $project->getPHID(),
|
||||
'name' => $project->getName(),
|
||||
'members' => $member_phids,
|
||||
'slugs' => $project_slugs,
|
||||
'dateCreated' => $project->getDateCreated(),
|
||||
'dateModified' => $project->getDateModified(),
|
||||
);
|
||||
|
|
|
@ -46,6 +46,7 @@ final class ConduitAPI_project_query_Method extends ConduitAPI_project_Method {
|
|||
$query = new PhabricatorProjectQuery();
|
||||
$query->setViewer($request->getUser());
|
||||
$query->needMembers(true);
|
||||
$query->needSlugs(true);
|
||||
|
||||
$ids = $request->getValue('ids');
|
||||
if ($ids) {
|
||||
|
@ -82,8 +83,26 @@ final class ConduitAPI_project_query_Method extends ConduitAPI_project_Method {
|
|||
$query->setOffset($offset);
|
||||
}
|
||||
|
||||
$results = $query->execute();
|
||||
return $this->buildProjectInfoDictionaries($results);
|
||||
$pager = $this->newPager($request);
|
||||
$results = $query->executeWithCursorPager($pager);
|
||||
$projects = $this->buildProjectInfoDictionaries($results);
|
||||
|
||||
// TODO: This is pretty hideous.
|
||||
$slug_map = array();
|
||||
foreach ($slugs as $slug) {
|
||||
foreach ($projects as $project) {
|
||||
if (in_array($slug, $project['slugs'])) {
|
||||
$slug_map[$slug] = $project['phid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'data' => $projects,
|
||||
'slugMap' => $slug_map,
|
||||
);
|
||||
|
||||
return $this->addPagerResults($result, $pager);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue