Execute this task

@param \TYPO3\Surf\Domain\Model\Node $node
@param \TYPO3\Surf\Domain\Model\Application $application
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@param array $options
195621
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        if (! isset($options['keepReleases'])) {
            $deployment->getLogger()->debug(($deployment->isDryRun() ? 'Would keep' : 'Keeping') . ' all releases for "' . $application->getName() . '"');

            return;
        }

        $keepReleases = $options['keepReleases'];
        $releasesPath = $application->getReleasesPath();
        $currentReleaseIdentifier = $deployment->getReleaseIdentifier();

        $previousReleaseIdentifier = \TYPO3\Surf\findPreviousReleaseIdentifier($deployment, $node, $application, $this->shell);
        $allReleases = \TYPO3\Surf\findAllReleases($deployment, $node, $application, $this->shell);

        $removableReleases = array_map('trim', array_filter($allReleases, function ($release) use ($currentReleaseIdentifier, $previousReleaseIdentifier) {
            return $release !== '.' && $release !== $currentReleaseIdentifier && $release !== $previousReleaseIdentifier && $release !== 'current' && $release !== 'previous';
        }));

        sort($removableReleases);

        $removeReleases = array_slice($removableReleases, 0, count($removableReleases) - $keepReleases);
        $removeCommand = '';
        foreach ($removeReleases as $removeRelease) {
            $removeCommand .= "rm -rf {$releasesPath}/{$removeRelease};rm -f {$releasesPath}/{$removeRelease}REVISION;";
        }
        if (count($removeReleases) > 0) {
            $deployment->getLogger()->info(($deployment->isDryRun() ? 'Would remove' : 'Removing') . ' releases ' . implode(', ', $removeReleases));
            $this->shell->executeOrSimulate($removeCommand, $node, $deployment);
        } else {
            $deployment->getLogger()->info('No releases to remove');
        }
    }
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);
    }
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);
    }
745251
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $deployment->getLogger()->warning(DeprecationMessageFactory::createGenericDeprecationWarningForTask(__CLASS__));
        $options = $this->configureOptions($options);
        $projectName = $options['sourceforgeProjectName'];

        $sourceforgeLogin = $options['sourceforgeUserName'] . ',' . $options['sourceforgeProjectName'];

        $projectDirectory = str_replace(' ', '\ ', sprintf('/home/frs/project/%s/%s/%s/%s/%s', substr($projectName, 0, 1), substr($projectName, 0, 2), $projectName, $options['sourceforgePackageName'], $options['version']));
        $targetHostAndDirectory = escapeshellarg($sourceforgeLogin . '@frs.sourceforge.net:' . $projectDirectory);

        $this->shell->executeOrSimulate('rsync -e ssh ' . implode(' ', $options['files']) . ' ' . $targetHostAndDirectory, $node, $deployment);
    }
799042
public static function run($version, $deployFile)
    {
        // Init Deployer
        $console = new Application('Deployer', $version);
        $input = new ArgvInput();
        $output = new ConsoleOutput();
        $deployer = new self($console);

        // Pretty-print uncaught exceptions in symfony-console
        set_exception_handler(function ($e) use ($input, $output, $deployer) {
            $io = new SymfonyStyle($input, $output);
            $io->block($e->getMessage(), get_class($e), 'fg=white;bg=red', ' ', true);
            $io->block($e->getTraceAsString());

            $deployer->logger->log('['. get_class($e) .'] '. $e->getMessage());
            $deployer->logger->log($e->getTraceAsString());
            exit(1);
        });

        // Require deploy.php file
        if (is_readable($deployFile)) {
            // Prevent variable leak into deploy.php file
            call_user_func(function () use ($deployFile) {
                require $deployFile;
            });
        }

        // Run Deployer
        $deployer->init();
        $console->run($input, $output);
    }
178996
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $this->executeOrSimulate($node, $application, $deployment, $options);
    }
279038
private function executeAction($id, array $options)
    {
        $action = $this->adapter->post(sprintf('%s/floating_ips/%s/actions', $this->endpoint, $id), $options);

        $action = json_decode($action);

        return new ActionEntity($action->action);
    }
607268
protected function determineWorkingDirectoryAndTargetNode(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        if (!isset($this->workingDirectory, $this->targetNode)) {
            if (isset($options['useApplicationWorkspace']) && $options['useApplicationWorkspace'] === true) {
                $this->workingDirectory = $deployment->getWorkspacePath($application);
                $node = $deployment->getNode('localhost');
            } else {
                $this->workingDirectory = $deployment->getApplicationReleasePath($application);
            }
            $this->targetNode = $node;
        }
    }
