Differential D14740 Diff 35652 src/applications/phame/controller/post/PhamePostPublishController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/controller/post/PhamePostPublishController.php
| <?php | <?php | ||||
| final class PhamePostPublishController extends PhamePostController { | final class PhamePostPublishController extends PhamePostController { | ||||
| public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
| $viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
| $id = $request->getURIData('id'); | |||||
| $id = $request->getURIData('id'); | |||||
| $post = id(new PhamePostQuery()) | $post = id(new PhamePostQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withIDs(array($id)) | ->withIDs(array($id)) | ||||
| ->requireCapabilities( | ->requireCapabilities( | ||||
| array( | array( | ||||
| PhabricatorPolicyCapability::CAN_VIEW, | |||||
| PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
| )) | )) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$post) { | if (!$post) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $cancel_uri = $post->getViewURI(); | |||||
| $action = $request->getURIData('action'); | |||||
| $is_publish = ($action == 'publish'); | |||||
| if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
| $xactions = array(); | $xactions = array(); | ||||
| if ($is_publish) { | |||||
| $new_value = PhameConstants::VISIBILITY_PUBLISHED; | |||||
| } else { | |||||
| $new_value = PhameConstants::VISIBILITY_DRAFT; | |||||
| } | |||||
| $xactions[] = id(new PhamePostTransaction()) | $xactions[] = id(new PhamePostTransaction()) | ||||
| ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) | ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) | ||||
| ->setNewValue(PhameConstants::VISIBILITY_PUBLISHED); | ->setNewValue($new_value); | ||||
| id(new PhamePostEditor()) | id(new PhamePostEditor()) | ||||
| ->setActor($viewer) | ->setActor($viewer) | ||||
| ->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
| ->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
| ->setContinueOnMissingFields(true) | ->setContinueOnMissingFields(true) | ||||
| ->applyTransactions($post, $xactions); | ->applyTransactions($post, $xactions); | ||||
| return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
| ->setURI($this->getApplicationURI('/post/view/'.$post->getID().'/')); | ->setURI($cancel_uri); | ||||
| } | } | ||||
| $cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/'); | if ($is_publish) { | ||||
| $title = pht('Publish Post'); | |||||
| $body = pht('This post will go live once you publish it.'); | |||||
| $button = pht('Publish'); | |||||
| } else { | |||||
| $title = pht('Unpublish Post'); | |||||
| $body = pht( | |||||
| 'This post will revert to draft status and no longer be visible '. | |||||
| 'to other users.'); | |||||
| $button = pht('Unpublish'); | |||||
| } | |||||
| $dialog = $this->newDialog() | return $this->newDialog() | ||||
| ->setTitle(pht('Publish Post?')) | ->setTitle($title) | ||||
| ->appendChild( | ->appendParagraph($body) | ||||
| pht( | ->addSubmitButton($button) | ||||
| 'The post "%s" will go live once you publish it.', | |||||
| $post->getTitle())) | |||||
| ->addSubmitButton(pht('Publish')) | |||||
| ->addCancelButton($cancel_uri); | ->addCancelButton($cancel_uri); | ||||
| return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
| } | } | ||||
| } | } | ||||