Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / drydock / management / DrydockManagementReleaseResourceWorkflow.php
blob01060a5325cd2ec695229edf122198679aa27901
1 <?php
3 final class DrydockManagementReleaseResourceWorkflow
4 extends DrydockManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('release-resource')
9 ->setSynopsis(pht('Release a resource.'))
10 ->setArguments(
11 array(
12 array(
13 'name' => 'id',
14 'param' => 'id',
15 'repeat' => true,
16 'help' => pht('Resource ID to release.'),
18 ));
21 public function execute(PhutilArgumentParser $args) {
22 $ids = $args->getArg('id');
23 if (!$ids) {
24 throw new PhutilArgumentUsageException(
25 pht(
26 'Specify one or more resource IDs to release with "%s".',
27 '--id'));
30 $viewer = $this->getViewer();
31 $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
33 $resources = id(new DrydockResourceQuery())
34 ->setViewer($viewer)
35 ->withIDs($ids)
36 ->execute();
38 PhabricatorWorker::setRunAllTasksInProcess(true);
39 foreach ($ids as $id) {
40 $resource = idx($resources, $id);
42 if (!$resource) {
43 echo tsprintf(
44 "%s\n",
45 pht('Resource "%s" does not exist.', $id));
46 continue;
49 if (!$resource->canRelease()) {
50 echo tsprintf(
51 "%s\n",
52 pht('Resource "%s" is not releasable.', $id));
53 continue;
56 $command = DrydockCommand::initializeNewCommand($viewer)
57 ->setTargetPHID($resource->getPHID())
58 ->setAuthorPHID($drydock_phid)
59 ->setCommand(DrydockCommand::COMMAND_RELEASE)
60 ->save();
62 $resource->scheduleUpdate();
64 echo tsprintf(
65 "%s\n",
66 pht('Scheduled release of resource "%s".', $id));