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();
|
|
|
|
|
|
|
|
$xactions = id(new PhabricatorObjectHandleData(array($this->phid)))
|
|
|
|
->setViewer($user)
|
|
|
|
->loadObjects();
|
|
|
|
$xaction = idx($xactions, $this->phid);
|
|
|
|
|
|
|
|
if (!$xaction) {
|
|
|
|
// TODO: This may also mean you don't have permission to edit the object,
|
|
|
|
// but we can't make that distinction via PhabricatorObjectHandleData
|
|
|
|
// at the moment.
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj_phid = $xaction->getObjectPHID();
|
|
|
|
$obj_handle = PhabricatorObjectHandleData::loadOneHandle($obj_phid, $user);
|
|
|
|
if (!$obj_handle) {
|
|
|
|
// Require the corresponding object exist and be visible to the user.
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
->setContentSource(
|
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
|
|
array(
|
|
|
|
'ip' => $request->getRemoteAddr(),
|
|
|
|
)))
|
|
|
|
->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)
|
|
|
|
->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(
|
|
|
|
id(new PhabricatorRemarkupControl())
|
|
|
|
->setName('text')
|
|
|
|
->setValue($xaction->getComment()->getContent()));
|
|
|
|
|
|
|
|
$dialog
|
|
|
|
->addSubmitButton(pht('Edit Comment'))
|
|
|
|
->addCancelButton($obj_handle->getURI());
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|