1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Add specific close status queries to maniphest.find (and rename it to maniphest.query)

Summary:
  - Allow clients to query for specific closed statuses (invalid, resolved, wontfix, etc), not just "closed" tasks.
  - Rename this method to maniphest.query and deprecate maniphest.find as an alias to maniphest.query, for API consistency.

Test Plan: Ran queries for all tasks, "wontfix" tasks, closed tasks.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D2887
This commit is contained in:
epriestley 2012-06-29 09:17:19 -07:00
parent 3223defe96
commit 2bb8150506
4 changed files with 163 additions and 91 deletions

View file

@ -170,6 +170,7 @@ phutil_register_library_map(array(
'ConduitAPI_maniphest_find_Method' => 'applications/conduit/method/maniphest/ConduitAPI_maniphest_find_Method.php',
'ConduitAPI_maniphest_gettasktransactions_Method' => 'applications/conduit/method/maniphest/ConduitAPI_maniphest_gettasktransactions_Method.php',
'ConduitAPI_maniphest_info_Method' => 'applications/conduit/method/maniphest/ConduitAPI_maniphest_info_Method.php',
'ConduitAPI_maniphest_query_Method' => 'applications/conduit/method/maniphest/ConduitAPI_maniphest_query_Method.php',
'ConduitAPI_maniphest_update_Method' => 'applications/conduit/method/maniphest/ConduitAPI_maniphest_update_Method.php',
'ConduitAPI_owners_query_Method' => 'applications/conduit/method/owners/ConduitAPI_owners_query_Method.php',
'ConduitAPI_paste_Method' => 'applications/conduit/method/paste/ConduitAPI_paste_Method.php',
@ -1244,9 +1245,10 @@ phutil_register_library_map(array(
'ConduitAPI_macro_query_Method' => 'ConduitAPI_macro_Method',
'ConduitAPI_maniphest_Method' => 'ConduitAPIMethod',
'ConduitAPI_maniphest_createtask_Method' => 'ConduitAPI_maniphest_Method',
'ConduitAPI_maniphest_find_Method' => 'ConduitAPI_maniphest_Method',
'ConduitAPI_maniphest_find_Method' => 'ConduitAPI_maniphest_query_Method',
'ConduitAPI_maniphest_gettasktransactions_Method' => 'ConduitAPI_maniphest_Method',
'ConduitAPI_maniphest_info_Method' => 'ConduitAPI_maniphest_Method',
'ConduitAPI_maniphest_query_Method' => 'ConduitAPI_maniphest_Method',
'ConduitAPI_maniphest_update_Method' => 'ConduitAPI_maniphest_Method',
'ConduitAPI_owners_query_Method' => 'ConduitAPIMethod',
'ConduitAPI_paste_Method' => 'ConduitAPIMethod',

View file

@ -1,7 +1,7 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
* 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.
@ -18,98 +18,22 @@
/**
* @group conduit
*
* @concrete-extensible
*/
final class ConduitAPI_maniphest_find_Method
extends ConduitAPI_maniphest_Method {
extends ConduitAPI_maniphest_query_Method {
public function getMethodStatus() {
return self::METHOD_STATUS_DEPRECATED;
}
public function getMethodStatusDescription() {
return "Renamed to 'maniphest.query'.";
}
public function getMethodDescription() {
return "Execute complex searches for Maniphest tasks.";
}
public function defineParamTypes() {
$orders = array(
ManiphestTaskQuery::ORDER_PRIORITY,
ManiphestTaskQuery::ORDER_CREATED,
ManiphestTaskQuery::ORDER_MODIFIED,
);
$orders = implode(', ', $orders);
$statuses = array(
ManiphestTaskQuery::STATUS_ANY,
ManiphestTaskQuery::STATUS_OPEN,
ManiphestTaskQuery::STATUS_CLOSED,
);
$statuses = implode(', ', $statuses);
return array(
'ownerPHIDs' => 'optional list',
'authorPHIDs' => 'optional list',
'projectPHIDs' => 'optional list',
'ccPHIDs' => 'optional list',
'order' => 'optional enum<'.$orders.'>',
'status' => 'optional enum<'.$statuses.'>',
'limit' => 'optional int',
'offset' => 'optional int',
);
}
public function defineReturnType() {
return 'list';
}
public function defineErrorTypes() {
return array(
);
}
protected function execute(ConduitAPIRequest $request) {
$query = new ManiphestTaskQuery();
$owners = $request->getValue('ownerPHIDs');
if ($owners) {
$query->withOwners($owners);
}
$authors = $request->getValue('authorPHIDs');
if ($authors) {
$query->withAuthors($authors);
}
$projects = $request->getValue('projectPHIDs');
if ($projects) {
$query->withProjects($projects);
}
$ccs = $request->getValue('ccPHIDs');
if ($ccs) {
$query->withSubscribers($ccs);
}
$order = $request->getValue('order');
if ($order) {
$query->setOrderBy($order);
}
$status = $request->getValue('status');
if ($status) {
$query->withStatus($status);
}
$limit = $request->getValue('limit');
if ($limit) {
$query->setLimit($limit);
}
$offset = $request->getValue('offset');
if ($offset) {
$query->setOffset($offset);
}
$results = $query->execute();
return $this->buildTaskInfoDictionaries($results);
return "Deprecated alias of maniphest.query";
}
}

View file

@ -0,0 +1,125 @@
<?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
*
* TODO: Remove maniphest.find, then make this final.
*
* @concrete-extensible
*/
class ConduitAPI_maniphest_query_Method
extends ConduitAPI_maniphest_Method {
public function getMethodDescription() {
return "Execute complex searches for Maniphest tasks.";
}
public function defineParamTypes() {
$orders = array(
ManiphestTaskQuery::ORDER_PRIORITY,
ManiphestTaskQuery::ORDER_CREATED,
ManiphestTaskQuery::ORDER_MODIFIED,
);
$orders = implode(', ', $orders);
$statuses = array(
ManiphestTaskQuery::STATUS_ANY,
ManiphestTaskQuery::STATUS_OPEN,
ManiphestTaskQuery::STATUS_CLOSED,
ManiphestTaskQuery::STATUS_RESOLVED,
ManiphestTaskQuery::STATUS_WONTFIX,
ManiphestTaskQuery::STATUS_INVALID,
ManiphestTaskQuery::STATUS_SPITE,
ManiphestTaskQuery::STATUS_DUPLICATE,
);
$statuses = implode(', ', $statuses);
return array(
'ownerPHIDs' => 'optional list',
'authorPHIDs' => 'optional list',
'projectPHIDs' => 'optional list',
'ccPHIDs' => 'optional list',
'order' => 'optional enum<'.$orders.'>',
'status' => 'optional enum<'.$statuses.'>',
'limit' => 'optional int',
'offset' => 'optional int',
);
}
public function defineReturnType() {
return 'list';
}
public function defineErrorTypes() {
return array(
);
}
protected function execute(ConduitAPIRequest $request) {
$query = new ManiphestTaskQuery();
$owners = $request->getValue('ownerPHIDs');
if ($owners) {
$query->withOwners($owners);
}
$authors = $request->getValue('authorPHIDs');
if ($authors) {
$query->withAuthors($authors);
}
$projects = $request->getValue('projectPHIDs');
if ($projects) {
$query->withProjects($projects);
}
$ccs = $request->getValue('ccPHIDs');
if ($ccs) {
$query->withSubscribers($ccs);
}
$order = $request->getValue('order');
if ($order) {
$query->setOrderBy($order);
}
$status = $request->getValue('status');
if ($status) {
$query->withStatus($status);
}
$limit = $request->getValue('limit');
if ($limit) {
$query->setLimit($limit);
}
$offset = $request->getValue('offset');
if ($offset) {
$query->setOffset($offset);
}
$results = $query->execute();
return $this->buildTaskInfoDictionaries($results);
}
}

View file

@ -40,6 +40,11 @@ final class ManiphestTaskQuery {
const STATUS_ANY = 'status-any';
const STATUS_OPEN = 'status-open';
const STATUS_CLOSED = 'status-closed';
const STATUS_RESOLVED = 'status-resolved';
const STATUS_WONTFIX = 'status-wontfix';
const STATUS_INVALID = 'status-invalid';
const STATUS_SPITE = 'status-spite';
const STATUS_DUPLICATE = 'status-duplicate';
private $priority = null;
@ -282,6 +287,15 @@ final class ManiphestTaskQuery {
}
private function buildStatusWhereClause($conn) {
static $map = array(
self::STATUS_RESOLVED => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED,
self::STATUS_WONTFIX => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX,
self::STATUS_INVALID => ManiphestTaskStatus::STATUS_CLOSED_INVALID,
self::STATUS_SPITE => ManiphestTaskStatus::STATUS_CLOSED_SPITE,
self::STATUS_DUPLICATE => ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE,
);
switch ($this->status) {
case self::STATUS_ANY:
return null;
@ -290,7 +304,14 @@ final class ManiphestTaskQuery {
case self::STATUS_CLOSED:
return 'status > 0';
default:
throw new Exception("Unknown status query '{$this->status}'!");
$constant = idx($map, $this->status);
if (!$constant) {
throw new Exception("Unknown status query '{$this->status}'!");
}
return qsprintf(
$conn,
'status = %d',
$constant);
}
}