1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Restore Slowvote commenting with ApplicationTransactions

Summary: Now it works like everything else does.

Test Plan: {F50168}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D6455
This commit is contained in:
epriestley 2013-07-15 04:45:43 -07:00
parent ea52bcbcd6
commit 05a807f417
5 changed files with 151 additions and 0 deletions

View file

@ -1527,9 +1527,11 @@ phutil_register_library_map(array(
'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php',
'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php',
'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php',
'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php',
'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php',
'PhabricatorSlowvoteCreateController' => 'applications/slowvote/controller/PhabricatorSlowvoteCreateController.php',
'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php',
'PhabricatorSlowvoteEditor' => 'applications/slowvote/editor/PhabricatorSlowvoteEditor.php',
'PhabricatorSlowvoteListController' => 'applications/slowvote/controller/PhabricatorSlowvoteListController.php',
'PhabricatorSlowvoteOption' => 'applications/slowvote/storage/PhabricatorSlowvoteOption.php',
'PhabricatorSlowvotePoll' => 'applications/slowvote/storage/PhabricatorSlowvotePoll.php',
@ -3486,9 +3488,11 @@ phutil_register_library_map(array(
'PhabricatorSetupIssueView' => 'AphrontView',
'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO',
'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO',
'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvoteController' => 'PhabricatorController',
'PhabricatorSlowvoteCreateController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO',
'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorSlowvoteListController' =>
array(
0 => 'PhabricatorSlowvoteController',

View file

@ -44,6 +44,7 @@ final class PhabricatorApplicationSlowvote extends PhabricatorApplication {
=> 'PhabricatorSlowvoteListController',
'create/' => 'PhabricatorSlowvoteCreateController',
'(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController',
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController',
),
);
}

View file

@ -0,0 +1,70 @@
<?php
final class PhabricatorSlowvoteCommentController
extends PhabricatorSlowvoteController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$poll = id(new PhabricatorSlowvoteQuery())
->setViewer($user)
->withIDs(array($this->id))
->executeOne();
if (!$poll) {
return new Aphront404Response();
}
$is_preview = $request->isPreviewRequest();
$draft = PhabricatorDraft::buildFromRequest($request);
$view_uri = '/V'.$poll->getID();
$xactions = array();
$xactions[] = id(new PhabricatorSlowvoteTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->attachComment(
id(new PhabricatorSlowvoteTransactionComment())
->setContent($request->getStr('comment')));
$editor = id(new PhabricatorSlowvoteEditor())
->setActor($user)
->setContinueOnNoEffect($request->isContinueRequest())
->setContentSourceFromRequest($request)
->setIsPreview($is_preview);
try {
$xactions = $editor->applyTransactions($poll, $xactions);
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($view_uri)
->setException($ex);
}
if ($draft) {
$draft->replaceOrDelete();
}
if ($request->isAjax()) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($user)
->setTransactions($xactions)
->setIsPreview($is_preview)
->setAnchorOffset($request->getStr('anchor'));
} else {
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
}
}

View file

@ -140,6 +140,7 @@ final class PhabricatorSlowvotePollController
$panel);
$xactions = $this->buildTransactions($poll);
$add_comment = $this->buildCommentForm($poll);
return $this->buildApplicationPage(
array(
@ -147,6 +148,7 @@ final class PhabricatorSlowvotePollController
$header,
$content,
$xactions,
$add_comment,
),
array(
'title' => 'V'.$poll->getID().' '.$poll->getQuestion(),
@ -384,4 +386,34 @@ final class PhabricatorSlowvotePollController
return $timeline;
}
private function buildCommentForm(PhabricatorSlowvotePoll $poll) {
$viewer = $this->getRequest()->getUser();
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$add_comment_header = id(new PhabricatorHeaderView())
->setHeader(
$is_serious
? pht('Add Comment')
: pht('Enter Deliberations'));
$submit_button_name = $is_serious
? pht('Add Comment')
: pht('Perhaps');
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $poll->getPHID());
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setDraft($draft)
->setAction($this->getApplicationURI('/comment/'.$poll->getID().'/'))
->setSubmitButtonName($submit_button_name);
return array(
$add_comment_header,
$add_comment_form,
);
}
}

View file

@ -0,0 +1,44 @@
<?php
final class PhabricatorSlowvoteEditor
extends PhabricatorApplicationTransactionEditor {
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT;
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
}
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
}
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
}
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
return;
}
}