Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / harbormaster / management / HarbormasterManagementUpdateWorkflow.php
blob05d1e5a6a245fc93450b089e0949e0b28d473f22
1 <?php
3 final class HarbormasterManagementUpdateWorkflow
4 extends HarbormasterManagementWorkflow {
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.'),
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.'),
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.'),
30 array(
31 'name' => 'buildable',
32 'wildcard' => true,
34 ));
37 public function execute(PhutilArgumentParser $args) {
38 $viewer = $this->getViewer();
40 $force_update = $args->getArg('force');
42 $names = $args->getArg('buildable');
43 if (count($names) != 1) {
44 throw new PhutilArgumentUsageException(
45 pht('Specify exactly one buildable, by object name.'));
48 $buildable = id(new PhabricatorObjectQuery())
49 ->setViewer($viewer)
50 ->withNames($names)
51 ->executeOne();
53 if (!$buildable) {
54 throw new PhutilArgumentUsageException(
55 pht('No such buildable "%s"!', head($names)));
58 if (!($buildable instanceof HarbormasterBuildable)) {
59 throw new PhutilArgumentUsageException(
60 pht('Object "%s" is not a Harbormaster Buildable!', head($names)));
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();
70 $builds = $buildable->getBuilds();
71 $builds = mpull($builds, null, 'getID');
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));
84 $console = PhutilConsole::getConsole();
86 if (!$args->getArg('background')) {
87 PhabricatorWorker::setRunAllTasksInProcess(true);
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()));
98 $engine = id(new HarbormasterBuildEngine())
99 ->setViewer($viewer)
100 ->setBuild($build);
102 if ($force_update) {
103 $engine->setForceBuildableUpdate(true);
106 $engine->continueBuild();
109 $console->writeOut("%s\n", pht('Done.'));
111 return 0;