Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/conduit/DifferentialSetDiffPropertyConduitAPIMethod.php
12256 views
1
<?php
2
3
final class DifferentialSetDiffPropertyConduitAPIMethod
4
extends DifferentialConduitAPIMethod {
5
6
public function getAPIMethodName() {
7
return 'differential.setdiffproperty';
8
}
9
10
public function getMethodDescription() {
11
return pht('Attach properties to Differential diffs.');
12
}
13
14
protected function defineParamTypes() {
15
return array(
16
'diff_id' => 'required diff_id',
17
'name' => 'required string',
18
'data' => 'required string',
19
);
20
}
21
22
protected function defineReturnType() {
23
return 'void';
24
}
25
26
protected function defineErrorTypes() {
27
return array(
28
'ERR_NOT_FOUND' => pht('Diff was not found.'),
29
);
30
}
31
32
protected function execute(ConduitAPIRequest $request) {
33
$data = $request->getValue('data');
34
if ($data === null || !strlen($data)) {
35
throw new Exception(pht('Field "data" must be non-empty.'));
36
}
37
38
$diff_id = $request->getValue('diff_id');
39
if ($diff_id === null) {
40
throw new Exception(pht('Field "diff_id" must be non-null.'));
41
}
42
43
$name = $request->getValue('name');
44
if ($name === null || !strlen($name)) {
45
throw new Exception(pht('Field "name" must be non-empty.'));
46
}
47
48
$data = json_decode($data, true);
49
50
self::updateDiffProperty($diff_id, $name, $data);
51
}
52
53
private static function updateDiffProperty($diff_id, $name, $data) {
54
$property = id(new DifferentialDiffProperty())->loadOneWhere(
55
'diffID = %d AND name = %s',
56
$diff_id,
57
$name);
58
if (!$property) {
59
$property = new DifferentialDiffProperty();
60
$property->setDiffID($diff_id);
61
$property->setName($name);
62
}
63
$property->setData($data);
64
$property->save();
65
return $property;
66
}
67
68
}
69
70