Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / badges / controller / PhabricatorBadgesCommentController.php
blob32e1775149b754bf9d0258d7df5736e5deaa98b5
1 <?php
3 final class PhabricatorBadgesCommentController
4 extends PhabricatorBadgesController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
10 if (!$request->isFormPost()) {
11 return new Aphront400Response();
14 $badge = id(new PhabricatorBadgesQuery())
15 ->setViewer($viewer)
16 ->withIDs(array($id))
17 ->executeOne();
18 if (!$badge) {
19 return new Aphront404Response();
22 $is_preview = $request->isPreviewRequest();
23 $draft = PhabricatorDraft::buildFromRequest($request);
25 $view_uri = $this->getApplicationURI('view/'.$badge->getID());
27 $xactions = array();
28 $xactions[] = id(new PhabricatorBadgesTransaction())
29 ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
30 ->attachComment(
31 id(new PhabricatorBadgesTransactionComment())
32 ->setContent($request->getStr('comment')));
34 $editor = id(new PhabricatorBadgesEditor())
35 ->setActor($viewer)
36 ->setContinueOnNoEffect($request->isContinueRequest())
37 ->setContentSourceFromRequest($request)
38 ->setIsPreview($is_preview);
40 try {
41 $xactions = $editor->applyTransactions($badge, $xactions);
42 } catch (PhabricatorApplicationTransactionNoEffectException $ex) {
43 return id(new PhabricatorApplicationTransactionNoEffectResponse())
44 ->setCancelURI($view_uri)
45 ->setException($ex);
48 if ($draft) {
49 $draft->replaceOrDelete();
52 if ($request->isAjax() && $is_preview) {
53 return id(new PhabricatorApplicationTransactionResponse())
54 ->setObject($badge)
55 ->setViewer($viewer)
56 ->setTransactions($xactions)
57 ->setIsPreview($is_preview);
58 } else {
59 return id(new AphrontRedirectResponse())
60 ->setURI($view_uri);