예제 #1
0
 /**
  * Implement this by setting $obj values (e.g. $obj->setId($row->Id) from a DB row
  * @param GD_Model_Deployment $obj
  * @param Zend_Db_Table_Row_Abstract $row
  */
 protected function populateObjectFromRow(&$obj, Zend_Db_Table_Row_Abstract $row)
 {
     $obj->setId($row->id)->setUsersId($row->users_id)->setProjectsId($row->projects_id)->setWhen($row->when)->setServersId($row->servers_id)->setFromRevision($row->from_revision)->setToRevision($row->to_revision)->setComment($row->comment)->setDeploymentStatusesId($row->deployment_statuses_id);
     $u_map = new GD_Model_UsersMapper();
     $user = new GD_Model_User();
     $u_map->populateObjectFromRow($user, $row->findParentRow('GD_Model_DbTable_Users'));
     $obj->setUser($user);
     $p_map = new GD_Model_ProjectsMapper();
     $project = new GD_Model_Project();
     $p_map->populateObjectFromRow($project, $row->findParentRow('GD_Model_DbTable_Projects'));
     $obj->setProject($project);
     $s_map = new GD_Model_ServersMapper();
     $server = new GD_Model_Server();
     $s_map->populateObjectFromRow($server, $row->findParentRow('GD_Model_DbTable_Servers'));
     $obj->setServer($server);
     $ds_map = new GD_Model_DeploymentStatusesMapper();
     $deployment_status = new GD_Model_DeploymentStatus();
     $ds_map->populateObjectFromRow($deployment_status, $row->findParentRow('GD_Model_DbTable_DeploymentStatuses'));
     $obj->setDeploymentStatus($deployment_status);
 }
예제 #2
0
 public function testDeploymentStatusGetAndSet()
 {
     $test = new GD_Model_DeploymentStatus();
     $obj = new GD_Model_Deployment();
     $obj->setDeploymentStatus($test);
     $this->assertSame($test, $obj->getDeploymentStatus());
 }
