[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ConpherenceUpdateThreadConduitAPIMethod 4 extends ConpherenceConduitAPIMethod { 5 6 public function getAPIMethodName() { 7 return 'conpherence.updatethread'; 8 } 9 10 public function getMethodDescription() { 11 return pht('Update an existing conpherence thread.'); 12 } 13 14 public function defineParamTypes() { 15 return array( 16 'id' => 'optional int', 17 'phid' => 'optional phid', 18 'title' => 'optional string', 19 'message' => 'optional string', 20 'addParticipantPHIDs' => 'optional list<phids>', 21 'removeParticipantPHID' => 'optional phid', 22 ); 23 } 24 25 public function defineReturnType() { 26 return 'bool'; 27 } 28 29 public function defineErrorTypes() { 30 return array( 31 'ERR_USAGE_NO_THREAD_ID' => pht( 32 'You must specify a thread id or thread phid to query transactions '. 33 'from.'), 34 'ERR_USAGE_THREAD_NOT_FOUND' => pht( 35 'Thread does not exist or logged in user can not see it.'), 36 'ERR_USAGE_ONLY_SELF_REMOVE' => pht( 37 'Only a user can remove themselves from a thread.'), 38 'ERR_USAGE_NO_UPDATES' => pht( 39 'You must specify data that actually updates the conpherence.'), 40 ); 41 } 42 43 protected function execute(ConduitAPIRequest $request) { 44 $user = $request->getUser(); 45 $id = $request->getValue('id'); 46 $phid = $request->getValue('phid'); 47 $query = id(new ConpherenceThreadQuery()) 48 ->setViewer($user) 49 ->needFilePHIDs(true); 50 if ($id) { 51 $query->withIDs(array($id)); 52 } else if ($phid) { 53 $query->withPHIDs(array($phid)); 54 } else { 55 throw new ConduitException('ERR_USAGE_NO_THREAD_ID'); 56 } 57 $conpherence = $query->executeOne(); 58 if (!$conpherence) { 59 throw new ConduitException('ERR_USAGE_THREAD_NOT_FOUND'); 60 } 61 62 $source = PhabricatorContentSource::newFromConduitRequest($request); 63 $editor = id(new ConpherenceEditor()) 64 ->setContentSource($source) 65 ->setActor($user); 66 $xactions = array(); 67 $add_participant_phids = $request->getValue('addParticipantPHIDs', array()); 68 $remove_participant_phid = $request->getValue('removeParticipantPHID'); 69 $message = $request->getValue('message'); 70 $title = $request->getValue('title'); 71 if ($add_participant_phids) { 72 $xactions[] = id(new ConpherenceTransaction()) 73 ->setTransactionType( 74 ConpherenceTransactionType::TYPE_PARTICIPANTS) 75 ->setNewValue(array('+' => $add_participant_phids)); 76 } 77 if ($remove_participant_phid) { 78 if ($remove_participant_phid != $user->getPHID()) { 79 throw new ConduitException('ERR_USAGE_ONLY_SELF_REMOVE'); 80 } 81 $xactions[] = id(new ConpherenceTransaction()) 82 ->setTransactionType( 83 ConpherenceTransactionType::TYPE_PARTICIPANTS) 84 ->setNewValue(array('-' => array($remove_participant_phid))); 85 } 86 if ($title) { 87 $xactions[] = id(new ConpherenceTransaction()) 88 ->setTransactionType(ConpherenceTransactionType::TYPE_TITLE) 89 ->setNewValue($title); 90 } 91 if ($message) { 92 $xactions = array_merge( 93 $xactions, 94 $editor->generateTransactionsFromText( 95 $user, 96 $conpherence, 97 $message)); 98 } 99 100 try { 101 $xactions = $editor->applyTransactions($conpherence, $xactions); 102 } catch (PhabricatorApplicationTransactionNoEffectException $ex) { 103 throw new ConduitException('ERR_USAGE_NO_UPDATES'); 104 } 105 106 return true; 107 } 108 109 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |