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