2012-12-15 00:42:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DrydockManagementReleaseWorkflow
|
|
|
|
extends DrydockManagementWorkflow {
|
|
|
|
|
2015-01-15 21:42:07 +01:00
|
|
|
protected function didConstruct() {
|
2012-12-15 00:42:58 +01:00
|
|
|
$this
|
|
|
|
->setName('release')
|
|
|
|
->setSynopsis('Release a lease.')
|
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'ids',
|
|
|
|
'wildcard' => true,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
|
|
|
$ids = $args->getArg('ids');
|
|
|
|
if (!$ids) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
2014-06-09 20:36:49 +02:00
|
|
|
'Specify one or more lease IDs to release.');
|
2012-12-15 00:42:58 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 22:15:40 +01:00
|
|
|
$viewer = $this->getViewer();
|
2013-12-26 19:41:36 +01:00
|
|
|
|
|
|
|
$leases = id(new DrydockLeaseQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs($ids)
|
|
|
|
->execute();
|
|
|
|
|
2012-12-15 00:42:58 +01:00
|
|
|
foreach ($ids as $id) {
|
2013-12-26 19:41:36 +01:00
|
|
|
$lease = idx($leases, $id);
|
2012-12-15 00:42:58 +01:00
|
|
|
if (!$lease) {
|
|
|
|
$console->writeErr("Lease %d does not exist!\n", $id);
|
|
|
|
} else if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
|
|
|
|
$console->writeErr("Lease %d is not 'active'!\n", $id);
|
|
|
|
} else {
|
2013-12-26 19:41:36 +01:00
|
|
|
$resource = $lease->getResource();
|
2012-12-15 00:42:58 +01:00
|
|
|
$blueprint = $resource->getBlueprint();
|
|
|
|
$blueprint->releaseLease($resource, $lease);
|
|
|
|
|
|
|
|
$console->writeErr("Released lease %d.\n", $id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|