@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 67 lines 2.0 kB view raw
1<?php 2 3final class AlmanacInterfaceDeleteController 4 extends AlmanacDeviceController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getViewer(); 8 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, 17 )) 18 ->executeOne(); 19 if (!$interface) { 20 return new Aphront404Response(); 21 } 22 23 $device = $interface->getDevice(); 24 $device_uri = $device->getURI(); 25 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); 34 } 35 36 if ($request->isFormPost()) { 37 $type_destroy = AlmanacInterfaceDestroyTransaction::TRANSACTIONTYPE; 38 39 $xactions = array(); 40 41 $xactions[] = $interface->getApplicationTransactionTemplate() 42 ->setTransactionType($type_destroy) 43 ->setNewValue(true); 44 45 $editor = id(new AlmanacInterfaceEditor()) 46 ->setActor($viewer) 47 ->setContentSourceFromRequest($request) 48 ->setContinueOnNoEffect(true) 49 ->setContinueOnMissingFields(true); 50 51 $editor->applyTransactions($interface, $xactions); 52 53 return id(new AphrontRedirectResponse())->setURI($device_uri); 54 } 55 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')); 65 } 66 67}