Executes this task

@param Node $node
@param Application $application
@param Deployment $deployment
@param array $options
182239
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $releaseIdentifier = $deployment->getReleaseIdentifier();
        $releasesPath = $application->getReleasesPath();
        $commands = [
            "mkdir -p $releasesPath/$releaseIdentifier/Data",
            "cd $releasesPath/$releaseIdentifier",
            'ln -sf ../../../shared/Data/Logs ./Data/Logs',
            'ln -sf ../../../shared/Data/Persistent ./Data/Persistent'
        ];
        $this->shell->executeOrSimulate($commands, $node, $deployment);
    }
795108
protected function createFile($directoryPath, $content, Node $node, Deployment $deployment, array $options)
    {
        $commands = [
            'mkdir -p '.escapeshellarg($directoryPath),
            'cd '.escapeshellarg($directoryPath),
            'echo '.escapeshellarg(implode(' | ', $content)).' > '.escapeshellarg($this->getFileName($options)),
        ];
        $this->shell->executeOrSimulate($commands, $node, $deployment);
    }
365939
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        try {
            $options = $this->configureOptions($options);
        } catch (ExceptionInterface $e) {
            return;
        }

        if (empty($options['directories'])) {
            return;
        }

        $baseDirectory = $options['baseDirectory'] ?: $deployment->getApplicationReleasePath($application);

        $commands = array_map(function ($directory) {
            return sprintf('mkdir -p %s', $directory);
        }, $options['directories']);

        array_unshift($commands, sprintf('cd %s', $baseDirectory));

        $this->shell->executeOrSimulate($commands, $node, $deployment);
    }
619542
protected function executeCliCommand(array $cliArguments, Node $node, CMS $application, Deployment $deployment, array $options = [])
    {
        $this->determineWorkingDirectoryAndTargetNode($node, $application, $deployment, $options);
        $phpBinaryPathAndFilename = isset($options['phpBinaryPathAndFilename']) ? $options['phpBinaryPathAndFilename'] : 'php';
        $commandPrefix = '';
        if (isset($options['context'])) {
            $commandPrefix = 'TYPO3_CONTEXT=' . escapeshellarg($options['context']) . ' ';
        }
        $commandPrefix .= $phpBinaryPathAndFilename . ' ';

        $this->determineWorkingDirectoryAndTargetNode($node, $application, $deployment, $options);

        return $this->shell->executeOrSimulate([
            'cd ' . escapeshellarg($this->workingDirectory),
            $commandPrefix . implode(' ', array_map('escapeshellarg', $cliArguments))
        ], $this->targetNode, $deployment);
    }
1291276
public void deployResources(Resource[] resources, int options)
    {
        if (resources != null)
        {
        	for (Resource resource : resources)
        	{
        		this.deployResource(resource, options);
        	}
        }
    }
1240597
protected function executeOrSimulate(
        Node $node,
        Application $application,
        Deployment $deployment,
        array $options = []
    ) {
        if (empty($options['clearPhpCacheUris'])) {
            return;
        }
        $uris = is_array($options['clearPhpCacheUris']) ? $options['clearPhpCacheUris'] : [$options['clearPhpCacheUris']];
        foreach ($uris as $uri) {
            $deployment->getLogger()->log('... (localhost): curl "'.$uri.'"', LOG_DEBUG);
            if ($deployment->isDryRun() === false) {
                $this->browser->request($uri);
            }
        }
    }
636487
public function rollback(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $releasePath = $deployment->getApplicationReleasePath($application);
        $this->shell->execute('rm -Rf ' . $releasePath, $node, $deployment, true);
    }
710851
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $releaseIdentifier = $deployment->getReleaseIdentifier();
        $releasesPath = $application->getReleasesPath();
        $this->shell->executeOrSimulate('cd ' . $releasesPath . ' && rm -f ./previous && if [ -e ./current ]; then mv ./current ./previous; fi && ln -s ./' . $releaseIdentifier . ' ./current && rm -f ./next', $node, $deployment);
        $deployment->getLogger()->notice('<success>Node "' . $node->getName() . '" ' . ($deployment->isDryRun() ? 'would be' : 'is') . ' live!</success>');
    }
