@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PholioMockCommentController extends PholioController {
4
5 public function handleRequest(AphrontRequest $request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
8
9 if (!$request->isFormPost()) {
10 return new Aphront400Response();
11 }
12
13 $mock = id(new PholioMockQuery())
14 ->setViewer($viewer)
15 ->withIDs(array($id))
16 ->needImages(true)
17 ->executeOne();
18
19 if (!$mock) {
20 return new Aphront404Response();
21 }
22
23 $is_preview = $request->isPreviewRequest();
24
25 $draft = PhabricatorDraft::buildFromRequest($request);
26
27 $mock_uri = $mock->getURI();
28
29 $comment = $request->getStr('comment');
30
31 $xactions = array();
32
33 $inline_comments = id(new PholioTransactionComment())->loadAllWhere(
34 'authorphid = %s AND transactionphid IS NULL AND imageid IN (%Ld)',
35 $viewer->getPHID(),
36 mpull($mock->getActiveImages(), 'getID'));
37
38 if (!$inline_comments || strlen($comment)) {
39 $xactions[] = id(new PholioTransaction())
40 ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
41 ->attachComment(
42 id(new PholioTransactionComment())
43 ->setContent($comment));
44 }
45
46 foreach ($inline_comments as $inline_comment) {
47 $xactions[] = id(new PholioTransaction())
48 ->setTransactionType(PholioMockInlineTransaction::TRANSACTIONTYPE)
49 ->attachComment($inline_comment);
50 }
51
52 $editor = id(new PholioMockEditor())
53 ->setActor($viewer)
54 ->setContentSourceFromRequest($request)
55 ->setContinueOnNoEffect($request->isContinueRequest())
56 ->setIsPreview($is_preview);
57
58 try {
59 $xactions = $editor->applyTransactions($mock, $xactions);
60 } catch (PhabricatorApplicationTransactionNoEffectException $ex) {
61 return id(new PhabricatorApplicationTransactionNoEffectResponse())
62 ->setCancelURI($mock_uri)
63 ->setException($ex);
64 }
65
66 if ($draft) {
67 $draft->replaceOrDelete();
68 }
69
70 if ($request->isAjax() && $is_preview) {
71 return id(new PhabricatorApplicationTransactionResponse())
72 ->setObject($mock)
73 ->setViewer($viewer)
74 ->setTransactions($xactions)
75 ->setIsPreview($is_preview);
76 } else {
77 return id(new AphrontRedirectResponse())->setURI($mock_uri);
78 }
79 }
80
81}