@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 PhrictionPublishController
4 extends PhrictionController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('documentID');
9 $content_id = $request->getURIData('contentID');
10
11 $document = id(new PhrictionDocumentQuery())
12 ->setViewer($viewer)
13 ->withIDs(array($id))
14 ->needContent(true)
15 ->requireCapabilities(
16 array(
17 PhabricatorPolicyCapability::CAN_EDIT,
18 PhabricatorPolicyCapability::CAN_VIEW,
19 ))
20 ->executeOne();
21 if (!$document) {
22 return new Aphront404Response();
23 }
24
25 $document_uri = $document->getURI();
26
27 $content = id(new PhrictionContentQuery())
28 ->setViewer($viewer)
29 ->withIDs(array($content_id))
30 ->executeOne();
31 if (!$content) {
32 return new Aphront404Response();
33 }
34
35 if ($content->getPHID() == $document->getContentPHID()) {
36 return $this->newDialog()
37 ->setTitle(pht('Already Published'))
38 ->appendChild(
39 pht(
40 'This version of the document is already the published '.
41 'version.'))
42 ->addCancelButton($document_uri);
43 }
44
45 $content_uri = $document_uri.'?v='.$content->getVersion();
46
47 if ($request->isFormPost()) {
48 $xactions = array();
49
50 $xactions[] = id(new PhrictionTransaction())
51 ->setTransactionType(
52 PhrictionDocumentPublishTransaction::TRANSACTIONTYPE)
53 ->setNewValue($content->getPHID());
54
55 id(new PhrictionTransactionEditor())
56 ->setActor($viewer)
57 ->setContentSourceFromRequest($request)
58 ->setContinueOnNoEffect(true)
59 ->setContinueOnMissingFields(true)
60 ->applyTransactions($document, $xactions);
61
62 return id(new AphrontRedirectResponse())->setURI($document_uri);
63 }
64
65 if ($content->getVersion() < $document->getContent()->getVersion()) {
66 $title = pht('Publish Older Version?');
67 $body = pht(
68 'Revert the published version of this document to an older '.
69 'version?');
70 $button = pht('Revert');
71 } else {
72 $title = pht('Publish Draft?');
73 $body = pht(
74 'Update the published version of this document to this newer '.
75 'version?');
76 $button = pht('Publish');
77 }
78
79 return $this->newDialog()
80 ->setTitle($title)
81 ->appendChild($body)
82 ->addSubmitButton($button)
83 ->addCancelButton($content_uri);
84 }
85
86}