Differential D7898 Diff 17879 src/applications/harbormaster/controller/HarbormasterBuildActionController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/controller/HarbormasterBuildActionController.php
<?php | <?php | ||||
final class HarbormasterBuildActionController | final class HarbormasterBuildActionController | ||||
extends HarbormasterController { | extends HarbormasterController { | ||||
private $id; | private $id; | ||||
private $action; | private $action; | ||||
private $via; | |||||
public function willProcessRequest(array $data) { | public function willProcessRequest(array $data) { | ||||
$this->id = $data['id']; | $this->id = $data['id']; | ||||
$this->action = $data['action']; | $this->action = $data['action']; | ||||
$this->via = idx($data, 'via'); | |||||
} | } | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$viewer = $request->getUser(); | $viewer = $request->getUser(); | ||||
$command = $this->action; | $command = $this->action; | ||||
$build = id(new HarbormasterBuildQuery()) | $build = id(new HarbormasterBuildQuery()) | ||||
Show All 13 Lines | switch ($command) { | ||||
break; | break; | ||||
case HarbormasterBuildCommand::COMMAND_RESUME: | case HarbormasterBuildCommand::COMMAND_RESUME: | ||||
$can_issue = $build->canResumeBuild(); | $can_issue = $build->canResumeBuild(); | ||||
break; | break; | ||||
default: | default: | ||||
return new Aphront400Response(); | return new Aphront400Response(); | ||||
} | } | ||||
$build_uri = $this->getApplicationURI('/build/'.$build->getID().'/'); | switch ($this->via) { | ||||
case 'buildable': | |||||
$return_uri = $build->getBuildable()->getMonogram(); | |||||
break; | |||||
default: | |||||
$return_uri = $this->getApplicationURI('/build/'.$build->getID().'/'); | |||||
break; | |||||
} | |||||
if ($request->isDialogFormPost() && $can_issue) { | if ($request->isDialogFormPost() && $can_issue) { | ||||
// Issue the new build command. | // Issue the new build command. | ||||
id(new HarbormasterBuildCommand()) | id(new HarbormasterBuildCommand()) | ||||
->setAuthorPHID($viewer->getPHID()) | ->setAuthorPHID($viewer->getPHID()) | ||||
->setTargetPHID($build->getPHID()) | ->setTargetPHID($build->getPHID()) | ||||
->setCommand($command) | ->setCommand($command) | ||||
->save(); | ->save(); | ||||
// Schedule a build update. We may already have stuff in queue (in which | // Schedule a build update. We may already have stuff in queue (in which | ||||
// case this will just no-op), but we might also be dealing with a | // case this will just no-op), but we might also be dealing with a | ||||
// stopped build, which won't restart unless we deal with this. | // stopped build, which won't restart unless we deal with this. | ||||
PhabricatorWorker::scheduleTask( | PhabricatorWorker::scheduleTask( | ||||
'HarbormasterBuildWorker', | 'HarbormasterBuildWorker', | ||||
array( | array( | ||||
'buildID' => $build->getID() | 'buildID' => $build->getID() | ||||
)); | )); | ||||
return id(new AphrontRedirectResponse())->setURI($build_uri); | return id(new AphrontRedirectResponse())->setURI($return_uri); | ||||
} | } | ||||
switch ($command) { | switch ($command) { | ||||
case HarbormasterBuildCommand::COMMAND_RESTART: | case HarbormasterBuildCommand::COMMAND_RESTART: | ||||
if ($can_issue) { | if ($can_issue) { | ||||
$title = pht('Really restart build?'); | $title = pht('Really restart build?'); | ||||
$body = pht( | $body = pht( | ||||
'Progress on this build will be discarded and the build will '. | 'Progress on this build will be discarded and the build will '. | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | switch ($command) { | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setTitle($title) | ->setTitle($title) | ||||
->appendChild($body) | ->appendChild($body) | ||||
->addCancelButton($build_uri); | ->addCancelButton($return_uri); | ||||
if ($can_issue) { | if ($can_issue) { | ||||
$dialog->addSubmitButton($submit); | $dialog->addSubmitButton($submit); | ||||
} | } | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
} | } | ||||
} | } |