3 final class DrydockManagementReleaseResourceWorkflow
4 extends DrydockManagementWorkflow
{
6 protected function didConstruct() {
8 ->setName('release-resource')
9 ->setSynopsis(pht('Release a resource.'))
16 'help' => pht('Resource ID to release.'),
20 'help' => pht('Release all resources. Dangerous!'),
25 public function execute(PhutilArgumentParser
$args) {
26 $is_all = $args->getArg('all');
27 $ids = $args->getArg('id');
28 if (!$ids && !$is_all) {
29 throw new PhutilArgumentUsageException(
31 'Specify which resources you want to release. See "--help" for '.
35 $viewer = $this->getViewer();
36 $statuses = $this->getReleaseableResourceStatuses();
38 $query = id(new DrydockResourceQuery())
40 ->withStatuses(mpull($statuses, 'getKey'));
43 $query->withIDs($ids);
46 $resources = $query->execute();
49 $id_map = mpull($resources, null, 'getID');
51 foreach ($ids as $id) {
52 $resource = idx($resources, $id);
55 throw new PhutilArgumentUsageException(
56 pht('Resource "%s" does not exist.', $id));
60 $resources = array_select_keys($id_map, $ids);
66 pht('No resources selected for release.'));
71 $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
73 PhabricatorWorker
::setRunAllTasksInProcess(true);
75 foreach ($resources as $resource) {
76 if (!$resource->canRelease()) {
80 'Resource "%s" is not releasable.',
81 $resource->getDisplayName()));
85 $command = DrydockCommand
::initializeNewCommand($viewer)
86 ->setTargetPHID($resource->getPHID())
87 ->setAuthorPHID($drydock_phid)
88 ->setCommand(DrydockCommand
::COMMAND_RELEASE
)
91 $resource->scheduleUpdate();
96 'Scheduled release of resource "%s".',
97 $resource->getDisplayName()));
103 private function getReleaseableResourceStatuses() {
104 $statuses = DrydockResourceStatus
::getAllStatuses();
105 foreach ($statuses as $key => $status) {
106 $statuses[$key] = DrydockResourceStatus
::newStatusObject($status);
109 foreach ($statuses as $key => $status) {
110 if (!$status->canRelease()) {
111 unset($statuses[$key]);