예제 #3
0
 public function indexAction()
 {
     $this->view->headTitle('New Deployment');
     $this->view->headScript()->appendFile($this->getFrontController()->getBaseUrl() . "/js/pages/deploy_setup.js");
     $this->view->headLink()->appendStylesheet("/css/template/form.css");
     $this->view->headLink()->appendStylesheet("/css/pages/deploy.css");
     $projects = new GD_Model_ProjectsMapper();
     $project_slug = $this->_getParam("project");
     if ($project_slug != "") {
         $project = $projects->getProjectBySlug($project_slug);
     }
     if (is_null($project)) {
         throw new GD_Exception("Project '{$project_slug}' was not set up.");
     }
     $this->view->project = $project;
     $form = new GDApp_Form_DeploymentSetup($project->getId());
     $this->view->form = $form;
     $deployments = new GD_Model_DeploymentsMapper();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getParams())) {
             $user = GD_Auth_Database::GetLoggedInUser();
             $server_id = $this->_request->getParam('serverId', false);
             $last_deployment = $deployments->getLastSuccessfulDeployment($project->getId(), $server_id);
             if (!is_null($last_deployment)) {
                 $from_rev = $last_deployment->getToRevision();
             } else {
                 $from_rev = "";
             }
             $git = GD_Git::FromProject($project);
             $git->gitPull();
             $input_to_rev = $this->_request->getParam('toRevision', false);
             $comment = $this->_request->getParam('comment', '');
             try {
                 $to_rev = $git->getFullHash($input_to_rev);
                 $deployment = new GD_Model_Deployment();
                 $deployment->setUsersId($user->getId())->setProjectsId($project->getId())->setWhen(date("Y-m-d H:i:s"))->setServersId($server_id)->setFromRevision($from_rev)->setToRevision($to_rev)->setComment($comment)->setDeploymentStatusesId(1);
                 $deployments->save($deployment);
                 // Generate the list of files to deploy and save in deployment_files table
                 try {
                     $files_changed = $git->getFilesChangedList($deployment->getFromRevision(), $deployment->getToRevision());
                 } catch (GD_Exception $ex) {
                     if ($ex->getStringCode() == GD_Git::GIT_GENERAL_NO_FILES_CHANGED) {
                         $files_changed = array();
                     } else {
                         throw $ex;
                     }
                 }
                 $deployment_files = new GD_Model_DeploymentFilesMapper();
                 $deployment_file_statuses = new GD_Model_DeploymentFileStatusesMapper();
                 $deployment_file_actions = new GD_Model_DeploymentFileActionsMapper();
                 foreach ($files_changed as $fc) {
                     $deployment_file = new GD_Model_DeploymentFile();
                     $deployment_file->setDeploymentsId($deployment->getId());
                     $deployment_file->setDeploymentFileActionsId($deployment_file_actions->getDeploymentFileActionByGitStatus($fc['action'])->getId());
                     $deployment_file->setDeploymentFileStatusesId($deployment_file_statuses->getDeploymentFileStatusByCode('NEW')->getId());
                     $deployment_file->setDetails($fc['file']);
                     $deployment_files->save($deployment_file);
                 }
                 // Add any additional configuration files
                 $config_servers_map = new GD_Model_ConfigsServersMapper();
                 $configs = $config_servers_map->getAllConfigsForServer($server_id);
                 foreach ($configs as $config) {
                     $c = $config->getConfig();
                     $cfile = "!CFG!{$c->getId()}!{$c->getFilename()}";
                     $deployment_file = new GD_Model_DeploymentFile();
                     $deployment_file->setDeploymentsId($deployment->getId());
                     $deployment_file->setDeploymentFileActionsId($deployment_file_actions->getDeploymentFileActionByGitStatus('M')->getId());
                     $deployment_file->setDeploymentFileStatusesId($deployment_file_statuses->getDeploymentFileStatusByCode('NEW')->getId());
                     $deployment_file->setDetails($cfile);
                     $deployment_files->save($deployment_file);
                 }
                 // Forward to either run or preview page...
                 if ($this->_request->getParam('submitRun_x') > 0) {
                     // go to run
                     $this->_redirect($this->getFrontController()->getBaseUrl() . "/project/" . $this->_getParam("project") . "/deploy/run/" . $deployment->getId());
                 } else {
                     if ($this->_request->getParam('submitPreview_x') > 0) {
                         // go to preview
                         $this->_redirect($this->getFrontController()->getBaseUrl() . "/project/" . $this->_getParam("project") . "/deploy/preview/" . $deployment->getId());
                     }
                 }
             } catch (GD_Exception $ex) {
                 if ($ex->getStringCode() === GD_Git::GIT_GENERAL_EMPTY_REF) {
                     $form->toRevision->addError("Empty ref: " . $ex->getMessage());
                 } else {
                     if ($ex->getStringCode() === GD_Git::GIT_GENERAL_INVALID_REF) {
                         $form->toRevision->addError("This revision could not be found in this project. Please check it.");
                         $form->addError("error");
                     } else {
                         throw $ex;
                     }
                 }
             }
         }
     } else {
         $git = GD_Git::FromProject($project);
         try {
             $git->checkValidRepository();
         } catch (GD_Exception $ex) {
             if ($ex->getStringCode() == GD_Git::GIT_STATUS_ERROR_NOT_A_REPOSITORY || $ex->getStringCode() == GD_Git::GIT_STATUS_ERROR_DIFFERENT_REPOSITORY) {
                 $return_url = base64_encode($this->_request->getRequestUri());
                 $this->_redirect($this->getFrontController()->getBaseUrl() . "/error/reclone?project=" . $this->_getParam("project") . "&return=" . $return_url);
             } else {
                 throw $ex;
             }
         }
         $data = array();
         if (count($data) > 0) {
             $form->populate($data);
         }
     }
 }