Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/management/HarbormasterManagementUpdateWorkflow.php
12256 views
1
<?php
2
3
final class HarbormasterManagementUpdateWorkflow
4
extends HarbormasterManagementWorkflow {
5
6
protected function didConstruct() {
7
$this
8
->setName('update')
9
->setExamples('**update** [__options__] __buildable__')
10
->setSynopsis(pht('Explicitly update the builds for __buildable__.'))
11
->setArguments(
12
array(
13
array(
14
'name' => 'build',
15
'param' => 'id',
16
'help' => pht('Update only this build.'),
17
),
18
array(
19
'name' => 'force',
20
'help' => pht(
21
'Force the buildable to update even if no build status '.
22
'changes occur during normal update.'),
23
),
24
array(
25
'name' => 'background',
26
'help' => pht(
27
'If updating generates tasks, queue them for the daemons '.
28
'instead of executing them in this process.'),
29
),
30
array(
31
'name' => 'buildable',
32
'wildcard' => true,
33
),
34
));
35
}
36
37
public function execute(PhutilArgumentParser $args) {
38
$viewer = $this->getViewer();
39
40
$force_update = $args->getArg('force');
41
42
$names = $args->getArg('buildable');
43
if (count($names) != 1) {
44
throw new PhutilArgumentUsageException(
45
pht('Specify exactly one buildable, by object name.'));
46
}
47
48
$buildable = id(new PhabricatorObjectQuery())
49
->setViewer($viewer)
50
->withNames($names)
51
->executeOne();
52
53
if (!$buildable) {
54
throw new PhutilArgumentUsageException(
55
pht('No such buildable "%s"!', head($names)));
56
}
57
58
if (!($buildable instanceof HarbormasterBuildable)) {
59
throw new PhutilArgumentUsageException(
60
pht('Object "%s" is not a Harbormaster Buildable!', head($names)));
61
}
62
63
// Reload the buildable directly to get builds.
64
$buildable = id(new HarbormasterBuildableQuery())
65
->setViewer($viewer)
66
->withIDs(array($buildable->getID()))
67
->needBuilds(true)
68
->executeOne();
69
70
$builds = $buildable->getBuilds();
71
$builds = mpull($builds, null, 'getID');
72
73
$build_id = $args->getArg('build');
74
if ($build_id) {
75
$builds = array_select_keys($builds, array($build_id));
76
if (!$builds) {
77
throw new PhutilArgumentUsageException(
78
pht(
79
'The specified buildable does not have a build with ID "%s".',
80
$build_id));
81
}
82
}
83
84
$console = PhutilConsole::getConsole();
85
86
if (!$args->getArg('background')) {
87
PhabricatorWorker::setRunAllTasksInProcess(true);
88
}
89
90
foreach ($builds as $build) {
91
$console->writeOut(
92
"%s\n",
93
pht(
94
'Updating build %d of buildable %s...',
95
$build->getID(),
96
$buildable->getMonogram()));
97
98
$engine = id(new HarbormasterBuildEngine())
99
->setViewer($viewer)
100
->setBuild($build);
101
102
if ($force_update) {
103
$engine->setForceBuildableUpdate(true);
104
}
105
106
$engine->continueBuild();
107
}
108
109
$console->writeOut("%s\n", pht('Done.'));
110
111
return 0;
112
}
113
114
}
115
116