Differential D16565 Diff 39942 src/applications/drydock/conduit/DrydockDestroyLeaseConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/conduit/DrydockDestroyLeaseConduitAPIMethod.php
- This file was added.
<?php | |||||
final class DrydockDestroyLeaseConduitAPIMethod | |||||
extends DrydockConduitAPIMethod { | |||||
public function getAPIMethodName() { | |||||
return 'drydock.destroylease'; | |||||
} | |||||
public function getMethodDescription() { | |||||
return pht('Destroy a Drydock lease.'); | |||||
} | |||||
protected function defineParamTypes() { | |||||
return array( | |||||
'leasePHID' => 'required phid', | |||||
); | |||||
} | |||||
protected function defineErrorTypes() { | |||||
return array( | |||||
'ERR_NO_LEASE' => pht('No active lease exists with this ID.'), | |||||
'ERR_NOT_AUTHORIZED' => pht( | |||||
'You are not authorized to destroy this lease.'), | |||||
); | |||||
} | |||||
protected function defineReturnType() { | |||||
return 'map<string, wild>'; | |||||
} | |||||
protected function execute(ConduitAPIRequest $request) { | |||||
$viewer = $request->getUser(); | |||||
$lease = id(new DrydockLeaseQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs(array($request->getValue('leasePHID'))) | |||||
->executeOne(); | |||||
if (!$lease) { | |||||
throw new ConduitException('ERR_NO_LEASE'); | |||||
} | |||||
if ($lease->getOwnerPHID() !== $viewer->getPHID()) { | |||||
throw new ConduitException('ERR_NOT_AUTHORIZED'); | |||||
} | |||||
$command = DrydockCommand::initializeNewCommand($viewer) | |||||
->setTargetPHID($lease->getPHID()) | |||||
->setCommand(DrydockCommand::COMMAND_RELEASE) | |||||
->save(); | |||||
$lease->scheduleUpdate(); | |||||
$search = id(new ConduitCall('drydock.lease.search', array( | |||||
'constraints' => array( | |||||
'phids' => array($lease->getPHID()), | |||||
), | |||||
))) | |||||
->setUser($viewer) | |||||
->execute(); | |||||
return idxv($search, array('data', 0)); | |||||
} | |||||
} |