示例#1
0
 /**
  * @param Node $node
  * @param Deployment $deployment
  * @param array $options
  * @param Application $application
  * @return string
  * @throws InvalidConfigurationException
  * @throws TaskExecutionException
  */
 protected function getSharedPathFromNode(Node $node, Deployment $deployment, $options, Application $application)
 {
     if ($node->hasOption('sharedPath')) {
         $sharedPath = $node->getOption('sharedPath');
     } else {
         if ($node->hasOption('deploymentPath')) {
             $deploymentPath = $node->getOption('deploymentPath');
         } elseif (!empty($options['deploymentPath'])) {
             $deploymentPath = $options['deploymentPath'];
         } else {
             throw new InvalidConfigurationException('No deploymentPath defined!', 1414849872);
         }
         $webDir = $this->getWebDir($deployment, $application);
         if ($webDir !== '') {
             $deploymentPath = rtrim($deploymentPath, '/') . '/' . $webDir;
         }
         $commands = array();
         $commands[] = 'cd ' . escapeshellarg($deploymentPath);
         $commands[] = 'readlink ' . escapeshellarg('fileadmin');
         $output = $this->shell->execute($commands, $node, $deployment, TRUE);
         if (preg_match('/(.+)\\/fileadmin\\/?$/', trim($output), $matches)) {
             $sharedPath = $matches[1];
         } else {
             $sharedPath = str_replace('htdocs', 'shared', $deploymentPath);
         }
     }
     if ($sharedPath[0] !== '/') {
         $sharedPath = rtrim($deploymentPath, '/') . '/' . $sharedPath;
     }
     return rtrim($sharedPath, '/') . '/';
 }
示例#2
0
 /**
  * @param Node $node
  * @param Deployment $deployment
  * @param array $options
  * @param Application $application
  * @return array
  * @throws TaskExecutionException
  */
 protected function getCredentialsFromTypo3Cms(Node $node, Deployment $deployment, array $options = array(), Application $application)
 {
     $commands = $this->buildCommands($deployment, $application, 'coreapi', 'configurationapi:show DB', $options);
     if (empty($commands) === FALSE) {
         // Overwrite first command
         $commands[0] = 'cd ' . escapeshellarg($options['deploymentPath']);
     } else {
         throw new TaskExecutionException('Could not receive database credentials', 1409252547);
     }
     $returnedOutput = $this->shell->execute($commands, $node, $deployment, FALSE, FALSE);
     $returnedOutput = json_decode($returnedOutput, TRUE);
     if (empty($returnedOutput)) {
         throw new TaskExecutionException('Could not receive database credentials', 1409252546);
     }
     $credentials = array();
     foreach ($returnedOutput as $key => $value) {
         switch ($key) {
             case 'username':
                 $credentials['user'] = $value;
                 break;
             default:
                 $credentials[$key] = $value;
                 break;
         }
     }
     return $credentials;
 }
 /**
  * Executes this task
  *
  * @param Node $node
  * @param Application $application
  * @param Deployment $deployment
  * @param array $options
  * @throws TaskExecutionException
  * @return void
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     if ($node->isLocalhost()) {
         $deployment->getLogger()->log('node seems not to be a remote node', LOG_DEBUG);
     } else {
         $username = $node->hasOption('username') ? $node->getOption('username') : NULL;
         if (!empty($username)) {
             $username = $username . '@';
         }
         $hostname = $node->getHostname();
         $sshOptions = array('-A', '-q', '-o BatchMode=yes');
         if ($node->hasOption('port')) {
             $sshOptions[] = '-p ' . escapeshellarg($node->getOption('port'));
         }
         $command = 'ssh ' . implode(' ', $sshOptions) . ' ' . escapeshellarg($username . $hostname) . ' exit;';
         $this->shell->execute($command, $deployment->getNode('localhost'), $deployment);
         $deployment->getLogger()->log('SSH connection successfully established', LOG_DEBUG);
     }
 }