/**
* Deployment form submission handler.
*
* Initiate a DNDeployment record and redirect to it for status polling
*
* @return \SS_HTTPResponse
*/
public function doDeploy($data, $form)
{
if (in_array($data['SelectRelease'], array('Tag', 'Branch', 'Redeploy', 'SHA'))) {
$buildName = $data[$data['SelectRelease']];
} else {
throw new LogicException("Bad release selection method " . Convert::raw2xml($data['SelectRelease']));
}
if (!preg_match('/^[a-f0-9]{40}$/', $buildName)) {
throw new LogicException("Bad commit SHA");
}
// Performs canView permission check by limiting visible projects
$project = $this->getCurrentProject();
if (!$project) {
return new SS_HTTPResponse("Project '" . Convert::raw2xml($this->getRequest()->latestParam('Project')) . "' not found.", 404);
}
// Performs canView permission check by limiting visible projects
$environment = $this->getCurrentEnvironment($project);
if (!$environment) {
return new SS_HTTPResponse("Environment '" . Convert::raw2xml($this->getRequest()->latestParam('Environment')) . "' not found.", 404);
}
$sha = $project->DNBuildList()->byName($buildName);
$deployment = new DNDeployment();
$deployment->EnvironmentID = $environment->ID;
$deployment->SHA = $sha->FullName();
$deployment->write();
$deployment->start();
$this->redirect($deployment->Link());
}