1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-12 00:26:13 +01:00
phorge-phorge/src/applications/drydock/management/DrydockManagementReleaseWorkflow.php
epriestley e4bb9255be Allow leases to be explicitly released via web or CLI
Summary: Permit the forcible release of Drydock leases. The implementation isn't very exciting for now.

Test Plan: Released leases via web and CLI.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D4181
2012-12-14 15:42:58 -08:00

45 lines
1.1 KiB
PHP

<?php
final class DrydockManagementReleaseWorkflow
extends DrydockManagementWorkflow {
public function didConstruct() {
$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(
"Specify one or more lease IDs to release.");
}
foreach ($ids as $id) {
$lease = id(new DrydockLease())->load($id);
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 {
$resource = $lease->loadResource();
$blueprint = $resource->getBlueprint();
$blueprint->releaseLease($resource, $lease);
$console->writeErr("Released lease %d.\n", $id);
}
}
}
}