@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final 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 since %s in favor of %s.',
21 '09/2013',
22 'differential.querydiffs');
23 }
24
25
26 public function getMethodDescription() {
27 return pht(
28 'Load the content of a diff from Differential by revision ID '.
29 'or diff ID.');
30 }
31
32 protected function defineParamTypes() {
33 return array(
34 'revision_id' => 'optional id',
35 'diff_id' => 'optional id',
36 );
37 }
38
39 protected function defineReturnType() {
40 return 'nonempty dict';
41 }
42
43 protected function defineErrorTypes() {
44 return array(
45 'ERR_BAD_DIFF' => pht('No such diff exists.'),
46 );
47 }
48
49 protected function execute(ConduitAPIRequest $request) {
50 $diff_id = $request->getValue('diff_id');
51
52 // If we have a revision ID, we need the most recent diff. Figure that out
53 // without loading all the attached data.
54 $revision_id = $request->getValue('revision_id');
55 if ($revision_id) {
56 $diffs = id(new DifferentialDiffQuery())
57 ->setViewer($request->getUser())
58 ->withRevisionIDs(array($revision_id))
59 ->execute();
60 if ($diffs) {
61 $diff_id = head($diffs)->getID();
62 } else {
63 throw new ConduitException('ERR_BAD_DIFF');
64 }
65 }
66
67 $diff = null;
68 if ($diff_id) {
69 $diff = id(new DifferentialDiffQuery())
70 ->setViewer($request->getUser())
71 ->withIDs(array($diff_id))
72 ->needChangesets(true)
73 ->executeOne();
74 }
75
76 if (!$diff) {
77 throw new ConduitException('ERR_BAD_DIFF');
78 }
79
80 return $diff->getDiffDict();
81 }
82
83}