Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phame / controller / post / PhamePostPublishController.php
blob70989082bd2e026985f5d1e4f8c60470c379f1e7
1 <?php
3 final class PhamePostPublishController extends PhamePostController {
5 public function handleRequest(AphrontRequest $request) {
6 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
9 $post = id(new PhamePostQuery())
10 ->setViewer($viewer)
11 ->withIDs(array($id))
12 ->requireCapabilities(
13 array(
14 PhabricatorPolicyCapability::CAN_VIEW,
15 PhabricatorPolicyCapability::CAN_EDIT,
17 ->executeOne();
18 if (!$post) {
19 return new Aphront404Response();
22 $cancel_uri = $post->getViewURI();
24 $action = $request->getURIData('action');
25 $is_publish = ($action == 'publish');
27 if ($request->isFormPost()) {
28 $xactions = array();
30 if ($is_publish) {
31 $new_value = PhameConstants::VISIBILITY_PUBLISHED;
32 } else {
33 $new_value = PhameConstants::VISIBILITY_DRAFT;
36 $xactions[] = id(new PhamePostTransaction())
37 ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE)
38 ->setNewValue($new_value);
40 id(new PhamePostEditor())
41 ->setActor($viewer)
42 ->setContentSourceFromRequest($request)
43 ->setContinueOnNoEffect(true)
44 ->setContinueOnMissingFields(true)
45 ->applyTransactions($post, $xactions);
47 return id(new AphrontRedirectResponse())
48 ->setURI($cancel_uri);
51 if ($is_publish) {
52 $title = pht('Publish Post');
53 $body = pht('This post will go live once you publish it.');
54 $button = pht('Publish');
55 } else {
56 $title = pht('Unpublish Post');
57 $body = pht(
58 'This post will revert to draft status and no longer be visible '.
59 'to other users.');
60 $button = pht('Unpublish');
63 return $this->newDialog()
64 ->setTitle($title)
65 ->appendParagraph($body)
66 ->addSubmitButton($button)
67 ->addCancelButton($cancel_uri);