Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/drydock/controller/DrydockBlueprintDisableController.php
12256 views
1
<?php
2
3
final class DrydockBlueprintDisableController
4
extends DrydockBlueprintController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $request->getViewer();
8
$id = $request->getURIData('id');
9
10
$blueprint = id(new DrydockBlueprintQuery())
11
->setViewer($viewer)
12
->withIDs(array($id))
13
->requireCapabilities(
14
array(
15
PhabricatorPolicyCapability::CAN_VIEW,
16
PhabricatorPolicyCapability::CAN_EDIT,
17
))
18
->executeOne();
19
if (!$blueprint) {
20
return new Aphront404Response();
21
}
22
23
$is_disable = ($request->getURIData('action') == 'disable');
24
$id = $blueprint->getID();
25
$cancel_uri = $this->getApplicationURI("blueprint/{$id}/");
26
27
if ($request->isFormPost()) {
28
$xactions = array();
29
30
$xactions[] = id(new DrydockBlueprintTransaction())
31
->setTransactionType(
32
DrydockBlueprintDisableTransaction::TRANSACTIONTYPE)
33
->setNewValue($is_disable ? 1 : 0);
34
35
$editor = id(new DrydockBlueprintEditor())
36
->setActor($viewer)
37
->setContentSourceFromRequest($request)
38
->setContinueOnNoEffect(true)
39
->setContinueOnMissingFields(true)
40
->applyTransactions($blueprint, $xactions);
41
42
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
43
}
44
45
if ($is_disable) {
46
$title = pht('Disable Blueprint');
47
$body = pht(
48
'If you disable this blueprint, Drydock will no longer use it to '.
49
'allocate new resources. Existing resources will not be affected.');
50
$button = pht('Disable Blueprint');
51
} else {
52
$title = pht('Enable Blueprint');
53
$body = pht(
54
'If you enable this blueprint, Drydock will start using it to '.
55
'allocate new resources.');
56
$button = pht('Enable Blueprint');
57
}
58
59
return $this->newDialog()
60
->setTitle($title)
61
->appendParagraph($body)
62
->addCancelButton($cancel_uri)
63
->addSubmitButton($button);
64
}
65
}
66
67