DNEnvironment::CurrentBuild PHP Method

CurrentBuild() public method

Dear people of the future: If you are looking to optimize this, simply create a CurrentBuildSHA(), which can be a lot faster. I presume you came here because of the Project display template, which only needs a SHA.
public CurrentBuild ( ) : false | DNDeployment
return false | DNDeployment
    public function CurrentBuild()
    {
        // The DeployHistory function is far too slow to use for this
        /** @var DNDeployment $deploy */
        $deploy = DNDeployment::get()->filter(['EnvironmentID' => $this->ID, 'State' => DNDeployment::STATE_COMPLETED])->sort('LastEdited DESC')->first();
        if (!$deploy || !$deploy->SHA) {
            return false;
        }
        $repo = $this->Project()->getRepository();
        if (!$repo) {
            return $deploy;
        }
        try {
            $commit = $this->getCommit($deploy->SHA);
            if ($commit) {
                $deploy->Message = Convert::raw2xml($this->getCommitMessage($commit));
                $deploy->Committer = Convert::raw2xml($commit->getCommitterName());
                $deploy->CommitDate = $commit->getCommitterDate()->Format('d/m/Y g:ia');
                $deploy->Author = Convert::raw2xml($commit->getAuthorName());
                $deploy->AuthorDate = $commit->getAuthorDate()->Format('d/m/Y g:ia');
            }
            // We can't find this SHA, so we ignore adding a commit message to the deployment
        } catch (Exception $ex) {
        }
        return $deploy;
    }

Usage Example

 /**
  * @param \SS_HTTPRequest $request
  * @return \SS_HTTPResponse
  */
 public function redeploy(\SS_HTTPRequest $request)
 {
     $currentBuild = $this->environment->CurrentBuild();
     if (!$currentBuild || !$currentBuild->exists()) {
         return $this->redirect(Controller::join_links($this->environment->Link(\EnvironmentOverview::ACTION_OVERVIEW), 'deployment', 'new'));
     }
     $strategy = $this->environment->Backend()->planDeploy($this->environment, ['sha' => $currentBuild->SHA, 'ref_type' => \GitDispatcher::REF_TYPE_PREVIOUS, 'ref_name' => $currentBuild->RefName]);
     $deployment = $strategy->createDeployment();
     return $this->redirect($deployment->Link());
 }
All Usage Examples Of DNEnvironment::CurrentBuild