Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/controller/AlmanacInterfaceDeleteController.php
12256 views
1
<?php
2
3
final 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
}
68
69