2012-12-11 23:01:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorApplicationTransactionCommentEditController
|
|
|
|
extends PhabricatorApplicationTransactionController {
|
|
|
|
|
2015-06-29 20:30:27 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
2012-12-11 23:01:51 +01:00
|
|
|
|
2013-08-23 01:45:14 +02:00
|
|
|
$xaction = id(new PhabricatorObjectQuery())
|
2015-06-29 20:30:27 +02:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($request->getURIData('phid')))
|
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();
|
|
|
|
}
|
|
|
|
|
2015-06-29 20:30:27 +02:00
|
|
|
$phid = $xaction->getObjectPHID();
|
|
|
|
$handles = $viewer->loadHandles(array($phid));
|
|
|
|
$obj_handle = $handles[$phid];
|
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())
|
2015-06-29 20:30:27 +02:00
|
|
|
->setActor($viewer)
|
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()) {
|
2014-05-05 19:57:23 +02:00
|
|
|
return id(new AphrontAjaxResponse())->setContent(array());
|
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
|
|
|
}
|
|
|
|
|
2015-06-29 20:30:27 +02:00
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setFullWidth(true)
|
|
|
|
->appendControl(
|
|
|
|
id(new PhabricatorRemarkupControl())
|
|
|
|
->setName('text')
|
|
|
|
->setValue($xaction->getComment()->getContent()));
|
2012-12-11 23:01:51 +01:00
|
|
|
|
2015-06-29 20:30:27 +02:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Edit Comment'))
|
2012-12-11 23:02:12 +01:00
|
|
|
->addHiddenInput('anchor', $request->getStr('anchor'))
|
2015-06-29 20:30:27 +02:00
|
|
|
->appendForm($form)
|
2014-05-05 19:55:32 +02:00
|
|
|
->addSubmitButton(pht('Save Changes'))
|
2012-12-11 23:01:51 +01:00
|
|
|
->addCancelButton($obj_handle->getURI());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|