@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 65 lines 2.0 kB view raw
1<?php 2 3final 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}