Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / transactions / controller / PhabricatorApplicationTransactionCommentRemoveController.php
blob4d6570b13d10b1cc7dba7446159698a5895f11d4
1 <?php
3 final class PhabricatorApplicationTransactionCommentRemoveController
4 extends PhabricatorApplicationTransactionController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
8 $phid = $request->getURIData('phid');
10 $xaction = id(new PhabricatorObjectQuery())
11 ->withPHIDs(array($phid))
12 ->setViewer($viewer)
13 ->executeOne();
14 if (!$xaction) {
15 return new Aphront404Response();
18 if (!$xaction->getComment()) {
19 return new Aphront404Response();
22 if ($xaction->getComment()->getIsRemoved()) {
23 // You can't remove an already-removed comment.
24 return new Aphront400Response();
27 $obj_phid = $xaction->getObjectPHID();
28 $obj_handle = id(new PhabricatorHandleQuery())
29 ->setViewer($viewer)
30 ->withPHIDs(array($obj_phid))
31 ->executeOne();
33 $done_uri = $obj_handle->getURI();
35 // We allow administrative removal of comments even if an object is locked,
36 // so you can lock a flamewar and then go clean it up. Locked threads may
37 // not otherwise be edited, and non-administrators can not remove comments
38 // from locked threads.
40 $object = $xaction->getObject();
41 $can_interact = PhabricatorPolicyFilter::canInteract(
42 $viewer,
43 $object);
44 if (!$can_interact && !$viewer->getIsAdmin()) {
45 return $this->newDialog()
46 ->setTitle(pht('Conversation Locked'))
47 ->appendParagraph(
48 pht(
49 'You can not remove this comment because the conversation is '.
50 'locked.'))
51 ->addCancelButton($done_uri);
54 if ($request->isFormOrHisecPost()) {
55 $comment = $xaction->getApplicationTransactionCommentObject()
56 ->setContent('')
57 ->setIsRemoved(true);
59 $editor = id(new PhabricatorApplicationTransactionCommentEditor())
60 ->setActor($viewer)
61 ->setRequest($request)
62 ->setCancelURI($done_uri)
63 ->setContentSource(PhabricatorContentSource::newFromRequest($request))
64 ->applyEdit($xaction, $comment);
66 if ($request->isAjax()) {
67 return id(new AphrontAjaxResponse())->setContent(array());
68 } else {
69 return id(new AphrontReloadResponse())->setURI($done_uri);
73 $form = id(new AphrontFormView())
74 ->setUser($viewer);
76 $dialog = $this->newDialog()
77 ->setTitle(pht('Remove Comment'));
79 $dialog
80 ->appendParagraph(
81 pht(
82 "Removing a comment prevents anyone (including you) from reading ".
83 "it. Removing a comment also hides the comment's edit history ".
84 "and prevents it from being edited."))
85 ->appendParagraph(
86 pht('Really remove this comment?'));
88 $dialog
89 ->addSubmitButton(pht('Remove Comment'))
90 ->addCancelButton($done_uri);
92 return $dialog;