Give Phame blogs mutable interact policies
[phabricator.git] / src / applications / phame / controller / blog / PhameBlogArchiveController.php
blob8b63bad9ff8bfa58f098197336f7de185702b7dc
1 <?php
3 final class PhameBlogArchiveController
4 extends PhameBlogController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
10 $blog = id(new PhameBlogQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->requireCapabilities(
14 array(
15 PhabricatorPolicyCapability::CAN_VIEW,
16 PhabricatorPolicyCapability::CAN_EDIT,
18 ->executeOne();
19 if (!$blog) {
20 return new Aphront404Response();
23 $view_uri = $this->getApplicationURI('blog/manage/'.$blog->getID().'/');
25 if ($request->isFormPost()) {
26 if ($blog->isArchived()) {
27 $new_status = PhameBlog::STATUS_ACTIVE;
28 } else {
29 $new_status = PhameBlog::STATUS_ARCHIVED;
32 $xactions = array();
34 $xactions[] = id(new PhameBlogTransaction())
35 ->setTransactionType(PhameBlogStatusTransaction::TRANSACTIONTYPE)
36 ->setNewValue($new_status);
38 id(new PhameBlogEditor())
39 ->setActor($viewer)
40 ->setContentSourceFromRequest($request)
41 ->setContinueOnNoEffect(true)
42 ->setContinueOnMissingFields(true)
43 ->applyTransactions($blog, $xactions);
45 return id(new AphrontRedirectResponse())->setURI($view_uri);
48 if ($blog->isArchived()) {
49 $title = pht('Activate Blog');
50 $body = pht('This blog will become active again.');
51 $button = pht('Activate Blog');
52 } else {
53 $title = pht('Archive Blog');
54 $body = pht('This blog will be marked as archived.');
55 $button = pht('Archive Blog');
58 $dialog = id(new AphrontDialogView())
59 ->setUser($viewer)
60 ->setTitle($title)
61 ->appendChild($body)
62 ->addCancelButton($view_uri)
63 ->addSubmitButton($button);
65 return id(new AphrontDialogResponse())->setDialog($dialog);