@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 56 lines 1.6 kB view raw
1<?php 2 3final class DrydockResourceReleaseController extends DrydockResourceController { 4 5 public function handleRequest(AphrontRequest $request) { 6 $viewer = $request->getViewer(); 7 $id = $request->getURIData('id'); 8 9 $resource = id(new DrydockResourceQuery()) 10 ->setViewer($viewer) 11 ->withIDs(array($id)) 12 ->requireCapabilities( 13 array( 14 PhabricatorPolicyCapability::CAN_VIEW, 15 PhabricatorPolicyCapability::CAN_EDIT, 16 )) 17 ->executeOne(); 18 if (!$resource) { 19 return new Aphront404Response(); 20 } 21 22 $resource_uri = '/resource/'.$resource->getID().'/'; 23 $resource_uri = $this->getApplicationURI($resource_uri); 24 25 if (!$resource->canRelease()) { 26 return $this->newDialog() 27 ->setTitle(pht('Resource Not Releasable')) 28 ->appendParagraph( 29 pht( 30 'Resources can not be released after they are destroyed.')) 31 ->addCancelButton($resource_uri); 32 } 33 34 if ($request->isFormPost()) { 35 $command = DrydockCommand::initializeNewCommand($viewer) 36 ->setTargetPHID($resource->getPHID()) 37 ->setCommand(DrydockCommand::COMMAND_RELEASE) 38 ->save(); 39 40 $resource->scheduleUpdate(); 41 42 return id(new AphrontRedirectResponse())->setURI($resource_uri); 43 } 44 45 46 return $this->newDialog() 47 ->setTitle(pht('Really release resource?')) 48 ->appendChild( 49 pht( 50 'Releasing a resource releases all leases and destroys the '. 51 'resource. It can not be undone.')) 52 ->addSubmitButton(pht('Release Resource')) 53 ->addCancelButton($resource_uri); 54 } 55 56}