Path: blob/master/src/applications/conpherence/conduit/ConpherenceUpdateThreadConduitAPIMethod.php
12256 views
<?php12final class ConpherenceUpdateThreadConduitAPIMethod3extends ConpherenceConduitAPIMethod {45public function getAPIMethodName() {6return 'conpherence.updatethread';7}89public function getMethodDescription() {10return pht('Update an existing conpherence room.');11}1213public function getMethodStatus() {14return self::METHOD_STATUS_FROZEN;15}1617public function getMethodStatusDescription() {18return pht(19'This method is frozen and will eventually be deprecated. New code '.20'should use "conpherence.edit" instead.');21}2223protected function defineParamTypes() {24return array(25'id' => 'optional int',26'phid' => 'optional phid',27'title' => 'optional string',28'message' => 'optional string',29'addParticipantPHIDs' => 'optional list<phids>',30'removeParticipantPHID' => 'optional phid',31);32}3334protected function defineReturnType() {35return 'bool';36}3738protected function defineErrorTypes() {39return array(40'ERR_USAGE_NO_ROOM_ID' => pht(41'You must specify a room ID or room PHID to query transactions from.'),42'ERR_USAGE_ROOM_NOT_FOUND' => pht(43'Room does not exist or logged in user can not see it.'),44'ERR_USAGE_ONLY_SELF_REMOVE' => pht(45'Only a user can remove themselves from a room.'),46'ERR_USAGE_NO_UPDATES' => pht(47'You must specify data that actually updates the Conpherence.'),48);49}5051protected function execute(ConduitAPIRequest $request) {52$user = $request->getUser();53$id = $request->getValue('id');54$phid = $request->getValue('phid');55$query = id(new ConpherenceThreadQuery())56->setViewer($user);57if ($id) {58$query->withIDs(array($id));59} else if ($phid) {60$query->withPHIDs(array($phid));61} else {62throw new ConduitException('ERR_USAGE_NO_ROOM_ID');63}64$conpherence = $query->executeOne();65if (!$conpherence) {66throw new ConduitException('ERR_USAGE_ROOM_NOT_FOUND');67}6869$source = $request->newContentSource();70$editor = id(new ConpherenceEditor())71->setContentSource($source)72->setActor($user);73$xactions = array();74$add_participant_phids = $request->getValue('addParticipantPHIDs', array());75$remove_participant_phid = $request->getValue('removeParticipantPHID');76$message = $request->getValue('message');77$title = $request->getValue('title');78if ($add_participant_phids) {79$xactions[] = id(new ConpherenceTransaction())80->setTransactionType(81ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)82->setNewValue(array('+' => $add_participant_phids));83}84if ($remove_participant_phid) {85if ($remove_participant_phid != $user->getPHID()) {86throw new ConduitException('ERR_USAGE_ONLY_SELF_REMOVE');87}88$xactions[] = id(new ConpherenceTransaction())89->setTransactionType(90ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)91->setNewValue(array('-' => array($remove_participant_phid)));92}93if ($title) {94$xactions[] = id(new ConpherenceTransaction())95->setTransactionType(96ConpherenceThreadTitleTransaction::TRANSACTIONTYPE)97->setNewValue($title);98}99if ($message) {100$xactions = array_merge(101$xactions,102$editor->generateTransactionsFromText(103$user,104$conpherence,105$message));106}107108try {109$xactions = $editor->applyTransactions($conpherence, $xactions);110} catch (PhabricatorApplicationTransactionNoEffectException $ex) {111throw new ConduitException('ERR_USAGE_NO_UPDATES');112}113114return true;115}116117}118119120