1008076
public static function serve($source, $destination, $options = [])
    {
        $options = array_merge(self::$defaultOptions, $options);

        try {
            ServeConvertedWebP::serve($source, $destination, $options);
        } catch (\Exception $e) {
            self::performFailAction(
                $options['fail'],
                $options['fail-when-original-unavailable'],
                $source,
                $destination,
                $options
            );
        }
    }
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);
    }
663930
public function run(DeltaInterface $version, OptionsInterface $options)
    {
        if (!$this->shouldMigrate($version, $options)) {
            if ($options->isExceptionOnSkip()) {
                throw new RunnerException(sprintf(
                    'Cowardly refusing to run %s() on a delta that is already "%s" (ID: %s).',
                    $options->getDirection(),
                    $options->getDirection(),
                    $version->getId()
                ));
            }

            return false; // skip
        }

        // Dispatch MIGRATE_BEFORE
        $this->getPublisher()->publish(new MigrateBeforeEvent($version, $options, $this->getContext()));

        $version->migrate($options); // state will be changed

        // Dispatch MIGRATE_AFTER
        $event = new MigrateAfterEvent($version, $options, $this->getContext());
        $this->getPublisher()->publish($event);

        return $event;
    }
872012
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $options = array_replace_recursive($this->options, $options);
        if (empty($options['sourceNode']) === false) {
            $node = $this->nodeFactory->getNodeByArray($options['sourceNode']);
            $options = array_replace_recursive($options, $options['sourceNodeOptions']);
        }

        $credentials = $this->getCredentials($node, $deployment, $options, $application);
        $mysqlArguments = $this->getMysqlArguments($credentials);
        $tableLikes = $this->getTableLikes($options, $credentials);
        $dumpFile = $this->getDumpFile($options, $credentials);

        $commands = [$this->getDataTablesCommand($mysqlArguments, $tableLikes, $dumpFile)];
        if (empty($tableLikes) === false) {
            $commands[] = $this->getStructureCommand($mysqlArguments, $tableLikes, $dumpFile);
        }

        $this->shell->executeOrSimulate($commands, $node, $deployment, false, false);
    }
944407
public function afterDelete(Event $event, Entity $entity, ArrayObject $options)
    {
        //Deletes the file
        (new File(BANNERS . $entity->filename))->delete();

        parent::afterDelete($event, $entity, $options);
    }
392365
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $commands = [
            'if [ -d '.escapeshellarg($deployment->getApplicationReleasePath($application)).' ]; then '.
            'cd '.escapeshellarg($deployment->getApplicationReleasePath($application)).'; '.
            'if [ -d \'.git\' ] && hash git 2>/dev/null; then '.
            'CHANGES=$( git status --porcelain ); '.
            'if [ "$CHANGES" ]; then '.
            'echo \'Detected changes in the target directory. Deployments are just possible to clean targets!\' 1>&2; '.
            'echo $CHANGES 1>&2; '.
            'exit 1; '.
            'fi; '.
            'fi; '.
            'fi;',
        ];

        $this->shell->executeOrSimulate($commands, $node, $deployment);
    }
452991
protected function getCredentials(Node $node, Deployment $deployment, array $options, Application $application)
    {
        if (empty($options['db']) === true) {
            throw new InvalidConfigurationException('db is not configured', 1429628542);
        }
        if (empty($options['db']['credentialsSource']) === false) {
            switch ($options['db']['credentialsSource']) {
                case 'TYPO3\\CMS':
                    $credentials = $this->getCredentialsFromTypo3Cms($node, $deployment, $options, $application);
                    break;
                default:
                    throw new InvalidConfigurationException('unknown credentialsSource', 1429628543);
            }
        } else {
            $credentials = $options['db'];
        }

        return $credentials;
    }
726484
protected function deployToBranch($options) {
    $this->branchName = $this->getBranchName($options);
    $this->prepareDir();
    $this->addGitRemotes();
    $this->checkoutLocalDeployBranch();
    $this->mergeUpstreamChanges();
    $this->build();
    $this->commit();
    $this->push($this->branchName, $options);
  }
1148006
protected function runDeployies(array $deployies, array $options = [])
    {
        if (count($deployies) == 0) {
            $this->note('<info>Nothing to deploy.</info>');

            return;
        }

        foreach ($deployies as $file) {
            $this->runDeploy($file);
        }
    }