/** * Construct the deployment form * * @return Form */ public function getDeployForm($request = null) { // Performs canView permission check by limiting visible projects $project = $this->getCurrentProject(); if (!$project) { return $this->project404Response(); } // Performs canView permission check by limiting visible projects $environment = $this->getCurrentEnvironment($project); if (!$environment) { return $this->environment404Response(); } if (!$environment->canDeploy()) { return new SS_HTTPResponse("Not allowed to deploy", 401); } // Generate the form $form = new DeployForm($this, 'DeployForm', $environment, $project); // If this is an ajax request we don't want to submit the form - we just want to retrieve the markup. if ($request && !$request->requestVar('action_showDeploySummary') && $this->getRequest()->isAjax() && $this->getRequest()->isGET()) { // We can just use the URL we're accessing $form->setFormAction($this->getRequest()->getURL()); $body = json_encode(array('Content' => $form->forAjaxTemplate()->forTemplate())); $this->getResponse()->addHeader('Content-Type', 'application/json'); $this->getResponse()->setBody($body); return $body; } $form->setFormAction($this->getRequest()->getURL() . '/DeployForm'); return $form; }
/** * Deployment form submission handler. * * Initiate a DNDeployment record and redirect to it for status polling * * @param array $data * @param DeployForm $form * @return \SS_HTTPResponse */ public function doDeploy($data, $form) { $buildName = $form->getSelectedBuild($data); // 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); } // Initiate the deployment // The extension point should pass in: Project, Environment, SelectRelease, buildName $this->extend('doDeploy', $project, $environment, $buildName, $data); $sha = $project->DNBuildList()->byName($buildName); $deployment = DNDeployment::create(); $deployment->EnvironmentID = $environment->ID; $deployment->SHA = $sha->FullName(); $deployment->write(); $deployment->start(); return $this->redirect($deployment->Link()); }