Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/flag/conduit/FlagDeleteConduitAPIMethod.php
12256 views
1
<?php
2
3
final class FlagDeleteConduitAPIMethod extends FlagConduitAPIMethod {
4
5
public function getAPIMethodName() {
6
return 'flag.delete';
7
}
8
9
public function getMethodDescription() {
10
return pht('Clear a flag.');
11
}
12
13
protected function defineParamTypes() {
14
return array(
15
'id' => 'optional id',
16
'objectPHID' => 'optional phid',
17
);
18
}
19
20
protected function defineReturnType() {
21
return 'dict | null';
22
}
23
24
protected function defineErrorTypes() {
25
return array(
26
'ERR_NOT_FOUND' => pht('Bad flag ID.'),
27
'ERR_WRONG_USER' => pht('You are not the creator of this flag.'),
28
'ERR_NEED_PARAM' => pht('Must pass an id or an objectPHID.'),
29
);
30
}
31
32
protected function execute(ConduitAPIRequest $request) {
33
$id = $request->getValue('id');
34
$object = $request->getValue('objectPHID');
35
if ($id) {
36
$flag = id(new PhabricatorFlag())->load($id);
37
if (!$flag) {
38
throw new ConduitException('ERR_NOT_FOUND');
39
}
40
if ($flag->getOwnerPHID() != $request->getUser()->getPHID()) {
41
throw new ConduitException('ERR_WRONG_USER');
42
}
43
} else if ($object) {
44
$flag = id(new PhabricatorFlag())->loadOneWhere(
45
'objectPHID = %s AND ownerPHID = %s',
46
$object,
47
$request->getUser()->getPHID());
48
if (!$flag) {
49
return null;
50
}
51
} else {
52
throw new ConduitException('ERR_NEED_PARAM');
53
}
54
$this->attachHandleToFlag($flag, $request->getUser());
55
$ret = $this->buildFlagInfoDictionary($flag);
56
$flag->delete();
57
return $ret;
58
}
59
60
}
61
62