644326
protected function executeDeploy($method, DeployBase $deploy)
    {
        $this->say('Deploy has initialized!');
        $deploy->beforeDeploy();
        $this->executeCommandHook($method, 'before_deploy');
        $deploy->onDeploy();
        $this->executeCommandHook($method, 'after_deploy');
        $deploy->afterDeploy();
        $this->say('Deploy has completed!');

        return $this;
    }
930697
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $configurationFileExtension = isset($options['configurationFileExtension']) ? $options['configurationFileExtension'] : 'yaml';
        $targetReleasePath = $deployment->getApplicationReleasePath($application);
        $configurationPath = $deployment->getDeploymentConfigurationPath();
        if (!is_dir($configurationPath)) {
            return;
        }
        $commands = [];
        $configurationFiles = Files::readDirectoryRecursively($configurationPath, $configurationFileExtension);
        foreach ($configurationFiles as $configuration) {
            $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
            $escapedSourcePath = escapeshellarg($configuration);
            $escapedTargetPath = escapeshellarg(Files::concatenatePaths([$targetReleasePath, 'Configuration', $targetConfigurationPath]) . '/');
            if ($node->isLocalhost()) {
                $commands[] = 'mkdir -p ' . $escapedTargetPath;
                $commands[] = 'cp ' . $escapedSourcePath . ' ' . $escapedTargetPath;
            } else {
                $username = isset($options['username']) ? $options['username'] . '@' : '';
                $hostname = $node->getHostname();

                $sshPort = isset($options['port']) ? '-p ' . escapeshellarg($options['port']) . ' ' : '';
                $scpPort = isset($options['port']) ? '-P ' . escapeshellarg($options['port']) . ' ' : '';
                $sshOptions = '';
                $expect = '';
                if ($node->hasOption('password')) {
                    $sshOptions .= '-o PubkeyAuthentication=no ';
                    $passwordSshLoginScriptPathAndFilename = Files::concatenatePaths([dirname(dirname(dirname(dirname(__DIR__)))), 'Resources', 'Private/Scripts/PasswordSshLogin.expect']);
                    if (Phar::running() !== '') {
                        $passwordSshLoginScriptContents = file_get_contents($passwordSshLoginScriptPathAndFilename);
                        $passwordSshLoginScriptPathAndFilename = Files::concatenatePaths([$deployment->getTemporaryPath(), 'PasswordSshLogin.expect']);
                        file_put_contents($passwordSshLoginScriptPathAndFilename, $passwordSshLoginScriptContents);
                    }
                    $expect = sprintf('expect %s %s', escapeshellarg($passwordSshLoginScriptPathAndFilename), escapeshellarg($node->getOption('password')));
                }
                $createDirectoryCommand = '"mkdir -p ' . $escapedTargetPath . '"';
                $commands[] = ltrim("{$expect} ssh {$sshOptions}{$sshPort}{$username}{$hostname} {$createDirectoryCommand}");
                $commands[] = ltrim("{$expect} scp {$sshOptions}{$scpPort}{$escapedSourcePath} {$username}{$hostname}:\"{$escapedTargetPath}\"");
            }
        }

        $localhost = new Node('localhost');
        $localhost->onLocalhost();

        $this->shell->executeOrSimulate($commands, $localhost, $deployment);
    }
1161583
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $deploymentPath = $application->getDeploymentPath();
        $sharedPath = $application->getSharedPath();
        $releasesPath = $application->getReleasesPath();
        $releaseIdentifier = $deployment->getReleaseIdentifier();
        $releasePath = $deployment->getApplicationReleasePath($application);
        $result = $this->shell->execute('test -d ' . $deploymentPath, $node, $deployment, true);
        if ($result === false) {
            throw new TaskExecutionException('Deployment directory "' . $deploymentPath . '" does not exist on node ' . $node->getName(), 1311003253);
        }
        $commands = [
            'mkdir -p ' . $releasesPath,
            'mkdir -p ' . $sharedPath,
            'mkdir -p ' . $releasePath,
            'cd ' . $releasesPath . ';ln -snf ./' . $releaseIdentifier . ' next'
        ];
        $this->shell->executeOrSimulate($commands, $node, $deployment);
    }
