Exemplo n.º 1
0
 public static function update($projectDir, $options = array())
 {
     $actionLog = self::initAction('update', $projectDir, 'SvnAction', $options);
     $configDirectory = '';
     if (is_null($projectDir)) {
         $actionLog->error(sprintf(__('Forbidden NULL value for input parameter [%s]', true), $projectDir));
     } else {
         if (!is_dir($projectDir)) {
             $actionLog->error(sprintf(__('Directory %s not found', true), $projectDir));
         } else {
             if (!is_dir($projectDir . DS . '.svn')) {
                 $actionLog->error(sprintf(__('Specified directory %s is not a working copy', true), $projectDir . DS . '.svn'));
             } else {
                 if (!is_writeable($projectDir)) {
                     $actionLog->error(sprintf(__('Specified directory %s is not writeable', true), $projectDir));
                 }
             }
         }
     }
     // Define step options
     $default_options = array('revision' => null, 'configDirectory' => null, 'parseResponse' => false);
     $options = array_merge($default_options, $options);
     // Execute command
     $projectDir = Utils::formatPath($projectDir);
     $revision = $options['revision'] != null ? ' -r' . $options['revision'] : '';
     $authentication = '';
     if (!is_null($options['user_svn'])) {
         $authentication .= '--username ' . $options['user_svn'];
         if (!empty($options['password_svn'])) {
             $authentication .= ' --password ' . $options['password_svn'];
         }
     }
     if (!is_null($options['configDirectory'])) {
         $configDirectory = '--config-dir ' . Utils::formatPath($options['configDirectory']);
     }
     $command = "svn update --non-interactive {$configDirectory} {$revision} {$authentication} 2>&1";
     $commandForLog = "svn update --non-interactive {$configDirectory} {$revision} XXXX 2>&1";
     ShellAction::executeCommand($command, array('directory' => $projectDir, 'actionLog' => $actionLog, 'commandForLog' => $commandForLog));
     // Parse response
     if (!(strpos($actionLog->getResult(), 'PROPFIND request failed on') === false) && $options['parseResponse']) {
         $actionLog->error(__('An error has been detected in the SVN output', true));
     }
     // End action
     $actionLog->end();
     return $actionLog;
 }
Exemplo n.º 2
0
 /**
  * Step 3 of the deployment process: Finalize
  * @param array $options	Various options used for configuring the step
  * @return string 			Shell output
  */
 private function _finalize($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('renamePrdFile' => false, 'changeFileMode' => false, 'giveWriteMode' => false, 'runAfterScript' => false);
     $options = array_merge($default_options, $options);
     $projectTmpDir = F_DEPLOYTMPDIR . $this->_project['Project']['name'] . DS;
     // Rename file type (eg. from .prd.xxx into .xxx)
     if ($options['renamePrdFile'] === true) {
         $command = "find " . Utils::formatPath($this->_project['Project']['prd_path']) . " -name '*." . Configure::read('FileSystem.renameExt') . ".*' " . "-exec /usr/bin/perl " . Utils::formatPath(F_DEPLOYDIR . 'scripts' . DS) . "renamePrdFile -vf 's/\\." . Configure::read('FileSystem.renameExt') . "\\./\\./i' {} \\;";
         $log = ShellAction::executeCommand($command, array('comment' => sprintf(__('Rename .%s files', true), Configure::read('FileSystem.renameExt')), 'directory' => F_DEPLOYDIR, 'stepLog' => $this->_stepLog));
     }
     // Change file mode
     if ($options['changeFileMode'] === true) {
         $command = "chmod -v " . Configure::read('FileSystem.permissions.files') . " \$(<" . Utils::formatPath($projectTmpDir . "files_to_chmod.txt") . ")";
         $log = ShellAction::executeCommand($command, array('comment' => sprintf(__('Changing files permissions to %s', true), Configure::read('FileSystem.permissions.files')), 'stepLog' => $this->_stepLog));
         $command = "chmod -v " . Configure::read('FileSystem.permissions.directories') . " \$(<" . Utils::formatPath($projectTmpDir . "dir_to_chmod.txt") . ")";
         $log = ShellAction::executeCommand($command, array('comment' => sprintf(__('Changing directories permissions to %s', true), Configure::read('FileSystem.permissions.directories')), 'stepLog' => $this->_stepLog));
     }
     // Change directory mode
     if ($options['giveWriteMode'] === true) {
         // Give write permissions to some folder
         $writable = $this->_config->writable;
         if (sizeof($writable) > 0) {
             for ($i = 0; $i < sizeof($writable); $i++) {
                 $command = "chmod -vR " . Configure::read('FileSystem.permissions.writable') . "  " . Utils::formatPath($this->_project['Project']['prd_path'] . $writable[$i]);
                 ShellAction::executeCommand($command, array('comment' => sprintf(__('Changing writeable permissions', true), Configure::read('FileSystem.permissions.writable')), 'stepLog' => $this->_stepLog));
             }
         }
     }
     // Running finalization script
     if ($options['runAfterScript']) {
         $scriptPath = null;
         if (isset($this->_config->scripts['after']) && !empty($this->_config->scripts['after'])) {
             $scriptPath = $this->_config->scripts['after'];
         }
         $log = ShellAction::runScript('after', $projectTmpDir, $scriptPath, $options);
     }
 }