Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / almanac / controller / AlmanacInterfaceDeleteController.php
blob4d40031b93d37ef76c6e5489b6e6af6766d82962
1 <?php
3 final class AlmanacInterfaceDeleteController
4 extends AlmanacDeviceController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
9 $id = $request->getURIData('id');
10 $interface = id(new AlmanacInterfaceQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->requireCapabilities(
14 array(
15 PhabricatorPolicyCapability::CAN_VIEW,
16 PhabricatorPolicyCapability::CAN_EDIT,
18 ->executeOne();
19 if (!$interface) {
20 return new Aphront404Response();
23 $device = $interface->getDevice();
24 $device_uri = $device->getURI();
26 if ($interface->loadIsInUse()) {
27 return $this->newDialog()
28 ->setTitle(pht('Interface In Use'))
29 ->appendParagraph(
30 pht(
31 'You can not delete this interface because it is currently in '.
32 'use. One or more services are bound to it.'))
33 ->addCancelButton($device_uri);
36 if ($request->isFormPost()) {
37 $type_destroy = AlmanacInterfaceDestroyTransaction::TRANSACTIONTYPE;
39 $xactions = array();
41 $xactions[] = $interface->getApplicationTransactionTemplate()
42 ->setTransactionType($type_destroy)
43 ->setNewValue(true);
45 $editor = id(new AlmanacInterfaceEditor())
46 ->setActor($viewer)
47 ->setContentSourceFromRequest($request)
48 ->setContinueOnNoEffect(true)
49 ->setContinueOnMissingFields(true);
51 $editor->applyTransactions($interface, $xactions);
53 return id(new AphrontRedirectResponse())->setURI($device_uri);
56 return $this->newDialog()
57 ->setTitle(pht('Delete Interface'))
58 ->appendParagraph(
59 pht(
60 'Remove interface %s on device %s?',
61 phutil_tag('strong', array(), $interface->renderDisplayAddress()),
62 phutil_tag('strong', array(), $device->getName())))
63 ->addCancelButton($device_uri)
64 ->addSubmitButton(pht('Delete Interface'));