mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-02 09:58:24 +01:00
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
This commit is contained in:
parent
01a6d580ac
commit
4295de508f
8 changed files with 186 additions and 64 deletions
|
@ -118,6 +118,8 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_conduit_getcertificate_Method' => 'applications/conduit/method/ConduitAPI_conduit_getcertificate_Method.php',
|
||||
'ConduitAPI_conduit_ping_Method' => 'applications/conduit/method/ConduitAPI_conduit_ping_Method.php',
|
||||
'ConduitAPI_conduit_query_Method' => 'applications/conduit/method/ConduitAPI_conduit_query_Method.php',
|
||||
'ConduitAPI_conpherence_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_Method.php',
|
||||
'ConduitAPI_conpherence_createthread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php',
|
||||
'ConduitAPI_daemon_launched_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_launched_Method.php',
|
||||
'ConduitAPI_daemon_log_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_log_Method.php',
|
||||
'ConduitAPI_daemon_setstatus_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_setstatus_Method.php',
|
||||
|
@ -1947,6 +1949,8 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_conduit_getcertificate_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_conduit_ping_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_conduit_query_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_conpherence_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_conpherence_createthread_Method' => 'ConduitAPI_conpherence_Method',
|
||||
'ConduitAPI_daemon_launched_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_daemon_log_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_daemon_setstatus_Method' => 'ConduitAPIMethod',
|
||||
|
|
|
@ -98,6 +98,10 @@ abstract class PhabricatorApplication {
|
|||
return null;
|
||||
}
|
||||
|
||||
public function getApplicationURI($path = '') {
|
||||
return $this->getBaseURI().ltrim($path, '/');
|
||||
}
|
||||
|
||||
public function getIconURI() {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ abstract class PhabricatorController extends AphrontController {
|
|||
if (!$this->getCurrentApplication()) {
|
||||
throw new Exception("No application!");
|
||||
}
|
||||
return $this->getCurrentApplication()->getBaseURI().ltrim($path, '/');
|
||||
return $this->getCurrentApplication()->getApplicationURI($path);
|
||||
}
|
||||
|
||||
public function buildApplicationPage($view, array $options) {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
abstract class ConduitAPI_conpherence_Method
|
||||
extends ConduitAPIMethod {
|
||||
|
||||
public function getApplication() {
|
||||
return PhabricatorApplication::getByClass(
|
||||
'PhabricatorApplicationConpherence');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
final class ConduitAPI_conpherence_createthread_Method
|
||||
extends ConduitAPI_conpherence_Method {
|
||||
|
||||
|
||||
public function getMethodDescription() {
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'title' => 'optional string',
|
||||
'message' => 'required string',
|
||||
'participantPHIDs' => 'required list<phids>'
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'nonempty dict';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array(
|
||||
'ERR_EMPTY_PARTICIPANT_PHIDS' => 'You must specify participant phids.',
|
||||
'ERR_EMPTY_MESSAGE' => 'You must specify a message.'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
|
||||
$participant_phids = $request->getValue('participantPHIDs', array());
|
||||
$message = $request->getValue('message');
|
||||
$title = $request->getValue('title');
|
||||
|
||||
list($errors, $conpherence) = ConpherenceEditor::createConpherence(
|
||||
$request->getUser(),
|
||||
$participant_phids,
|
||||
$title,
|
||||
$message,
|
||||
PhabricatorContentSource::newFromConduitRequest($request));
|
||||
|
||||
if ($errors) {
|
||||
foreach ($errors as $error_code) {
|
||||
switch ($error_code) {
|
||||
case ConpherenceEditor::ERROR_EMPTY_MESSAGE:
|
||||
throw new ConduitException('ERR_EMPTY_MESSAGE');
|
||||
break;
|
||||
case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS:
|
||||
throw new ConduitException('ERR_EMPTY_PARTICIPANT_PHIDS');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$id = $conpherence->getID();
|
||||
$uri = $this->getApplication()->getApplicationURI($id);
|
||||
return array(
|
||||
'conpherenceID' => $id,
|
||||
'conpherencePHID' => $conpherence->getPHID(),
|
||||
'conpherenceURI' => $uri);
|
||||
}
|
||||
}
|
|
@ -9,15 +9,9 @@ final class ConpherenceNewController extends ConpherenceController {
|
|||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$conpherence = id(new ConpherenceThread())
|
||||
->attachParticipants(array())
|
||||
->attachFilePHIDs(array())
|
||||
->setMessageCount(0);
|
||||
$title = pht('New Message');
|
||||
$participants = array();
|
||||
$message = '';
|
||||
$files = array();
|
||||
$errors = array();
|
||||
$e_participants = null;
|
||||
$e_message = null;
|
||||
|
||||
|
@ -29,72 +23,32 @@ final class ConpherenceNewController extends ConpherenceController {
|
|||
|
||||
if ($request->isFormPost()) {
|
||||
$participants = $request->getArr('participants');
|
||||
if (empty($participants)) {
|
||||
$e_participants = true;
|
||||
$errors[] = pht('You must specify participants.');
|
||||
} else {
|
||||
$participants[] = $user->getPHID();
|
||||
$participants = array_unique($participants);
|
||||
$conpherence->setRecentParticipantPHIDs(
|
||||
array_slice($participants, 0, 10));
|
||||
}
|
||||
|
||||
$message = $request->getStr('message');
|
||||
if (empty($message)) {
|
||||
list($error_codes, $conpherence) = ConpherenceEditor::createConpherence(
|
||||
$user,
|
||||
$participants,
|
||||
$conpherence_title = null,
|
||||
$message,
|
||||
PhabricatorContentSource::newFromRequest($request));
|
||||
|
||||
if ($error_codes) {
|
||||
foreach ($error_codes as $error_code) {
|
||||
switch ($error_code) {
|
||||
case ConpherenceEditor::ERROR_EMPTY_MESSAGE:
|
||||
$e_message = true;
|
||||
$errors[] = pht('You must write a message.');
|
||||
break;
|
||||
case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS:
|
||||
$e_participants = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$file_phids =
|
||||
PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
||||
array($message));
|
||||
if ($file_phids) {
|
||||
$files = id(new PhabricatorFileQuery())
|
||||
->setViewer($user)
|
||||
->withPHIDs($file_phids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
$conpherence->openTransaction();
|
||||
$conpherence->save();
|
||||
$xactions = array();
|
||||
$xactions[] = id(new ConpherenceTransaction())
|
||||
->setTransactionType(ConpherenceTransactionType::TYPE_PARTICIPANTS)
|
||||
->setNewValue(array('+' => $participants));
|
||||
if ($files) {
|
||||
$xactions[] = id(new ConpherenceTransaction())
|
||||
->setTransactionType(ConpherenceTransactionType::TYPE_FILES)
|
||||
->setNewValue(array('+' => mpull($files, 'getPHID')));
|
||||
}
|
||||
$xactions[] = id(new ConpherenceTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||
->attachComment(
|
||||
id(new ConpherenceTransactionComment())
|
||||
->setContent($message)
|
||||
->setConpherencePHID($conpherence->getPHID()));
|
||||
|
||||
id(new ConpherenceEditor())
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setActor($user)
|
||||
->applyTransactions($conpherence, $xactions);
|
||||
|
||||
$conpherence->saveTransaction();
|
||||
|
||||
} else {
|
||||
$uri = $this->getApplicationURI($conpherence->getID());
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($uri);
|
||||
}
|
||||
}
|
||||
|
||||
$error_view = null;
|
||||
if ($errors) {
|
||||
$error_view = id(new AphrontErrorView())
|
||||
->setTitle(pht('Conpherence Errors'))
|
||||
->setErrors($errors);
|
||||
}
|
||||
|
||||
$participant_handles = array();
|
||||
if ($participants) {
|
||||
$handles = id(new PhabricatorObjectHandleData($participants))
|
||||
|
|
|
@ -5,6 +5,81 @@
|
|||
*/
|
||||
final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
||||
|
||||
const ERROR_EMPTY_PARTICIPANTS = 'error-empty-participants';
|
||||
const ERROR_EMPTY_MESSAGE = 'error-empty-message';
|
||||
|
||||
public static function createConpherence(
|
||||
PhabricatorUser $creator,
|
||||
array $participant_phids,
|
||||
$title,
|
||||
$message,
|
||||
PhabricatorContentSource $source) {
|
||||
|
||||
$conpherence = id(new ConpherenceThread())
|
||||
->attachParticipants(array())
|
||||
->attachFilePHIDs(array())
|
||||
->setMessageCount(0);
|
||||
$files = array();
|
||||
$errors = array();
|
||||
if (empty($participant_phids)) {
|
||||
$errors[] = self::ERROR_EMPTY_PARTICIPANTS;
|
||||
} else {
|
||||
$participant_phids[] = $creator->getPHID();
|
||||
$participant_phids = array_unique($participant_phids);
|
||||
$conpherence->setRecentParticipantPHIDs(
|
||||
array_slice($participant_phids, 0, 10));
|
||||
}
|
||||
|
||||
if (empty($message)) {
|
||||
$errors[] = self::ERROR_EMPTY_MESSAGE;
|
||||
}
|
||||
|
||||
$file_phids =
|
||||
PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
||||
array($message));
|
||||
if ($file_phids) {
|
||||
$files = id(new PhabricatorFileQuery())
|
||||
->setViewer($creator)
|
||||
->withPHIDs($file_phids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
$conpherence->openTransaction();
|
||||
$conpherence->save();
|
||||
$xactions = array();
|
||||
$xactions[] = id(new ConpherenceTransaction())
|
||||
->setTransactionType(ConpherenceTransactionType::TYPE_PARTICIPANTS)
|
||||
->setNewValue(array('+' => $participant_phids));
|
||||
if ($files) {
|
||||
$xactions[] = id(new ConpherenceTransaction())
|
||||
->setTransactionType(ConpherenceTransactionType::TYPE_FILES)
|
||||
->setNewValue(array('+' => mpull($files, 'getPHID')));
|
||||
}
|
||||
if ($title) {
|
||||
$xactions[] = id(new ConpherenceTransaction())
|
||||
->setTransactionType(ConpherenceTransactionType::TYPE_TITLE)
|
||||
->setNewValue($title);
|
||||
}
|
||||
$xactions[] = id(new ConpherenceTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||
->attachComment(
|
||||
id(new ConpherenceTransactionComment())
|
||||
->setContent($message)
|
||||
->setConpherencePHID($conpherence->getPHID()));
|
||||
|
||||
id(new ConpherenceEditor())
|
||||
->setContentSource($source)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setActor($creator)
|
||||
->applyTransactions($conpherence, $xactions);
|
||||
|
||||
$conpherence->saveTransaction();
|
||||
}
|
||||
|
||||
return array($errors, $conpherence);
|
||||
}
|
||||
|
||||
public function generateTransactionsFromText(
|
||||
ConpherenceThread $conpherence,
|
||||
$text) {
|
||||
|
|
|
@ -46,6 +46,12 @@ final class PhabricatorContentSource {
|
|||
));
|
||||
}
|
||||
|
||||
public static function newFromConduitRequest(ConduitAPIRequest $request) {
|
||||
return self::newForSource(
|
||||
PhabricatorContentSource::SOURCE_CONDUIT,
|
||||
array());
|
||||
}
|
||||
|
||||
public function serialize() {
|
||||
return json_encode(array(
|
||||
'source' => $this->getSource(),
|
||||
|
|
Loading…
Add table
Reference in a new issue