@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Conpherence - add createthread method

Summary: Ref T3166. I moved the create logic into a static method in the editor class to keep things tidy.

Test Plan: created a conpherence from UI. purdy. tried errors and got UI to show "required". for conduit, created a thread with all the bells and whistles and it worked. verified i got proper exceptions with bum conduit calls

Reviewers: epriestley

Reviewed By: epriestley

CC: chad, aran, Korvin

Maniphest Tasks: T3166

Differential Revision: https://secure.phabricator.com/D6083

+186 -64
+4
src/__phutil_library_map__.php
··· 118 118 'ConduitAPI_conduit_getcertificate_Method' => 'applications/conduit/method/ConduitAPI_conduit_getcertificate_Method.php', 119 119 'ConduitAPI_conduit_ping_Method' => 'applications/conduit/method/ConduitAPI_conduit_ping_Method.php', 120 120 'ConduitAPI_conduit_query_Method' => 'applications/conduit/method/ConduitAPI_conduit_query_Method.php', 121 + 'ConduitAPI_conpherence_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_Method.php', 122 + 'ConduitAPI_conpherence_createthread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php', 121 123 'ConduitAPI_daemon_launched_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_launched_Method.php', 122 124 'ConduitAPI_daemon_log_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_log_Method.php', 123 125 'ConduitAPI_daemon_setstatus_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_setstatus_Method.php', ··· 1947 1949 'ConduitAPI_conduit_getcertificate_Method' => 'ConduitAPIMethod', 1948 1950 'ConduitAPI_conduit_ping_Method' => 'ConduitAPIMethod', 1949 1951 'ConduitAPI_conduit_query_Method' => 'ConduitAPIMethod', 1952 + 'ConduitAPI_conpherence_Method' => 'ConduitAPIMethod', 1953 + 'ConduitAPI_conpherence_createthread_Method' => 'ConduitAPI_conpherence_Method', 1950 1954 'ConduitAPI_daemon_launched_Method' => 'ConduitAPIMethod', 1951 1955 'ConduitAPI_daemon_log_Method' => 'ConduitAPIMethod', 1952 1956 'ConduitAPI_daemon_setstatus_Method' => 'ConduitAPIMethod',
+4
src/applications/base/PhabricatorApplication.php
··· 98 98 return null; 99 99 } 100 100 101 + public function getApplicationURI($path = '') { 102 + return $this->getBaseURI().ltrim($path, '/'); 103 + } 104 + 101 105 public function getIconURI() { 102 106 return null; 103 107 }
+1 -1
src/applications/base/controller/PhabricatorController.php
··· 141 141 if (!$this->getCurrentApplication()) { 142 142 throw new Exception("No application!"); 143 143 } 144 - return $this->getCurrentApplication()->getBaseURI().ltrim($path, '/'); 144 + return $this->getCurrentApplication()->getApplicationURI($path); 145 145 } 146 146 147 147 public function buildApplicationPage($view, array $options) {
+14
src/applications/conpherence/conduit/ConduitAPI_conpherence_Method.php
··· 1 + <?php 2 + 3 + /** 4 + * @group conduit 5 + */ 6 + abstract class ConduitAPI_conpherence_Method 7 + extends ConduitAPIMethod { 8 + 9 + public function getApplication() { 10 + return PhabricatorApplication::getByClass( 11 + 'PhabricatorApplicationConpherence'); 12 + } 13 + 14 + }
+65
src/applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php
··· 1 + <?php 2 + 3 + /** 4 + * @group conduit 5 + */ 6 + final class ConduitAPI_conpherence_createthread_Method 7 + extends ConduitAPI_conpherence_Method { 8 + 9 + 10 + public function getMethodDescription() { 11 + } 12 + 13 + public function defineParamTypes() { 14 + return array( 15 + 'title' => 'optional string', 16 + 'message' => 'required string', 17 + 'participantPHIDs' => 'required list<phids>' 18 + ); 19 + } 20 + 21 + public function defineReturnType() { 22 + return 'nonempty dict'; 23 + } 24 + 25 + public function defineErrorTypes() { 26 + return array( 27 + 'ERR_EMPTY_PARTICIPANT_PHIDS' => 'You must specify participant phids.', 28 + 'ERR_EMPTY_MESSAGE' => 'You must specify a message.' 29 + ); 30 + } 31 + 32 + protected function execute(ConduitAPIRequest $request) { 33 + 34 + $participant_phids = $request->getValue('participantPHIDs', array()); 35 + $message = $request->getValue('message'); 36 + $title = $request->getValue('title'); 37 + 38 + list($errors, $conpherence) = ConpherenceEditor::createConpherence( 39 + $request->getUser(), 40 + $participant_phids, 41 + $title, 42 + $message, 43 + PhabricatorContentSource::newFromConduitRequest($request)); 44 + 45 + if ($errors) { 46 + foreach ($errors as $error_code) { 47 + switch ($error_code) { 48 + case ConpherenceEditor::ERROR_EMPTY_MESSAGE: 49 + throw new ConduitException('ERR_EMPTY_MESSAGE'); 50 + break; 51 + case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS: 52 + throw new ConduitException('ERR_EMPTY_PARTICIPANT_PHIDS'); 53 + break; 54 + } 55 + } 56 + } 57 + 58 + $id = $conpherence->getID(); 59 + $uri = $this->getApplication()->getApplicationURI($id); 60 + return array( 61 + 'conpherenceID' => $id, 62 + 'conpherencePHID' => $conpherence->getPHID(), 63 + 'conpherenceURI' => $uri); 64 + } 65 + }
+17 -63
src/applications/conpherence/controller/ConpherenceNewController.php
··· 9 9 $request = $this->getRequest(); 10 10 $user = $request->getUser(); 11 11 12 - $conpherence = id(new ConpherenceThread()) 13 - ->attachParticipants(array()) 14 - ->attachFilePHIDs(array()) 15 - ->setMessageCount(0); 16 12 $title = pht('New Message'); 17 13 $participants = array(); 18 14 $message = ''; 19 - $files = array(); 20 - $errors = array(); 21 15 $e_participants = null; 22 16 $e_message = null; 23 17 ··· 29 23 30 24 if ($request->isFormPost()) { 31 25 $participants = $request->getArr('participants'); 32 - if (empty($participants)) { 33 - $e_participants = true; 34 - $errors[] = pht('You must specify participants.'); 35 - } else { 36 - $participants[] = $user->getPHID(); 37 - $participants = array_unique($participants); 38 - $conpherence->setRecentParticipantPHIDs( 39 - array_slice($participants, 0, 10)); 40 - } 41 - 42 26 $message = $request->getStr('message'); 43 - if (empty($message)) { 44 - $e_message = true; 45 - $errors[] = pht('You must write a message.'); 46 - } 47 - 48 - $file_phids = 49 - PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles( 50 - array($message)); 51 - if ($file_phids) { 52 - $files = id(new PhabricatorFileQuery()) 53 - ->setViewer($user) 54 - ->withPHIDs($file_phids) 55 - ->execute(); 56 - } 27 + list($error_codes, $conpherence) = ConpherenceEditor::createConpherence( 28 + $user, 29 + $participants, 30 + $conpherence_title = null, 31 + $message, 32 + PhabricatorContentSource::newFromRequest($request)); 57 33 58 - if (!$errors) { 59 - $conpherence->openTransaction(); 60 - $conpherence->save(); 61 - $xactions = array(); 62 - $xactions[] = id(new ConpherenceTransaction()) 63 - ->setTransactionType(ConpherenceTransactionType::TYPE_PARTICIPANTS) 64 - ->setNewValue(array('+' => $participants)); 65 - if ($files) { 66 - $xactions[] = id(new ConpherenceTransaction()) 67 - ->setTransactionType(ConpherenceTransactionType::TYPE_FILES) 68 - ->setNewValue(array('+' => mpull($files, 'getPHID'))); 34 + if ($error_codes) { 35 + foreach ($error_codes as $error_code) { 36 + switch ($error_code) { 37 + case ConpherenceEditor::ERROR_EMPTY_MESSAGE: 38 + $e_message = true; 39 + break; 40 + case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS: 41 + $e_participants = true; 42 + break; 43 + } 69 44 } 70 - $xactions[] = id(new ConpherenceTransaction()) 71 - ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 72 - ->attachComment( 73 - id(new ConpherenceTransactionComment()) 74 - ->setContent($message) 75 - ->setConpherencePHID($conpherence->getPHID())); 76 - 77 - id(new ConpherenceEditor()) 78 - ->setContentSourceFromRequest($request) 79 - ->setContinueOnNoEffect(true) 80 - ->setActor($user) 81 - ->applyTransactions($conpherence, $xactions); 82 - 83 - $conpherence->saveTransaction(); 84 - 45 + } else { 85 46 $uri = $this->getApplicationURI($conpherence->getID()); 86 47 return id(new AphrontRedirectResponse()) 87 48 ->setURI($uri); 88 49 } 89 - } 90 - 91 - $error_view = null; 92 - if ($errors) { 93 - $error_view = id(new AphrontErrorView()) 94 - ->setTitle(pht('Conpherence Errors')) 95 - ->setErrors($errors); 96 50 } 97 51 98 52 $participant_handles = array();
+75
src/applications/conpherence/editor/ConpherenceEditor.php
··· 5 5 */ 6 6 final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor { 7 7 8 + const ERROR_EMPTY_PARTICIPANTS = 'error-empty-participants'; 9 + const ERROR_EMPTY_MESSAGE = 'error-empty-message'; 10 + 11 + public static function createConpherence( 12 + PhabricatorUser $creator, 13 + array $participant_phids, 14 + $title, 15 + $message, 16 + PhabricatorContentSource $source) { 17 + 18 + $conpherence = id(new ConpherenceThread()) 19 + ->attachParticipants(array()) 20 + ->attachFilePHIDs(array()) 21 + ->setMessageCount(0); 22 + $files = array(); 23 + $errors = array(); 24 + if (empty($participant_phids)) { 25 + $errors[] = self::ERROR_EMPTY_PARTICIPANTS; 26 + } else { 27 + $participant_phids[] = $creator->getPHID(); 28 + $participant_phids = array_unique($participant_phids); 29 + $conpherence->setRecentParticipantPHIDs( 30 + array_slice($participant_phids, 0, 10)); 31 + } 32 + 33 + if (empty($message)) { 34 + $errors[] = self::ERROR_EMPTY_MESSAGE; 35 + } 36 + 37 + $file_phids = 38 + PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles( 39 + array($message)); 40 + if ($file_phids) { 41 + $files = id(new PhabricatorFileQuery()) 42 + ->setViewer($creator) 43 + ->withPHIDs($file_phids) 44 + ->execute(); 45 + } 46 + 47 + if (!$errors) { 48 + $conpherence->openTransaction(); 49 + $conpherence->save(); 50 + $xactions = array(); 51 + $xactions[] = id(new ConpherenceTransaction()) 52 + ->setTransactionType(ConpherenceTransactionType::TYPE_PARTICIPANTS) 53 + ->setNewValue(array('+' => $participant_phids)); 54 + if ($files) { 55 + $xactions[] = id(new ConpherenceTransaction()) 56 + ->setTransactionType(ConpherenceTransactionType::TYPE_FILES) 57 + ->setNewValue(array('+' => mpull($files, 'getPHID'))); 58 + } 59 + if ($title) { 60 + $xactions[] = id(new ConpherenceTransaction()) 61 + ->setTransactionType(ConpherenceTransactionType::TYPE_TITLE) 62 + ->setNewValue($title); 63 + } 64 + $xactions[] = id(new ConpherenceTransaction()) 65 + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 66 + ->attachComment( 67 + id(new ConpherenceTransactionComment()) 68 + ->setContent($message) 69 + ->setConpherencePHID($conpherence->getPHID())); 70 + 71 + id(new ConpherenceEditor()) 72 + ->setContentSource($source) 73 + ->setContinueOnNoEffect(true) 74 + ->setActor($creator) 75 + ->applyTransactions($conpherence, $xactions); 76 + 77 + $conpherence->saveTransaction(); 78 + } 79 + 80 + return array($errors, $conpherence); 81 + } 82 + 8 83 public function generateTransactionsFromText( 9 84 ConpherenceThread $conpherence, 10 85 $text) {
+6
src/applications/metamta/contentsource/PhabricatorContentSource.php
··· 46 46 )); 47 47 } 48 48 49 + public static function newFromConduitRequest(ConduitAPIRequest $request) { 50 + return self::newForSource( 51 + PhabricatorContentSource::SOURCE_CONDUIT, 52 + array()); 53 + } 54 + 49 55 public function serialize() { 50 56 return json_encode(array( 51 57 'source' => $this->getSource(),