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() {
|
2014-06-09 20:36:49 +02:00
|
|
|
return 'Update an existing Maniphest task.';
|
2012-01-06 04:02:50 +01:00
|
|
|
}
|
|
|
|
|
2012-05-20 01:18:13 +02:00
|
|
|
public function defineErrorTypes() {
|
|
|
|
return array(
|
|
|
|
'ERR-BAD-TASK' => 'No such maniphest task exists.',
|
2013-05-17 13:13:58 +02:00
|
|
|
'ERR-INVALID-PARAMETER' => 'Missing or malformed parameter.',
|
|
|
|
'ERR-NO-EFFECT' => 'Update has no effect.',
|
2012-05-20 01:18:13 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-01-06 04:02:50 +01:00
|
|
|
public function defineParamTypes() {
|
|
|
|
return $this->getTaskFields($is_new = false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineReturnType() {
|
|
|
|
return 'nonempty dict';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
|
|
$id = $request->getValue('id');
|
|
|
|
$phid = $request->getValue('phid');
|
|
|
|
|
|
|
|
if (($id && $phid) || (!$id && !$phid)) {
|
|
|
|
throw new Exception("Specify exactly one of 'id' and 'phid'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($id) {
|
2013-09-25 22:44:14 +02:00
|
|
|
$task = id(new ManiphestTaskQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->withIDs(array($id))
|
2014-12-11 01:27:30 +01:00
|
|
|
->needSubscriberPHIDs(true)
|
2013-09-25 22:44:14 +02:00
|
|
|
->executeOne();
|
2012-01-06 04:02:50 +01:00
|
|
|
} else {
|
2013-09-25 22:44:14 +02:00
|
|
|
$task = id(new ManiphestTaskQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->withPHIDs(array($phid))
|
2014-12-11 01:27:30 +01:00
|
|
|
->needSubscriberPHIDs(true)
|
2013-09-25 22:44:14 +02:00
|
|
|
->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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|