913228
public function rollback(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $replacePaths = [];
        $replacePaths['{workspacePath}'] = escapeshellarg($deployment->getWorkspacePath($application));

        if (!isset($options['rollbackCommand'])) {
            return;
        }
        $command = $options['rollbackCommand'];
        $command = str_replace(array_keys($replacePaths), $replacePaths, $command);

        $localhost = new Node('localhost');
        $localhost->onLocalhost();

        $this->shell->execute($command, $localhost, $deployment, true);
    }
1018866
private static function install(Application $app, string $config, string $repo) : void
    {
        $options = [
            'command'         => 'install',
            '--configuration' => $config,
            '--git-directory' => $repo,
            '-f'              => '-f'
        ];
        $app->run(new ArrayInput($options));
    }
1334005
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $options = $this->configureOptions($options);

        $dumpCommand = new Process([
            'mysqldump',
            '-h',
            $options['sourceHost'],
            '-u',
            $options['sourceUser'],
            '-p' . $options['sourcePassword'],
            $options['sourceDatabase']
        ]);

        $mysqlCommand = new Process([
            'mysql',
            '-h',
            $options['targetHost'],
            '-u',
            $options['targetUser'],
            '-p' . $options['targetPassword'],
            $options['targetDatabase']

        ]);

        $sshCommand = ['ssh'];
        $username = isset($options['username']) ? $options['username'] . '@' : '';
        $hostname = $node->getHostname();
        $sshCommand[] = $username . $hostname;
        if ($node->hasOption('port')) {
            $sshCommand[] = '-P';
            $sshCommand[] = $node->getOption('port');
        }
        $sshCommand[] = $mysqlCommand->getCommandLine();
        $sshCommand = new Process($sshCommand);

        $command = $dumpCommand->getCommandLine()
            . ' | '
            . $sshCommand->getCommandLine();

        $localhost = new Node('localhost');
        $localhost->onLocalhost();

        $this->shell->executeOrSimulate($command, $localhost, $deployment);
    }
89561
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->commandProviderService->getWebDir($deployment, $application);
            if ($webDir !== '') {
                $deploymentPath = rtrim($deploymentPath, '/').'/'.$webDir;
            }

            $commands = [];
            $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, '/').'/';
    }
928007
public function rollback(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $this->removeFile(
            rtrim($application->getReleasesPath(), '/').'/'.$this->getTargetPath($options),
            $node,
            $deployment,
            $options
        );

        $this->removeFile(
            rtrim($deployment->getWorkspacePath($application), '/').'/'.$this->getTargetPath($options),
            $deployment->getNode('localhost'),
            $deployment,
            $options
        );
    }
918758
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $sourceNode = $this->nodeFactory->getNodeByArray($options['sourceNode']);
        $credentials = $this->getCredentials($sourceNode, $deployment, $options['sourceNodeOptions'], $application);
        $dumpFile = $this->getDumpFile($options['sourceNodeOptions'], $credentials);
        $source = $this->getArgument($sourceNode, $dumpFile);

        $credentials = $this->getCredentials($node, $deployment, $options, $application);
        $dumpFile = $this->getDumpFile($options, $credentials);
        $target = $this->getArgument($node, $dumpFile);

        $command = 'scp -o BatchMode=\'yes\' '.$source.' '.$target;
        if ($sourceNode->isLocalhost() === true) {
            $this->shell->executeOrSimulate($command, $sourceNode, $deployment);
        } else {
            $this->shell->executeOrSimulate($command, $node, $deployment);
        }
    }