Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phame / controller / post / PhamePostMoveController.php
blobd088b260b5bd5b4504c31f31b2df1f0e1f58dd7f
1 <?php
3 final class PhamePostMoveController extends PhamePostController {
5 public function handleRequest(AphrontRequest $request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
9 $post = id(new PhamePostQuery())
10 ->setViewer($viewer)
11 ->withIDs(array($id))
12 ->requireCapabilities(
13 array(
14 PhabricatorPolicyCapability::CAN_EDIT,
15 PhabricatorPolicyCapability::CAN_VIEW,
17 ->executeOne();
19 if (!$post) {
20 return new Aphront404Response();
23 $view_uri = $post->getViewURI();
24 $v_blog = $post->getBlog()->getPHID();
26 if ($request->isFormPost()) {
27 $v_blog = $request->getStr('blogPHID');
29 $xactions = array();
30 $xactions[] = id(new PhamePostTransaction())
31 ->setTransactionType(PhamePostBlogTransaction::TRANSACTIONTYPE)
32 ->setNewValue($v_blog);
34 $editor = id(new PhamePostEditor())
35 ->setActor($viewer)
36 ->setContentSourceFromRequest($request)
37 ->setContinueOnMissingFields(true)
38 ->setContinueOnNoEffect(true);
40 $editor->applyTransactions($post, $xactions);
42 $view_uri = $post->getViewURI();
44 return id(new AphrontRedirectResponse())
45 ->setURI($view_uri.'?moved=1');
48 $blogs = id(new PhameBlogQuery())
49 ->setViewer($viewer)
50 ->requireCapabilities(
51 array(
52 PhabricatorPolicyCapability::CAN_VIEW,
53 PhabricatorPolicyCapability::CAN_EDIT,
55 ->execute();
57 $options = mpull($blogs, 'getName', 'getPHID');
58 asort($options);
60 $form = id(new PHUIFormLayoutView())
61 ->setUser($viewer)
62 ->appendChild(
63 id(new AphrontFormSelectControl())
64 ->setLabel(pht('Blog'))
65 ->setName('blogPHID')
66 ->setOptions($options)
67 ->setValue($v_blog));
69 return $this->newDialog()
70 ->setTitle(pht('Move Post'))
71 ->appendChild($form)
72 ->addSubmitButton(pht('Move Post'))
73 ->addCancelButton($view_uri);