Path: blob/master/src/applications/harbormaster/controller/HarbormasterPlanRunController.php
12256 views
<?php12final class HarbormasterPlanRunController extends HarbormasterPlanController {34public function handleRequest(AphrontRequest $request) {5$viewer = $this->getViewer();6$plan_id = $request->getURIData('id');78$plan = id(new HarbormasterBuildPlanQuery())9->setViewer($viewer)10->withIDs(array($plan_id))11->executeOne();12if (!$plan) {13return new Aphront404Response();14}1516$plan->assertHasRunCapability($viewer);1718$cancel_uri = $this->getApplicationURI("plan/{$plan_id}/");1920if (!$plan->canRunManually()) {21return $this->newDialog()22->setTitle(pht('Can Not Run Plan'))23->appendParagraph(pht('This plan can not be run manually.'))24->addCancelButton($cancel_uri);25}2627$e_name = true;28$v_name = null;2930$errors = array();31if ($request->isFormPost()) {32$buildable = HarbormasterBuildable::initializeNewBuildable($viewer)33->setIsManualBuildable(true);3435$v_name = $request->getStr('buildablePHID');3637if ($v_name) {38$object = id(new PhabricatorObjectQuery())39->setViewer($viewer)40->withNames(array($v_name))41->executeOne();4243if ($object instanceof HarbormasterBuildableInterface) {44$buildable45->setBuildablePHID($object->getHarbormasterBuildablePHID())46->setContainerPHID($object->getHarbormasterContainerPHID());47} else {48$e_name = pht('Invalid');49$errors[] = pht('Enter the name of a revision or commit.');50}51} else {52$e_name = pht('Required');53$errors[] = pht('You must choose a revision or commit to build.');54}5556if (!$errors) {57$buildable->save();5859$buildable->sendMessage(60$viewer,61HarbormasterMessageType::BUILDABLE_BUILD,62false);6364$buildable->applyPlan($plan, array(), $viewer->getPHID());6566$buildable_uri = '/B'.$buildable->getID();67return id(new AphrontRedirectResponse())->setURI($buildable_uri);68}69}7071if ($errors) {72$errors = id(new PHUIInfoView())->setErrors($errors);73}7475$title = pht('Run Build Plan Manually');76$save_button = pht('Run Plan Manually');7778$form = id(new PHUIFormLayoutView())79->setUser($viewer)80->appendRemarkupInstructions(81pht(82"Enter the name of a commit or revision to run this plan on (for ".83"example, `rX123456` or `D123`).\n\n".84"For more detailed output, you can also run manual builds from ".85"the command line:\n\n".86" $ ./bin/harbormaster build <object> --plan %s",87$plan->getID()))88->appendChild(89id(new AphrontFormTextControl())90->setLabel(pht('Buildable Name'))91->setName('buildablePHID')92->setError($e_name)93->setValue($v_name));9495return $this->newDialog()96->setWidth(AphrontDialogView::WIDTH_FULL)97->setTitle($title)98->appendChild($form)99->addCancelButton($cancel_uri)100->addSubmitButton($save_button);101}102103}104105106