Differential D14629 Diff 35395 src/applications/transactions/controller/PhabricatorApplicationTransactionCommentHistoryController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/controller/PhabricatorApplicationTransactionCommentHistoryController.php
<?php | <?php | ||||
final class PhabricatorApplicationTransactionCommentHistoryController | final class PhabricatorApplicationTransactionCommentHistoryController | ||||
extends PhabricatorApplicationTransactionController { | extends PhabricatorApplicationTransactionController { | ||||
private $phid; | |||||
public function shouldAllowPublic() { | public function shouldAllowPublic() { | ||||
return true; | return true; | ||||
} | } | ||||
public function willProcessRequest(array $data) { | public function handleRequest(AphrontRequest $request) { | ||||
$this->phid = $data['phid']; | $viewer = $this->getViewer(); | ||||
} | $phid = $request->getURIData('phid'); | ||||
public function processRequest() { | |||||
$request = $this->getRequest(); | |||||
$user = $request->getUser(); | |||||
$xaction = id(new PhabricatorObjectQuery()) | $xaction = id(new PhabricatorObjectQuery()) | ||||
->withPHIDs(array($this->phid)) | ->withPHIDs(array($phid)) | ||||
->setViewer($user) | ->setViewer($viewer) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$xaction) { | if (!$xaction) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
if (!$xaction->getComment()) { | if (!$xaction->getComment()) { | ||||
// You can't view history of a transaction with no comments. | // You can't view history of a transaction with no comments. | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
if ($xaction->getComment()->getIsRemoved()) { | if ($xaction->getComment()->getIsRemoved()) { | ||||
// You can't view history of a transaction with a removed comment. | // You can't view history of a transaction with a removed comment. | ||||
return new Aphront400Response(); | return new Aphront400Response(); | ||||
} | } | ||||
$comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery()) | $comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery()) | ||||
->setViewer($user) | ->setViewer($viewer) | ||||
->setTemplate($xaction->getApplicationTransactionCommentObject()) | ->setTemplate($xaction->getApplicationTransactionCommentObject()) | ||||
->withTransactionPHIDs(array($xaction->getPHID())) | ->withTransactionPHIDs(array($xaction->getPHID())) | ||||
->execute(); | ->execute(); | ||||
if (!$comments) { | if (!$comments) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$comments = msort($comments, 'getCommentVersion'); | $comments = msort($comments, 'getCommentVersion'); | ||||
$xactions = array(); | $xactions = array(); | ||||
foreach ($comments as $comment) { | foreach ($comments as $comment) { | ||||
$xactions[] = id(clone $xaction) | $xactions[] = id(clone $xaction) | ||||
->makeEphemeral() | ->makeEphemeral() | ||||
->setCommentVersion($comment->getCommentVersion()) | ->setCommentVersion($comment->getCommentVersion()) | ||||
->setContentSource($comment->getContentSource()) | ->setContentSource($comment->getContentSource()) | ||||
->setDateCreated($comment->getDateCreated()) | ->setDateCreated($comment->getDateCreated()) | ||||
->attachComment($comment); | ->attachComment($comment); | ||||
} | } | ||||
$obj_phid = $xaction->getObjectPHID(); | $obj_phid = $xaction->getObjectPHID(); | ||||
$obj_handle = id(new PhabricatorHandleQuery()) | $obj_handle = id(new PhabricatorHandleQuery()) | ||||
->setViewer($user) | ->setViewer($viewer) | ||||
->withPHIDs(array($obj_phid)) | ->withPHIDs(array($obj_phid)) | ||||
->executeOne(); | ->executeOne(); | ||||
$view = id(new PhabricatorApplicationTransactionView()) | $view = id(new PhabricatorApplicationTransactionView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->setObjectPHID($obj_phid) | ->setObjectPHID($obj_phid) | ||||
->setTransactions($xactions) | ->setTransactions($xactions) | ||||
->setShowEditActions(false) | ->setShowEditActions(false) | ||||
->setHideCommentOptions(true); | ->setHideCommentOptions(true); | ||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->setWidth(AphrontDialogView::WIDTH_FULL) | ->setWidth(AphrontDialogView::WIDTH_FULL) | ||||
->setFlush(true) | ->setFlush(true) | ||||
->setTitle(pht('Comment History')); | ->setTitle(pht('Comment History')); | ||||
$dialog->appendChild($view); | $dialog->appendChild($view); | ||||
$dialog | $dialog | ||||
->addCancelButton($obj_handle->getURI()); | ->addCancelButton($obj_handle->getURI()); | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
} | } | ||||
} | } |