mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 10:52:41 +01:00
e397103bf2
Summary: Ref T2015. Not directly related to Drydock, but I've wanted to do this for a bit. Introduce a common base class for all the workflows in the scripts in `bin/*`. This slightly reduces code duplication by moving `isExecutable()` to the base, but also provides `getViewer()`. This is a little nicer than `PhabricatorUser::getOmnipotentUser()` and gives us a layer of indirection if we ever want to introduce more general viewer mechanisms in scripts. Test Plan: Lint; ran some of the scripts. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7838
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
final class DrydockManagementCloseWorkflow
|
|
extends DrydockManagementWorkflow {
|
|
|
|
public function didConstruct() {
|
|
$this
|
|
->setName('close')
|
|
->setSynopsis('Close a resource.')
|
|
->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 resource IDs to close.");
|
|
}
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$resources = id(new DrydockResourceQuery())
|
|
->setViewer($viewer)
|
|
->withIDs($ids)
|
|
->execute();
|
|
|
|
foreach ($ids as $id) {
|
|
$resource = idx($resources, $id);
|
|
if (!$resource) {
|
|
$console->writeErr("Resource %d does not exist!\n", $id);
|
|
} else if ($resource->getStatus() != DrydockResourceStatus::STATUS_OPEN) {
|
|
$console->writeErr("Resource %d is not 'open'!\n", $id);
|
|
} else {
|
|
$resource->closeResource();
|
|
$console->writeErr("Closed resource %d.\n", $id);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|