Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/management/HarbormasterManagementRestartWorkflow.php
12256 views
1
<?php
2
3
final class HarbormasterManagementRestartWorkflow
4
extends HarbormasterManagementWorkflow {
5
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.'),
20
),
21
array(
22
'name' => 'active',
23
'help' => pht('Select all active builds.'),
24
),
25
));
26
}
27
28
public function execute(PhutilArgumentParser $args) {
29
$viewer = $this->getViewer();
30
$ids = $args->getArg('id');
31
$active = $args->getArg('active');
32
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.'));
39
}
40
41
$query = id(new HarbormasterBuildQuery())
42
->setViewer($viewer);
43
if ($ids) {
44
$query->withIDs($ids);
45
} else {
46
$query->withBuildStatuses(
47
HarbormasterBuildStatus::getActiveStatusConstants());
48
}
49
$builds = $query->execute();
50
51
$count = count($builds);
52
if (!$count) {
53
$this->logSkip(
54
pht('SKIP'),
55
pht('No builds to restart.'));
56
return 0;
57
}
58
59
$prompt = pht('Restart %s build(s)?', new PhutilNumber($count));
60
if (!phutil_console_confirm($prompt)) {
61
throw new ArcanistUserAbortException();
62
}
63
64
$message = new HarbormasterBuildMessageRestartTransaction();
65
66
foreach ($builds as $build) {
67
$this->logInfo(
68
pht('RESTARTING'),
69
pht('Build %d: %s', $build->getID(), $build->getName()));
70
71
try {
72
$message->assertCanSendMessage($viewer, $build);
73
} catch (HarbormasterMessageException $ex) {
74
$this->logWarn(
75
pht('INVALID'),
76
$ex->newDisplayString());
77
}
78
79
$build->sendMessage(
80
$viewer,
81
$message->getHarbormasterBuildMessageType());
82
83
$this->logOkay(
84
pht('QUEUED'),
85
pht('Sent a restart message to build.'));
86
}
87
88
return 0;
89
}
90
91
}
92
93