Path: blob/master/src/applications/harbormaster/management/HarbormasterManagementUpdateWorkflow.php
12256 views
<?php12final class HarbormasterManagementUpdateWorkflow3extends HarbormasterManagementWorkflow {45protected function didConstruct() {6$this7->setName('update')8->setExamples('**update** [__options__] __buildable__')9->setSynopsis(pht('Explicitly update the builds for __buildable__.'))10->setArguments(11array(12array(13'name' => 'build',14'param' => 'id',15'help' => pht('Update only this build.'),16),17array(18'name' => 'force',19'help' => pht(20'Force the buildable to update even if no build status '.21'changes occur during normal update.'),22),23array(24'name' => 'background',25'help' => pht(26'If updating generates tasks, queue them for the daemons '.27'instead of executing them in this process.'),28),29array(30'name' => 'buildable',31'wildcard' => true,32),33));34}3536public function execute(PhutilArgumentParser $args) {37$viewer = $this->getViewer();3839$force_update = $args->getArg('force');4041$names = $args->getArg('buildable');42if (count($names) != 1) {43throw new PhutilArgumentUsageException(44pht('Specify exactly one buildable, by object name.'));45}4647$buildable = id(new PhabricatorObjectQuery())48->setViewer($viewer)49->withNames($names)50->executeOne();5152if (!$buildable) {53throw new PhutilArgumentUsageException(54pht('No such buildable "%s"!', head($names)));55}5657if (!($buildable instanceof HarbormasterBuildable)) {58throw new PhutilArgumentUsageException(59pht('Object "%s" is not a Harbormaster Buildable!', head($names)));60}6162// Reload the buildable directly to get builds.63$buildable = id(new HarbormasterBuildableQuery())64->setViewer($viewer)65->withIDs(array($buildable->getID()))66->needBuilds(true)67->executeOne();6869$builds = $buildable->getBuilds();70$builds = mpull($builds, null, 'getID');7172$build_id = $args->getArg('build');73if ($build_id) {74$builds = array_select_keys($builds, array($build_id));75if (!$builds) {76throw new PhutilArgumentUsageException(77pht(78'The specified buildable does not have a build with ID "%s".',79$build_id));80}81}8283$console = PhutilConsole::getConsole();8485if (!$args->getArg('background')) {86PhabricatorWorker::setRunAllTasksInProcess(true);87}8889foreach ($builds as $build) {90$console->writeOut(91"%s\n",92pht(93'Updating build %d of buildable %s...',94$build->getID(),95$buildable->getMonogram()));9697$engine = id(new HarbormasterBuildEngine())98->setViewer($viewer)99->setBuild($build);100101if ($force_update) {102$engine->setForceBuildableUpdate(true);103}104105$engine->continueBuild();106}107108$console->writeOut("%s\n", pht('Done.'));109110return 0;111}112113}114115116