Path: blob/master/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php
12256 views
<?php12final class HarbormasterManagementBuildWorkflow3extends HarbormasterManagementWorkflow {45protected function didConstruct() {6$this7->setName('build')8->setExamples('**build** [__options__] __buildable__ --plan __id__')9->setSynopsis(pht('Run plan __id__ on __buildable__.'))10->setArguments(11array(12array(13'name' => 'plan',14'param' => 'id',15'help' => pht('ID of build plan to run.'),16),17array(18'name' => 'background',19'help' => pht(20'Submit builds into the build queue normally instead of '.21'running them in the foreground.'),22),23array(24'name' => 'buildable',25'wildcard' => true,26),27));28}2930public function execute(PhutilArgumentParser $args) {31$viewer = $this->getViewer();3233$names = $args->getArg('buildable');34if (count($names) != 1) {35throw new PhutilArgumentUsageException(36pht('Specify exactly one buildable object, by object name.'));37}3839$name = head($names);4041$buildable = id(new PhabricatorObjectQuery())42->setViewer($viewer)43->withNames($names)44->executeOne();45if (!$buildable) {46throw new PhutilArgumentUsageException(47pht('No such buildable "%s"!', $name));48}4950if (!($buildable instanceof HarbormasterBuildableInterface)) {51throw new PhutilArgumentUsageException(52pht('Object "%s" is not a buildable!', $name));53}5455$plan_id = $args->getArg('plan');56if (!$plan_id) {57throw new PhutilArgumentUsageException(58pht(59'Use %s to specify a build plan to run.',60'--plan'));61}6263$plan = id(new HarbormasterBuildPlanQuery())64->setViewer($viewer)65->withIDs(array($plan_id))66->executeOne();67if (!$plan) {68throw new PhutilArgumentUsageException(69pht('Build plan "%s" does not exist.', $plan_id));70}7172if (!$plan->canRunManually()) {73throw new PhutilArgumentUsageException(74pht('This build plan can not be run manually.'));75}7677$console = PhutilConsole::getConsole();7879$buildable = HarbormasterBuildable::initializeNewBuildable($viewer)80->setIsManualBuildable(true)81->setBuildablePHID($buildable->getHarbormasterBuildablePHID())82->setContainerPHID($buildable->getHarbormasterContainerPHID())83->save();8485$buildable->sendMessage(86$viewer,87HarbormasterMessageType::BUILDABLE_BUILD,88false);8990$console->writeOut(91"%s\n",92pht(93'Applying plan %s to new buildable %s...',94$plan->getID(),95'B'.$buildable->getID()));9697$console->writeOut(98"\n %s\n\n",99PhabricatorEnv::getProductionURI('/B'.$buildable->getID()));100101if (!$args->getArg('background')) {102PhabricatorWorker::setRunAllTasksInProcess(true);103}104105if ($viewer->isOmnipotent()) {106$initiator = id(new PhabricatorHarbormasterApplication())->getPHID();107} else {108$initiator = $viewer->getPHID();109}110$buildable->applyPlan($plan, array(), $initiator);111112$console->writeOut("%s\n", pht('Done.'));113114return 0;115}116117}118119120