2012-01-06 04:02:50 +01:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class ManiphestUpdateConduitAPIMethod extends ManiphestConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'maniphest.update';
|
|
|
|
}
|
2012-01-06 04:02:50 +01:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2015-05-22 09:27:56 +02:00
|
|
|
return pht('Update an existing Maniphest task.');
|
2012-01-06 04:02:50 +01:00
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineErrorTypes() {
|
2012-05-20 01:18:13 +02:00
|
|
|
return array(
|
2015-05-22 09:27:56 +02:00
|
|
|
'ERR-BAD-TASK' => pht('No such Maniphest task exists.'),
|
|
|
|
'ERR-INVALID-PARAMETER' => pht('Missing or malformed parameter.'),
|
|
|
|
'ERR-NO-EFFECT' => pht('Update has no effect.'),
|
2012-05-20 01:18:13 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineParamTypes() {
|
2012-01-06 04:02:50 +01:00
|
|
|
return $this->getTaskFields($is_new = false);
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineReturnType() {
|
2012-01-06 04:02:50 +01:00
|
|
|
return 'nonempty dict';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
|
|
$id = $request->getValue('id');
|
|
|
|
$phid = $request->getValue('phid');
|
|
|
|
|
|
|
|
if (($id && $phid) || (!$id && !$phid)) {
|
2015-05-22 09:27:56 +02:00
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
"Specify exactly one of '%s' and '%s'.",
|
|
|
|
'id',
|
|
|
|
'phid'));
|
2012-01-06 04:02:50 +01:00
|
|
|
}
|
|
|
|
|
2014-12-18 22:53:45 +01:00
|
|
|
$query = id (new ManiphestTaskQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->needSubscriberPHIDs(true)
|
|
|
|
->needProjectPHIDs(true);
|
2012-01-06 04:02:50 +01:00
|
|
|
if ($id) {
|
2014-12-18 22:53:45 +01:00
|
|
|
$query->withIDs(array($id));
|
2012-01-06 04:02:50 +01:00
|
|
|
} else {
|
2014-12-18 22:53:45 +01:00
|
|
|
$query->withPHIDs(array($phid));
|
2012-01-06 04:02:50 +01:00
|
|
|
}
|
2014-12-18 22:53:45 +01:00
|
|
|
$task = $query->executeOne();
|
2012-01-06 04:02:50 +01:00
|
|
|
|
2013-05-17 13:13:58 +02:00
|
|
|
$params = $request->getAllParameters();
|
|
|
|
unset($params['id']);
|
|
|
|
unset($params['phid']);
|
|
|
|
|
Check for null, strictly, in maniphest.update param validation
Summary:
If the first non-null entry in the params array is falsey, the request bombs.
Something like {"id":279,"projectPHIDs":[],"status":"0","ownerPHID":"PHID-USER-on3xxsnaljmfn36d4b7a"}
Test Plan:
Before:
echo '{"id":279,"projectPHIDs":[],"status":"0","ownerPHID":"PHID-USER-cj3cpuh7oorbmnn2pl5g"}' | arc call-conduit maniphest.update
{"error":"ERR-NO-EFFECT","errorMessage":"ERR-NO-EFFECT: Update has no effect.","response":null}
After:
echo '{"id":279,"projectPHIDs":[],"status":"0","ownerPHID":"PHID-USER-cj3cpuh7oorbmnn2pl5g"}' | arc call-conduit maniphest.update
{"error":null,"errorMessage":null,"response":{"id":"279","phid":"PHID-TASK-lbwcq3pmur2c5fuqqhlx"...
Reviewers: garoevans, epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran
Differential Revision: https://secure.phabricator.com/D8391
2014-03-04 20:42:18 +01:00
|
|
|
if (call_user_func_array('coalesce', $params) === null) {
|
2013-05-17 13:13:58 +02:00
|
|
|
throw new ConduitException('ERR-NO-EFFECT');
|
|
|
|
}
|
|
|
|
|
2012-01-06 04:02:50 +01:00
|
|
|
if (!$task) {
|
|
|
|
throw new ConduitException('ERR-BAD-TASK');
|
|
|
|
}
|
|
|
|
|
2014-12-11 01:27:30 +01:00
|
|
|
$task = $this->applyRequest($task, $request, $is_new = false);
|
2012-01-06 04:02:50 +01:00
|
|
|
|
|
|
|
return $this->buildTaskInfoDictionary($task);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|