Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / diffusion / controller / DiffusionRepositoryURIDisableController.php
blob466a0fd388d3ba26c3faf6077a81bd9472828fa4
1 <?php
3 final class DiffusionRepositoryURIDisableController
4 extends DiffusionController {
6 public function handleRequest(AphrontRequest $request) {
7 $response = $this->loadDiffusionContextForEdit();
8 if ($response) {
9 return $response;
12 $viewer = $this->getViewer();
13 $drequest = $this->getDiffusionRequest();
14 $repository = $drequest->getRepository();
16 $id = $request->getURIData('id');
17 $uri = id(new PhabricatorRepositoryURIQuery())
18 ->setViewer($viewer)
19 ->withIDs(array($id))
20 ->withRepositories(array($repository))
21 ->requireCapabilities(
22 array(
23 PhabricatorPolicyCapability::CAN_VIEW,
24 PhabricatorPolicyCapability::CAN_EDIT,
26 ->executeOne();
27 if (!$uri) {
28 return new Aphront404Response();
31 $is_disabled = $uri->getIsDisabled();
32 $view_uri = $uri->getViewURI();
34 if ($uri->isBuiltin()) {
35 return $this->newDialog()
36 ->setTitle(pht('Builtin URI'))
37 ->appendParagraph(
38 pht(
39 'You can not manually disable builtin URIs. To hide a builtin '.
40 'URI, configure its "Display" behavior instead.'))
41 ->addCancelButton($view_uri);
44 if ($request->isFormPost()) {
45 $xactions = array();
47 $xactions[] = id(new PhabricatorRepositoryURITransaction())
48 ->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_DISABLE)
49 ->setNewValue(!$is_disabled);
51 $editor = id(new DiffusionURIEditor())
52 ->setActor($viewer)
53 ->setContinueOnNoEffect(true)
54 ->setContinueOnMissingFields(true)
55 ->setContentSourceFromRequest($request)
56 ->applyTransactions($uri, $xactions);
58 return id(new AphrontRedirectResponse())->setURI($view_uri);
61 if ($is_disabled) {
62 $title = pht('Enable URI');
63 $body = pht(
64 'Enable this URI? Any configured behaviors will begin working '.
65 'again.');
66 $button = pht('Enable URI');
67 } else {
68 $title = pht('Disable URI');
69 $body = pht(
70 'Disable this URI? It will no longer be observed, fetched, mirrored, '.
71 'served or shown to users.');
72 $button = pht('Disable URI');
75 return $this->newDialog()
76 ->setTitle($title)
77 ->appendParagraph($body)
78 ->addCancelButton($view_uri)
79 ->addSubmitButton($button);