Path: blob/master/src/applications/flag/conduit/FlagDeleteConduitAPIMethod.php
12256 views
<?php12final class FlagDeleteConduitAPIMethod extends FlagConduitAPIMethod {34public function getAPIMethodName() {5return 'flag.delete';6}78public function getMethodDescription() {9return pht('Clear a flag.');10}1112protected function defineParamTypes() {13return array(14'id' => 'optional id',15'objectPHID' => 'optional phid',16);17}1819protected function defineReturnType() {20return 'dict | null';21}2223protected function defineErrorTypes() {24return array(25'ERR_NOT_FOUND' => pht('Bad flag ID.'),26'ERR_WRONG_USER' => pht('You are not the creator of this flag.'),27'ERR_NEED_PARAM' => pht('Must pass an id or an objectPHID.'),28);29}3031protected function execute(ConduitAPIRequest $request) {32$id = $request->getValue('id');33$object = $request->getValue('objectPHID');34if ($id) {35$flag = id(new PhabricatorFlag())->load($id);36if (!$flag) {37throw new ConduitException('ERR_NOT_FOUND');38}39if ($flag->getOwnerPHID() != $request->getUser()->getPHID()) {40throw new ConduitException('ERR_WRONG_USER');41}42} else if ($object) {43$flag = id(new PhabricatorFlag())->loadOneWhere(44'objectPHID = %s AND ownerPHID = %s',45$object,46$request->getUser()->getPHID());47if (!$flag) {48return null;49}50} else {51throw new ConduitException('ERR_NEED_PARAM');52}53$this->attachHandleToFlag($flag, $request->getUser());54$ret = $this->buildFlagInfoDictionary($flag);55$flag->delete();56return $ret;57}5859}606162