Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/conduit/DifferentialGetDiffConduitAPIMethod.php
12256 views
1
<?php
2
3
final class DifferentialGetDiffConduitAPIMethod
4
extends DifferentialConduitAPIMethod {
5
6
public function getAPIMethodName() {
7
return 'differential.getdiff';
8
}
9
10
public function shouldAllowPublic() {
11
return true;
12
}
13
14
public function getMethodStatus() {
15
return self::METHOD_STATUS_DEPRECATED;
16
}
17
18
public function getMethodStatusDescription() {
19
return pht(
20
'This method has been deprecated in favor of %s.',
21
'differential.querydiffs');
22
}
23
24
25
public function getMethodDescription() {
26
return pht(
27
'Load the content of a diff from Differential by revision ID '.
28
'or diff ID.');
29
}
30
31
protected function defineParamTypes() {
32
return array(
33
'revision_id' => 'optional id',
34
'diff_id' => 'optional id',
35
);
36
}
37
38
protected function defineReturnType() {
39
return 'nonempty dict';
40
}
41
42
protected function defineErrorTypes() {
43
return array(
44
'ERR_BAD_DIFF' => pht('No such diff exists.'),
45
);
46
}
47
48
protected function execute(ConduitAPIRequest $request) {
49
$diff_id = $request->getValue('diff_id');
50
51
// If we have a revision ID, we need the most recent diff. Figure that out
52
// without loading all the attached data.
53
$revision_id = $request->getValue('revision_id');
54
if ($revision_id) {
55
$diffs = id(new DifferentialDiffQuery())
56
->setViewer($request->getUser())
57
->withRevisionIDs(array($revision_id))
58
->execute();
59
if ($diffs) {
60
$diff_id = head($diffs)->getID();
61
} else {
62
throw new ConduitException('ERR_BAD_DIFF');
63
}
64
}
65
66
$diff = null;
67
if ($diff_id) {
68
$diff = id(new DifferentialDiffQuery())
69
->setViewer($request->getUser())
70
->withIDs(array($diff_id))
71
->needChangesets(true)
72
->executeOne();
73
}
74
75
if (!$diff) {
76
throw new ConduitException('ERR_BAD_DIFF');
77
}
78
79
return $diff->getDiffDict();
80
}
81
82
}
83
84