Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / almanac / controller / AlmanacBindingDisableController.php
blobd709db3e82fc4e12c5db3371bb9cb3406b5f3943
1 <?php
3 final class AlmanacBindingDisableController
4 extends AlmanacServiceController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
9 $id = $request->getURIData('id');
10 $binding = id(new AlmanacBindingQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->requireCapabilities(
14 array(
15 PhabricatorPolicyCapability::CAN_VIEW,
16 PhabricatorPolicyCapability::CAN_EDIT,
18 ->executeOne();
19 if (!$binding) {
20 return new Aphront404Response();
23 $id = $binding->getID();
24 $is_disable = !$binding->getIsDisabled();
25 $done_uri = $binding->getURI();
27 if ($is_disable) {
28 $disable_title = pht('Disable Binding');
29 $disable_body = pht('Disable this binding?');
30 $disable_button = pht('Disable Binding');
32 $v_disable = 1;
33 } else {
34 $disable_title = pht('Enable Binding');
35 $disable_body = pht('Enable this binding?');
36 $disable_button = pht('Enable Binding');
38 $v_disable = 0;
42 if ($request->isFormPost()) {
43 $type_disable = AlmanacBindingDisableTransaction::TRANSACTIONTYPE;
45 $xactions = array();
47 $xactions[] = id(new AlmanacBindingTransaction())
48 ->setTransactionType($type_disable)
49 ->setNewValue($v_disable);
51 $editor = id(new AlmanacBindingEditor())
52 ->setActor($viewer)
53 ->setContentSourceFromRequest($request)
54 ->setContinueOnNoEffect(true)
55 ->setContinueOnMissingFields(true);
57 $editor->applyTransactions($binding, $xactions);
59 return id(new AphrontRedirectResponse())->setURI($done_uri);
62 return $this->newDialog()
63 ->setTitle($disable_title)
64 ->appendParagraph($disable_body)
65 ->addSubmitButton($disable_button)
66 ->addCancelButton($done_uri);