Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/conduit/DifferentialCreateCommentConduitAPIMethod.php
12256 views
1
<?php
2
3
final class DifferentialCreateCommentConduitAPIMethod
4
extends DifferentialConduitAPIMethod {
5
6
public function getAPIMethodName() {
7
return 'differential.createcomment';
8
}
9
10
public function getMethodDescription() {
11
return pht('Add a comment to 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
'revision_id' => 'required revisionid',
27
'message' => 'optional string',
28
'action' => 'optional string',
29
'silent' => 'optional bool',
30
'attach_inlines' => 'optional bool',
31
);
32
}
33
34
protected function defineReturnType() {
35
return 'nonempty dict';
36
}
37
38
protected function defineErrorTypes() {
39
return array(
40
'ERR_BAD_REVISION' => pht('Bad revision ID.'),
41
);
42
}
43
44
protected function execute(ConduitAPIRequest $request) {
45
$viewer = $request->getUser();
46
47
$revision = id(new DifferentialRevisionQuery())
48
->setViewer($viewer)
49
->withIDs(array($request->getValue('revision_id')))
50
->needReviewers(true)
51
->needReviewerAuthority(true)
52
->needActiveDiffs(true)
53
->executeOne();
54
if (!$revision) {
55
throw new ConduitException('ERR_BAD_REVISION');
56
}
57
58
$xactions = array();
59
60
$modular_map = array(
61
'accept' => DifferentialRevisionAcceptTransaction::TRANSACTIONTYPE,
62
'reject' => DifferentialRevisionRejectTransaction::TRANSACTIONTYPE,
63
'resign' => DifferentialRevisionResignTransaction::TRANSACTIONTYPE,
64
'request_review' =>
65
DifferentialRevisionRequestReviewTransaction::TRANSACTIONTYPE,
66
'rethink' => DifferentialRevisionPlanChangesTransaction::TRANSACTIONTYPE,
67
);
68
69
$action = $request->getValue('action');
70
if (isset($modular_map[$action])) {
71
$xactions[] = id(new DifferentialTransaction())
72
->setTransactionType($modular_map[$action])
73
->setNewValue(true);
74
} else if ($action) {
75
switch ($action) {
76
case 'comment':
77
case 'none':
78
break;
79
default:
80
throw new Exception(
81
pht(
82
'Unsupported action "%s".',
83
$action));
84
break;
85
}
86
}
87
88
$content = $request->getValue('message');
89
if (strlen($content)) {
90
$xactions[] = id(new DifferentialTransaction())
91
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
92
->attachComment(
93
id(new DifferentialTransactionComment())
94
->setContent($content));
95
}
96
97
// NOTE: The legacy "attach_inlines" flag is now ignored and has no
98
// effect. See T13513.
99
100
// NOTE: The legacy "silent" flag is now ignored and has no effect. See
101
// T13042.
102
103
$editor = id(new DifferentialTransactionEditor())
104
->setActor($viewer)
105
->setContentSource($request->newContentSource())
106
->setContinueOnNoEffect(true)
107
->setContinueOnMissingFields(true);
108
109
$editor->applyTransactions($revision, $xactions);
110
111
return array(
112
'revisionid' => $revision->getID(),
113
'uri' => PhabricatorEnv::getURI('/D'.$revision->getID()),
114
);
115
}
116
117
}
118
119