Exemplo n.º 1
0
 /**
  * Step 2 of the deployment process: Synchronize
  * Synchronize the exported source code from snv with the code located in the target directory
  * @param SetLog 	$setLog		Custom logging object 
  * @param array 	$options	Various options used for configuring the step 
  */
 private function _synchronize($options = array())
 {
     // Check input parameters
     if (!$this->isInitialized()) {
         $this->_stepLog->error(sprintf(__('Missing working data', true)));
     }
     // Load project configuration
     self::_loadConfig();
     // Define step options
     $default_options = array('simulation' => true, 'runBeforeScript' => false, 'backup' => false, 'comment' => 'none');
     $options = array_merge($default_options, $options);
     $projectTmpDir = F_DEPLOYTMPDIR . $this->_project['Project']['name'] . DS;
     // Synchronize target files
     // Create target dir (if required)
     if (!is_dir($this->_project['Project']['prd_path'])) {
         // Create tmpDir folder inside Fredistrano
         $log = ShellAction::createDirectory($this->_project['Project']['prd_path'], Configure::read('FileSystem.permissions.directories'), array('stepLog' => $this->_stepLog));
     }
     // Run initialization script
     if (!$options['simulation']) {
         // Create a log entry for the pending deployement
         $actionLog = $this->_stepLog->addNewAction('create', 'Directory: ' . $this->_project['Project']['prd_path'], 'FS');
         $data = array('DeploymentLog' => array('project_id' => $this->_project['Project']['id'], 'user_id' => $this->_context['user'], 'uuid' => $this->_context['uuid'], 'title' => date("D, M jS Y, H:i") . ' - ' . $this->_project['Project']['name'], 'comment' => $options['comment'], 'archive' => 0));
         if (!$this->DeploymentLog->save($data)) {
             $actionLog->error(__('Unable to save deployment log', true));
         }
         $actionLog->end();
         if ($options['runBeforeScript']) {
             $scriptPath = null;
             if (isset($this->_config->scripts['before']) && !empty($this->_config->scripts['before'])) {
                 $scriptPath = $this->_config->scripts['before'];
             }
             $log = ShellAction::runScript('before', $projectTmpDir, $scriptPath, $options);
         }
         // Backup (if required)
         if ($options['backup'] === true) {
             $options['exclude'] = null;
             $source = $this->_project['Project']['prd_path'];
             $target = F_DEPLOYBACKUPDIR . $this->_project['Project']['name'] . DS;
             $log = ShellAction::synchronizeContent($source, $target, $options);
         }
     }
     // Generate exclusion file
     $exclude = $this->_config->exclude;
     $excludeString = "";
     for ($i = 0; $i < sizeof($exclude); $i++) {
         $excludeString .= "- " . $exclude[$i] . "\n";
     }
     $excludeString .= "- deploy.php\n";
     $excludeString .= "- .fredistrano\n";
     $excludeString .= "- **.dev.**\n";
     $excludeString .= "- **.svn**\n";
     $excludeFileName = $projectTmpDir . "exclude_file.txt";
     $handle = fopen($excludeFileName, "w");
     fwrite($handle, $excludeString);
     fclose($handle);
     // Run Rsync
     $target = $this->_project['Project']['prd_path'];
     $options['exclude'] = $excludeFileName;
     $log = ShellAction::synchronizeContent($projectTmpDir . "tmpDir" . DS, $target, $options);
     // Create file list
     $output = $log->getResult();
     PhpAction::createFilesListToChmod($output, $projectTmpDir, $target, array('stepLog' => $this->_stepLog));
     return $output;
 }