mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-02 01:48:23 +01:00
Add project.query to Conduit
Summary: Add a conduit method to query project information. Test Plan: Ran method from API test console. Reviewers: bill, btrahan, jungejason Reviewed By: btrahan CC: aran Maniphest Tasks: T681 Differential Revision: https://secure.phabricator.com/D1444
This commit is contained in:
parent
6472dbe168
commit
42ddad1bc8
7 changed files with 242 additions and 5 deletions
|
@ -141,6 +141,8 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_phriction_edit_Method' => 'applications/conduit/method/phriction/edit',
|
'ConduitAPI_phriction_edit_Method' => 'applications/conduit/method/phriction/edit',
|
||||||
'ConduitAPI_phriction_history_Method' => 'applications/conduit/method/phriction/history',
|
'ConduitAPI_phriction_history_Method' => 'applications/conduit/method/phriction/history',
|
||||||
'ConduitAPI_phriction_info_Method' => 'applications/conduit/method/phriction/info',
|
'ConduitAPI_phriction_info_Method' => 'applications/conduit/method/phriction/info',
|
||||||
|
'ConduitAPI_project_Method' => 'applications/conduit/method/project/base',
|
||||||
|
'ConduitAPI_project_query_Method' => 'applications/conduit/method/project/query',
|
||||||
'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info',
|
'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info',
|
||||||
'ConduitAPI_user_Method' => 'applications/conduit/method/user/base',
|
'ConduitAPI_user_Method' => 'applications/conduit/method/user/base',
|
||||||
'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find',
|
'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find',
|
||||||
|
@ -903,6 +905,8 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_phriction_edit_Method' => 'ConduitAPI_phriction_Method',
|
'ConduitAPI_phriction_edit_Method' => 'ConduitAPI_phriction_Method',
|
||||||
'ConduitAPI_phriction_history_Method' => 'ConduitAPI_phriction_Method',
|
'ConduitAPI_phriction_history_Method' => 'ConduitAPI_phriction_Method',
|
||||||
'ConduitAPI_phriction_info_Method' => 'ConduitAPI_phriction_Method',
|
'ConduitAPI_phriction_info_Method' => 'ConduitAPI_phriction_Method',
|
||||||
|
'ConduitAPI_project_Method' => 'ConduitAPIMethod',
|
||||||
|
'ConduitAPI_project_query_Method' => 'ConduitAPI_project_Method',
|
||||||
'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_user_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_user_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method',
|
'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method',
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group conduit
|
||||||
|
*/
|
||||||
|
abstract class ConduitAPI_project_Method extends ConduitAPIMethod {
|
||||||
|
|
||||||
|
protected function buildProjectInfoDictionary(PhabricatorProject $project) {
|
||||||
|
$results = $this->buildProjectInfoDictionaries(array($project));
|
||||||
|
return idx($results, $project->getPHID());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildProjectInfoDictionaries(array $projects) {
|
||||||
|
if (!$projects) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
foreach ($projects as $project) {
|
||||||
|
|
||||||
|
$member_phids = mpull($project->getAffiliations(), 'getUserPHID');
|
||||||
|
$member_phids = array_values($member_phids);
|
||||||
|
|
||||||
|
$result[$project->getPHID()] = array(
|
||||||
|
'id' => $project->getID(),
|
||||||
|
'phid' => $project->getPHID(),
|
||||||
|
'name' => $project->getName(),
|
||||||
|
'members' => $member_phids,
|
||||||
|
'dateCreated' => $project->getDateCreated(),
|
||||||
|
'dateModified' => $project->getDateModified(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/applications/conduit/method/project/base/__init__.php
Normal file
14
src/applications/conduit/method/project/base/__init__.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is automatically generated. Lint this module to rebuild it.
|
||||||
|
* @generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
||||||
|
|
||||||
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_source('ConduitAPI_project_Method.php');
|
|
@ -0,0 +1,82 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group conduit
|
||||||
|
*/
|
||||||
|
final class ConduitAPI_project_query_Method extends ConduitAPI_project_Method {
|
||||||
|
|
||||||
|
public function getMethodDescription() {
|
||||||
|
return "Execute searches for Projects.";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineParamTypes() {
|
||||||
|
return array(
|
||||||
|
'ids' => 'optional list<int>',
|
||||||
|
'phids' => 'optional list<phid>',
|
||||||
|
|
||||||
|
'members' => 'optional list<phid>',
|
||||||
|
|
||||||
|
'limit' => 'optional int',
|
||||||
|
'offset' => 'optional int',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineReturnType() {
|
||||||
|
return 'list';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineErrorTypes() {
|
||||||
|
return array(
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
|
$query = new PhabricatorProjectQuery();
|
||||||
|
$query->needMembers(true);
|
||||||
|
|
||||||
|
$ids = $request->getValue('ids');
|
||||||
|
if ($ids) {
|
||||||
|
$query->withIDs($ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
$phids = $request->getValue('phids');
|
||||||
|
if ($phids) {
|
||||||
|
$query->withPHIDs($phids);
|
||||||
|
}
|
||||||
|
|
||||||
|
$members = $request->getValue('members');
|
||||||
|
if ($members) {
|
||||||
|
$query->setMembers($members);
|
||||||
|
}
|
||||||
|
|
||||||
|
$limit = $request->getValue('limit');
|
||||||
|
if ($limit) {
|
||||||
|
$query->setLimit($limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
$offset = $request->getValue('offset');
|
||||||
|
if ($offset) {
|
||||||
|
$query->setOffset($offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
$results = $query->execute();
|
||||||
|
return $this->buildProjectInfoDictionaries($results);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
13
src/applications/conduit/method/project/query/__init__.php
Normal file
13
src/applications/conduit/method/project/query/__init__.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is automatically generated. Lint this module to rebuild it.
|
||||||
|
* @generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_module('phabricator', 'applications/conduit/method/project/base');
|
||||||
|
phutil_require_module('phabricator', 'applications/project/query/project');
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_source('ConduitAPI_project_query_Method.php');
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Facebook, Inc.
|
* Copyright 2012 Facebook, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -18,12 +18,26 @@
|
||||||
|
|
||||||
final class PhabricatorProjectQuery {
|
final class PhabricatorProjectQuery {
|
||||||
|
|
||||||
|
private $ids;
|
||||||
|
private $phids;
|
||||||
private $owners;
|
private $owners;
|
||||||
private $members;
|
private $members;
|
||||||
|
|
||||||
private $limit;
|
private $limit;
|
||||||
private $offset;
|
private $offset;
|
||||||
|
|
||||||
|
private $needMembers;
|
||||||
|
|
||||||
|
public function withIDs(array $ids) {
|
||||||
|
$this->ids = $ids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withPHIDs(array $phids) {
|
||||||
|
$this->phids = $phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setLimit($limit) {
|
public function setLimit($limit) {
|
||||||
$this->limit = $limit;
|
$this->limit = $limit;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -44,13 +58,19 @@ final class PhabricatorProjectQuery {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function needMembers($need_members) {
|
||||||
|
$this->needMembers = $need_members;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function execute() {
|
public function execute() {
|
||||||
$table = id(new PhabricatorProject());
|
$table = id(new PhabricatorProject());
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
|
$where = $this->buildWhereClause($conn_r);
|
||||||
$joins = $this->buildJoinsClause($conn_r);
|
$joins = $this->buildJoinsClause($conn_r);
|
||||||
|
|
||||||
$limit = null;
|
$limit = '';
|
||||||
if ($this->limit) {
|
if ($this->limit) {
|
||||||
$limit = qsprintf(
|
$limit = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
|
@ -69,13 +89,51 @@ final class PhabricatorProjectQuery {
|
||||||
|
|
||||||
$data = queryfx_all(
|
$data = queryfx_all(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'SELECT p.* FROM %T p %Q %Q %Q',
|
'SELECT p.* FROM %T p %Q %Q %Q %Q',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
$joins,
|
$joins,
|
||||||
|
$where,
|
||||||
$order,
|
$order,
|
||||||
$limit);
|
$limit);
|
||||||
|
|
||||||
return $table->loadAllFromArray($data);
|
$projects = $table->loadAllFromArray($data);
|
||||||
|
|
||||||
|
if ($projects && $this->needMembers) {
|
||||||
|
$members = PhabricatorProjectAffiliation::loadAllForProjectPHIDs(
|
||||||
|
mpull($projects, 'getPHID'));
|
||||||
|
foreach ($projects as $project) {
|
||||||
|
$project->attachAffiliations(
|
||||||
|
array_values(idx($members, $project->getPHID(), array())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $projects;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildWhereClause($conn_r) {
|
||||||
|
$where = array();
|
||||||
|
|
||||||
|
if ($this->ids) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'id IN (%Ld)',
|
||||||
|
$this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->phids) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'phid IN (%Ls)',
|
||||||
|
$this->phids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($where) {
|
||||||
|
$where = 'WHERE ('.implode(') AND (', $where).')';
|
||||||
|
} else {
|
||||||
|
$where = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $where;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildJoinsClause($conn_r) {
|
private function buildJoinsClause($conn_r) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Facebook, Inc.
|
* Copyright 2012 Facebook, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -26,6 +26,7 @@ class PhabricatorProject extends PhabricatorProjectDAO {
|
||||||
protected $phrictionSlug;
|
protected $phrictionSlug;
|
||||||
|
|
||||||
private $subprojectsNeedUpdate;
|
private $subprojectsNeedUpdate;
|
||||||
|
private $affiliations;
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
|
@ -54,6 +55,18 @@ class PhabricatorProject extends PhabricatorProjectDAO {
|
||||||
return $profile;
|
return $profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAffiliations() {
|
||||||
|
if ($this->affiliations === null) {
|
||||||
|
throw new Exception('Attach affiliations first!');
|
||||||
|
}
|
||||||
|
return $this->affiliations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachAffiliations(array $affiliations) {
|
||||||
|
$this->affiliations = $affiliations;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function loadAffiliations() {
|
public function loadAffiliations() {
|
||||||
$affils = PhabricatorProjectAffiliation::loadAllForProjectPHIDs(
|
$affils = PhabricatorProjectAffiliation::loadAllForProjectPHIDs(
|
||||||
array($this->getPHID()));
|
array($this->getPHID()));
|
||||||
|
|
Loading…
Add table
Reference in a new issue