2012-12-11 23:01:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorApplicationTransactionCommentEditController
|
|
|
|
extends PhabricatorApplicationTransactionController {
|
|
|
|
|
|
|
|
private $phid;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->phid = $data['phid'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-08-23 01:45:14 +02:00
|
|
|
$xaction = id(new PhabricatorObjectQuery())
|
|
|
|
->withPHIDs(array($this->phid))
|
2012-12-11 23:01:51 +01:00
|
|
|
->setViewer($user)
|
2013-08-23 01:45:14 +02:00
|
|
|
->executeOne();
|
2012-12-11 23:01:51 +01:00
|
|
|
|
|
|
|
if (!$xaction) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$xaction->getComment()) {
|
|
|
|
// You can't currently edit a transaction which doesn't have a comment.
|
|
|
|
// Some day you may be able to edit the visibility.
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2014-05-05 19:55:32 +02:00
|
|
|
if ($xaction->getComment()->getIsRemoved()) {
|
|
|
|
// You can't edit history of a transaction with a removed comment.
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
2012-12-11 23:01:51 +01:00
|
|
|
$obj_phid = $xaction->getObjectPHID();
|
2013-09-11 21:27:28 +02:00
|
|
|
$obj_handle = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs(array($obj_phid))
|
|
|
|
->executeOne();
|
2012-12-11 23:01:51 +01:00
|
|
|
|
|
|
|
if ($request->isDialogFormPost()) {
|
|
|
|
$text = $request->getStr('text');
|
|
|
|
|
|
|
|
$comment = $xaction->getApplicationTransactionCommentObject();
|
|
|
|
$comment->setContent($text);
|
|
|
|
if (!strlen($text)) {
|
|
|
|
$comment->setIsDeleted(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorApplicationTransactionCommentEditor())
|
|
|
|
->setActor($user)
|
2013-07-26 02:40:33 +02:00
|
|
|
->setContentSource(PhabricatorContentSource::newFromRequest($request))
|
2012-12-11 23:01:51 +01:00
|
|
|
->applyEdit($xaction, $comment);
|
|
|
|
|
2012-12-11 23:02:12 +01:00
|
|
|
if ($request->isAjax()) {
|
2012-12-11 23:02:29 +01:00
|
|
|
return id(new PhabricatorApplicationTransactionResponse())
|
2012-12-11 23:02:12 +01:00
|
|
|
->setViewer($user)
|
2012-12-11 23:02:29 +01:00
|
|
|
->setTransactions(array($xaction))
|
|
|
|
->setAnchorOffset($request->getStr('anchor'));
|
2012-12-11 23:02:12 +01:00
|
|
|
} else {
|
|
|
|
return id(new AphrontReloadResponse())->setURI($obj_handle->getURI());
|
|
|
|
}
|
2012-12-11 23:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
2014-05-02 18:37:34 +02:00
|
|
|
->setSubmitURI(
|
|
|
|
$this->getApplicationURI('/transactions/edit/'.$xaction->getPHID().'/'))
|
2012-12-11 23:01:51 +01:00
|
|
|
->setTitle(pht('Edit Comment'));
|
|
|
|
|
|
|
|
$dialog
|
2012-12-11 23:02:12 +01:00
|
|
|
->addHiddenInput('anchor', $request->getStr('anchor'))
|
2012-12-11 23:01:51 +01:00
|
|
|
->appendChild(
|
2013-08-26 20:53:11 +02:00
|
|
|
id(new PHUIFormLayoutView())
|
2013-07-26 02:40:33 +02:00
|
|
|
->setFullWidth(true)
|
|
|
|
->appendChild(
|
|
|
|
id(new PhabricatorRemarkupControl())
|
2012-12-11 23:01:51 +01:00
|
|
|
->setName('text')
|
2013-07-26 02:40:33 +02:00
|
|
|
->setValue($xaction->getComment()->getContent())));
|
2012-12-11 23:01:51 +01:00
|
|
|
|
|
|
|
$dialog
|
2014-05-05 19:55:32 +02:00
|
|
|
->addSubmitButton(pht('Save Changes'))
|
2012-12-11 23:01:51 +01:00
|
|
|
->addCancelButton($obj_handle->getURI());
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|