コード例 #1
0
ファイル: Manager.php プロジェクト: bijsterdee/deployer
 /**
  * Wrapper for sendToDatabase() to send plain commands to the database
  *
  * @param string $command
  * @param array $output
  * @param int $return
  * @param string $database_name
  * @param string $username
  * @param string $password
  * @throws DatabaseException
  */
 public function query($command, &$output = array(), &$return = 0, $database_name = null, $username = null, $password = null)
 {
     if ($this->database_checked && 'skip' == $this->database_name) {
         return;
     }
     if (null === $database_name) {
         $database_name = $this->database_name;
     }
     if (null === $username) {
         $username = $this->database_user;
     }
     if (null === $password) {
         $password = $this->database_pass;
     }
     $command = str_replace(array(), array(), $command);
     $command = escapeshellarg($command);
     $hostname = escapeshellarg($this->database_host);
     $port = escapeshellarg($this->database_port);
     $username = escapeshellarg($username);
     $password = escapeshellarg($password);
     $charset = escapeshellarg($this->database_charset);
     $database_name = escapeshellarg($database_name);
     $this->remote_shell->exec("mysql -h{$hostname} -P{$port} -u{$username} -p{$password} --default-character-set={$charset} -e {$command} --skip-column-names {$database_name}", $this->control_host, $output, $return, '/ -p[^ ]+ /', ' -p***** ', LOG_DEBUG);
     if (0 !== $return) {
         throw new DatabaseException('Database interaction failed !');
     }
 }
コード例 #2
0
ファイル: Deploy.php プロジェクト: lemonweb/dbpatcher
 /**
  * Returns all obsolete deployments that can be deleted.
  *
  * @param string $remote_host
  * @param string $remote_dir
  * @throws DeployException
  * @return array
  */
 protected function collectPastDeployments($remote_host, $remote_dir)
 {
     $this->logger->log("collectPastDeployments({$remote_host}, {$remote_dir})", LOG_DEBUG);
     $dirs = array();
     $return = null;
     $this->remote_shell->exec("ls -1 {$remote_dir}", $remote_host, $dirs, $return);
     if (0 !== $return) {
         throw new DeployException('ssh initialize failed');
     }
     if (!count($dirs)) {
         return array();
     }
     $deployment_dirs = array();
     foreach ($dirs as $dirname) {
         if (preg_match('/' . preg_quote($this->project_name) . '_\\d{4}-\\d{2}-\\d{2}_\\d{6}/', $dirname)) {
             $deployment_dirs[] = $dirname;
         }
     }
     // de two latest deployments always stay
     if (count($deployment_dirs) <= 2) {
         return array();
     }
     $dirs_to_delete = array();
     sort($deployment_dirs);
     $deployment_dirs = array_slice($deployment_dirs, 0, -2);
     foreach ($deployment_dirs as $key => $dirname) {
         $time = strtotime(str_replace(array($this->project_name . '_', '_'), array('', ' '), $dirname));
         // deployments older than a month can go
         if ($time < strtotime('-1 month')) {
             $this->logger->log("{$dirname} is older than a month");
             $dirs_to_delete[] = $dirname;
         } elseif ($time < strtotime('-1 week')) {
             // deployments older than a week only the last one of the day stays
             if (isset($deployment_dirs[$key + 1])) {
                 $time_next = strtotime(str_replace(array($this->project_name . '_', '_'), array('', ' '), $deployment_dirs[$key + 1]));
                 // if the next deployment was on the same day this one can go
                 if (date('Y-m-d', $time_next) == date('Y-m-d', $time)) {
                     $this->logger->log("{$dirname} was replaced the same day");
                     $dirs_to_delete[] = $dirname;
                 } else {
                     $this->logger->log("{$dirname} stays");
                 }
             }
         } else {
             $this->logger->log("{$dirname} stays");
         }
     }
     return $dirs_to_delete;
 }