Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / harbormaster / management / HarbormasterManagementRestartWorkflow.php
blob568bef46acec41a0c0a6c79d91130d43b3665748
1 <?php
3 final class HarbormasterManagementRestartWorkflow
4 extends HarbormasterManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('restart')
9 ->setExamples(
10 "**restart** --active\n".
11 '**restart** --id id')
12 ->setSynopsis(pht('Restart Harbormaster builds.'))
13 ->setArguments(
14 array(
15 array(
16 'name' => 'id',
17 'param' => 'id',
18 'repeat' => true,
19 'help' => pht('Select one or more builds by ID.'),
21 array(
22 'name' => 'active',
23 'help' => pht('Select all active builds.'),
25 ));
28 public function execute(PhutilArgumentParser $args) {
29 $viewer = $this->getViewer();
30 $ids = $args->getArg('id');
31 $active = $args->getArg('active');
33 if (!$ids && !$active) {
34 throw new PhutilArgumentUsageException(
35 pht('Use "--id" or "--active" to select builds.'));
36 } if ($ids && $active) {
37 throw new PhutilArgumentUsageException(
38 pht('Use one of "--id" or "--active" to select builds, but not both.'));
41 $query = id(new HarbormasterBuildQuery())
42 ->setViewer($viewer);
43 if ($ids) {
44 $query->withIDs($ids);
45 } else {
46 $query->withBuildStatuses(
47 HarbormasterBuildStatus::getActiveStatusConstants());
49 $builds = $query->execute();
51 $count = count($builds);
52 if (!$count) {
53 $this->logSkip(
54 pht('SKIP'),
55 pht('No builds to restart.'));
56 return 0;
59 $prompt = pht('Restart %s build(s)?', new PhutilNumber($count));
60 if (!phutil_console_confirm($prompt)) {
61 throw new ArcanistUserAbortException();
64 $message = new HarbormasterBuildMessageRestartTransaction();
66 foreach ($builds as $build) {
67 $this->logInfo(
68 pht('RESTARTING'),
69 pht('Build %d: %s', $build->getID(), $build->getName()));
71 try {
72 $message->assertCanSendMessage($viewer, $build);
73 } catch (HarbormasterMessageException $ex) {
74 $this->logWarn(
75 pht('INVALID'),
76 $ex->newDisplayString());
79 $build->sendMessage(
80 $viewer,
81 $message->getHarbormasterBuildMessageType());
83 $this->logOkay(
84 pht('QUEUED'),
85 pht('Sent a restart message to build.'));
88 return 0;