Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/conduit/DifferentialUpdateRevisionConduitAPIMethod.php
12256 views
1
<?php
2
3
final class DifferentialUpdateRevisionConduitAPIMethod
4
extends DifferentialConduitAPIMethod {
5
6
public function getAPIMethodName() {
7
return 'differential.updaterevision';
8
}
9
10
public function getMethodDescription() {
11
return pht('Update a Differential revision.');
12
}
13
14
public function getMethodStatus() {
15
return self::METHOD_STATUS_FROZEN;
16
}
17
18
public function getMethodStatusDescription() {
19
return pht(
20
'This method is frozen and will eventually be deprecated. New code '.
21
'should use "differential.revision.edit" instead.');
22
}
23
24
protected function defineParamTypes() {
25
return array(
26
'id' => 'required revisionid',
27
'diffid' => 'required diffid',
28
'fields' => 'required dict',
29
'message' => 'required string',
30
);
31
}
32
33
protected function defineReturnType() {
34
return 'nonempty dict';
35
}
36
37
protected function defineErrorTypes() {
38
return array(
39
'ERR_BAD_DIFF' => pht('Bad diff ID.'),
40
'ERR_BAD_REVISION' => pht('Bad revision ID.'),
41
'ERR_WRONG_USER' => pht('You are not the author of this revision.'),
42
'ERR_CLOSED' => pht('This revision has already been closed.'),
43
);
44
}
45
46
protected function execute(ConduitAPIRequest $request) {
47
$viewer = $request->getUser();
48
49
$diff = id(new DifferentialDiffQuery())
50
->setViewer($viewer)
51
->withIDs(array($request->getValue('diffid')))
52
->executeOne();
53
if (!$diff) {
54
throw new ConduitException('ERR_BAD_DIFF');
55
}
56
57
$revision = id(new DifferentialRevisionQuery())
58
->setViewer($request->getUser())
59
->withIDs(array($request->getValue('id')))
60
->needReviewers(true)
61
->needActiveDiffs(true)
62
->requireCapabilities(
63
array(
64
PhabricatorPolicyCapability::CAN_VIEW,
65
PhabricatorPolicyCapability::CAN_EDIT,
66
))
67
->executeOne();
68
if (!$revision) {
69
throw new ConduitException('ERR_BAD_REVISION');
70
}
71
72
if ($revision->isPublished()) {
73
throw new ConduitException('ERR_CLOSED');
74
}
75
76
$this->applyFieldEdit(
77
$request,
78
$revision,
79
$diff,
80
$request->getValue('fields', array()),
81
$request->getValue('message'));
82
83
return array(
84
'revisionid' => $revision->getID(),
85
'uri' => PhabricatorEnv::getURI('/D'.$revision->getID()),
86
);
87
}
88
89
}
90
91