@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 FlagEditConduitAPIMethod extends FlagConduitAPIMethod {
4
5 public function getAPIMethodName() {
6 return 'flag.edit';
7 }
8
9 public function getMethodDescription() {
10 return pht('Create or modify a flag.');
11 }
12
13 protected function defineParamTypes() {
14 return array(
15 'objectPHID' => 'required phid',
16 'color' => 'optional int',
17 'note' => 'optional string',
18 );
19 }
20
21 protected function defineReturnType() {
22 return 'dict';
23 }
24
25 protected function defineErrorTypes() {
26 return array(
27 'ERR-BAD-PHID' => pht('Must pass a PHID.'),
28 );
29 }
30
31 protected function execute(ConduitAPIRequest $request) {
32 $user = $request->getUser()->getPHID();
33 $phid = $request->getValue('objectPHID');
34 if ($phid === null) {
35 throw new ConduitException('ERR-BAD-PHID');
36 }
37 $new = false;
38
39 $flag = id(new PhabricatorFlag())->loadOneWhere(
40 'objectPHID = %s AND ownerPHID = %s',
41 $phid,
42 $user);
43 if ($flag) {
44 $params = $request->getAllParameters();
45 if (isset($params['color'])) {
46 $flag->setColor($params['color']);
47 }
48 if (isset($params['note'])) {
49 $flag->setNote($params['note']);
50 }
51 } else {
52 $default_color = PhabricatorFlagColor::COLOR_BLUE;
53 $flag = id(new PhabricatorFlag())
54 ->setOwnerPHID($user)
55 ->setType(phid_get_type($phid))
56 ->setObjectPHID($phid)
57 ->setReasonPHID($user)
58 ->setColor($request->getValue('color', $default_color))
59 ->setNote($request->getValue('note', ''));
60 $new = true;
61 }
62 $this->attachHandleToFlag($flag, $request->getUser());
63 $flag->save();
64 $ret = $this->buildFlagInfoDictionary($flag);
65 $ret['new'] = $new;
66 return $ret;
67 }
68
69}