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
@throws \TYPO3\Surf\Exception\InvalidConfigurationException
192354
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        if (!isset($options['folders'])) {
            return;
        }
        $folders = $options['folders'];
        if (!is_array($folders)) {
            $folders = [$folders];
        }
        $replacePaths = [
            '{deploymentPath}' => escapeshellarg($application->getDeploymentPath()),
            '{sharedPath}' => escapeshellarg($application->getSharedPath()),
            '{releasePath}' => escapeshellarg($deployment->getApplicationReleasePath($application)),
            '{currentPath}' => escapeshellarg($application->getReleasesPath() . '/current'),
            '{previousPath}' => escapeshellarg($application->getReleasesPath() . '/previous')
        ];

        $commands = [];

        $username = isset($options['username']) ? $options['username'] . '@' : '';
        $hostname = $node->getHostname();
        $port = $node->hasOption('port') ? '-P ' . escapeshellarg($node->getOption('port')) : '';

        foreach ($folders as $folderPair) {
            if (!is_array($folderPair) || count($folderPair) !== 2) {
                throw new InvalidConfigurationException('Each rsync folder definition must be an array of exactly two folders', 1405599056);
            }
            $sourceFolder = rtrim(str_replace(array_keys($replacePaths), $replacePaths, $folderPair[0]), '/') . '/';
            $targetFolder = rtrim(str_replace(array_keys($replacePaths), $replacePaths, $folderPair[1]), '/') . '/';
            $commands[] = "rsync -avz --delete -e ssh {$sourceFolder} {$username}{$hostname}:{$targetFolder}";
        }

        $ignoreErrors = isset($options['ignoreErrors']) && $options['ignoreErrors'] === true;
        $logOutput = !(isset($options['logOutput']) && $options['logOutput'] === false);

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

        $this->shell->executeOrSimulate($commands, $localhost, $deployment, $ignoreErrors, $logOutput);
    }
253827
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        Assert::isInstanceOf($application, Flow::class, sprintf('Flow application needed for RunCommandTask, got "%s"', get_class($application)));

        $options = $this->configureOptions($options);

        $targetPath = $deployment->getApplicationReleasePath($application);

        $command = sprintf('cd %s && FLOW_CONTEXT=%s ./%s %s', $targetPath, $application->getContext(), $application->getFlowScriptName(), $options['command']);

        $this->shell->executeOrSimulate($command, $node, $deployment, $options['ignoreErrors'], $options['logOutput']);
    }
402213
protected function fileExists($pathAndFileName, Node $node, CMS $application, Deployment $deployment, array $options = [])
    {
        $this->determineWorkingDirectoryAndTargetNode($node, $application, $deployment, $options);
        $pathAndFileName = $this->workingDirectory . '/' . $pathAndFileName;
        return $this->shell->executeOrSimulate('test -f ' . escapeshellarg($pathAndFileName), $this->targetNode, $deployment, true) === false ? false : true;
    }
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);
            }
        }
    }
1226493
public function onPeridotConfigure(CoreConfiguration $configuration, Application $application)
    {
        $this->configuration = new Configuration($configuration);
        $this->application = $application;
    }
410453
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        if (!isset($options['command'])) {
            throw new InvalidConfigurationException('Missing "command" option for ShellTask', 1311168045);
        }

        $replacePaths = [
            '{deploymentPath}' => escapeshellarg($application->getDeploymentPath()),
            '{sharedPath}' => escapeshellarg($application->getSharedPath()),
            '{releasePath}' => escapeshellarg($deployment->getApplicationReleasePath($application)),
            '{currentPath}' => escapeshellarg($application->getReleasesPath() . '/current'),
            '{previousPath}' => escapeshellarg($application->getReleasesPath() . '/previous')
        ];

        $command = $options['command'];
        $command = str_replace(array_keys($replacePaths), $replacePaths, $command);

        $ignoreErrors = isset($options['ignoreErrors']) && $options['ignoreErrors'] === true;
        $logOutput = !(isset($options['logOutput']) && $options['logOutput'] === false);

        $this->shell->executeOrSimulate($command, $node, $deployment, $ignoreErrors, $logOutput);
    }
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);
        }
    }
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;
        }
    }
617116
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        if (empty($options['branch']) || !empty($options['tag'])) {
            return;
        }

        $quietFlag = (isset($options['verbose']) && $options['verbose']) ? '' : '-q';

        $commands = [];
        $commands[] = 'cd '.escapeshellarg($deployment->getApplicationReleasePath($application));
        $commands[] = 'if [ -d \'.git\' ] && hash git 2>/dev/null; then '.
            'git branch -f '.escapeshellarg($options['branch']).' deploy && '.
            'git checkout '.$quietFlag.' '.escapeshellarg($options['branch']).' && '.
            'git branch -D deploy; '.
            'fi;';

        $this->shell->executeOrSimulate($commands, $node, $deployment);
    }
680092
protected function init($options)
    {
        if ($options instanceof Traversable) {
            $options = ArrayUtils::iteratorToArray($options);
        } elseif (!is_array($options)) {
            $errMsg = sprintf('%s  expects an array or Traversable config', __METHOD__);
            throw new Exception\InvalidArgumentException($errMsg);
        }

        if (!array_key_exists('serviceLocator', $options)) {
            $errMsg = 'Argument serviceLocator not found';
            throw new Exception\InvalidArgumentException($errMsg);
        }
        $this->setServiceLocator($options['serviceLocator']);

        if (!array_key_exists('moduleOptions', $options)) {
            $errMsg = 'Argument moduleOptions not found';
            throw new Exception\InvalidArgumentException($errMsg);
        }
        $this->setModuleOptions($options['moduleOptions']);
    }
1121215
public function execute(NodeData $node)
    {
        foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) {
            if (isset($propertyConfiguration['type']) && ($propertyConfiguration['type'] === ImageInterface::class || preg_match('/array\<.*\>/', $propertyConfiguration['type']))) {
                if (!isset($nodeProperties)) {
                    $nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?');
                    $nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]);
                    $nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC);
                    $nodeProperties = unserialize($nodeRecord['properties']);
                }

                if (!isset($nodeProperties[$propertyName]) || empty($nodeProperties[$propertyName])) {
                    continue;
                }

                if ($propertyConfiguration['type'] === ImageInterface::class) {
                    $adjustments = [];
                    $oldVariantConfiguration = $nodeProperties[$propertyName];
                    if (is_array($oldVariantConfiguration)) {
                        foreach ($oldVariantConfiguration as $variantPropertyName => $property) {
                            switch (substr($variantPropertyName, 3)) {
                                case 'originalImage':
                                    /**
                                     * @var $originalAsset \Neos\Media\Domain\Model\Image
                                     */
                                    $originalAsset = $this->assetRepository->findByIdentifier($this->persistenceManager->getIdentifierByObject($property));
                                    break;
                                case 'processingInstructions':
                                    $adjustments = $this->processingInstructionsConverter->convertFrom($property, 'array');
                                    break;
                            }
                        }

                        $nodeProperties[$propertyName] = null;
                        if (isset($originalAsset)) {
                            $stream = $originalAsset->getResource()->getStream();
                            if ($stream === false) {
                                continue;
                            }

                            fclose($stream);
                            $newImageVariant = new ImageVariant($originalAsset);
                            foreach ($adjustments as $adjustment) {
                                $newImageVariant->addAdjustment($adjustment);
                            }
                            $originalAsset->addVariant($newImageVariant);
                            $this->assetRepository->update($originalAsset);
                            $nodeProperties[$propertyName] = $this->persistenceManager->getIdentifierByObject($newImageVariant);
                        }
                    }
                } elseif (preg_match('/array\<.*\>/', $propertyConfiguration['type'])) {
                    if (is_array($nodeProperties[$propertyName])) {
                        $convertedValue = [];
                        foreach ($nodeProperties[$propertyName] as $entryValue) {
                            if (!is_object($entryValue)) {
                                continue;
                            }

                            $stream = $entryValue->getResource()->getStream();
                            if ($stream === false) {
                                continue;
                            }

                            fclose($stream);
                            $existingObjectIdentifier = null;
                            try {
                                $existingObjectIdentifier = $this->persistenceManager->getIdentifierByObject($entryValue);
                                if ($existingObjectIdentifier !== null) {
                                    $convertedValue[] = $existingObjectIdentifier;
                                }
                            } catch (\Exception $exception) {
                            }
                        }
                        $nodeProperties[$propertyName] = $convertedValue;
                    }
                }
            }
        }

        if (isset($nodeProperties)) {
            $nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?');
            $nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]);
        }
    }
135828
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $this->ensureApplicationIsTypo3Cms($application);
        $cliArguments = $this->getSuitableCliArguments($node, $application, $deployment, $options);
        if (empty($cliArguments)) {
            $deployment->getLogger()->warning('Neither Extension "typo3_console" nor "coreapi" was not found! Make sure one is available in your project, or remove this task (' . __CLASS__ . ') in your deployment configuration!');
            return;
        }
        $this->executeCliCommand(
            $cliArguments,
            $node,
            $application,
            $deployment,
            $options
        );
    }
976769
public static function configure($object, array $options)
    {
        foreach ($options as $property => $value) {
            $object->$property = $value;
        }
    }
610981
public function initialize(array $data, array $options = []): NodeInterface
    {
        if (!isset($data['id']) || !is_string($data['id']) || $data['id'] === '') {
            throw ValidationException::create('Field "id" must be a non-empty string.');
        }

        if (!preg_match('/^[0-9a-z\_]+$/i', $data['id'])) {
            throw ValidationException::create(
                'Field "id" must have only characters 0-9, a-z, A-Z or "_". Received: '.$data['id']
            );
        }

        $this->setId($data['id']);

        $this->addSubscriber($this);

        if (isset($data['name'])) {
            if (!is_string($data['name']) || $data['name'] === '') {
                throw ValidationException::create('Field "name" must be a non-empty string.');
            }

            $this->setName($data['name']);
        }

        if (isset($data['type'])) {
            if (!is_string($data['type']) || $data['type'] === '') {
                throw ValidationException::create('Field "type" must be a non-empty string.');
            }

            if (!preg_match('/^[0-9a-z\_]+$/i', $data['type'])) {
                throw ValidationException::create(
                    'Field "type" must have only characters 0-9, a-z, A-Z or "_". Received: '.$data['type']
                );
            }

            $this->setType($data['type']);
        }


        if (isset($data['metadata'])) {
            if (!is_array($data['metadata'])) {
                throw ValidationException::create('Field "metadata" must be an array.');
            }

            $this->setMetadata($data['metadata']);
        }

        if (isset($data['parent'])) {
            if (!is_object($data['parent'])
                || !($data['parent'] instanceof NodeInterface)
            ) {
                throw ValidationException::create(
                    'Field "parent" must be an instance of NodeInterface.'
                );
            }

            $this->addParent($data['parent']);
        }

        if (isset($data['children'])) {
            if (!is_array($data['children'])) {
                throw ValidationException::create('Field "children" must be an array.');
            }

            foreach ($data['children'] as $node) {
                if (!is_object($node) || !($node instanceof NodeInterface)) {
                    throw ValidationException::create(
                        'Field "children" must be an array of NodeInterface instances.'
                    );
                }

                $node->addParent($this);

                $this->addChild($node);
            }
        }

        return $this;
    }
568283
public static function configure($object, array $options): void
    {
        foreach ($options as $property => $value) {
            if (\property_exists($object, $property)) {
                $object->$property = $value;
            }
        }
    }
567498
protected function validateOutput($stepActionParams, $options, $context)
    {
        if (!is_array($stepActionParams)) {
            throw new InvalidConfigurationException(
                "Step '".self::STEP_VALIDATE_OBJECT_OUTPUT."' in AbstractConfigurableProducer expected an array as configuration"
            );
        }

        $stepParamsResolver = new OptionsResolver();

        $stepParamsResolver->setRequired([
            self::OUTPUT_OBJECT,
            self::OUTPUT_GROUP,
            self::OUTPUT_DISPLAY_ERROR,
        ]);

        $params = $stepParamsResolver->resolve($stepActionParams);

        $object = $this->confHelper->resolve($params[self::OUTPUT_OBJECT], $context);
        $group = $this->confHelper->resolve($params[self::OUTPUT_GROUP], $context);
        $showError = $this->confHelper->resolve($params[self::OUTPUT_DISPLAY_ERROR], $context);

        $version = $context['exchange']->getHeaders()['apiVersion'];

        $this->getHydrator()->hydrate($object, $group, $version);
        $validator = $this->getValidator();
        $errors = $validator->validate($object);
        if (count($errors) > 0) {
            $message = '';
            foreach ($errors as $error) {
                $message .= $error->getPropertyPath().' - '.$error->getMessage().' | ';
            }
            $exception = new ExternalSystemException($message);
            $exception->setExternalSystemName($this->getName());
            $exception->setShowExternalSystemErrorMessage($showError);
            throw $exception;
        }
    }
167983
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $this->checkOptionsForValidity($options);
        $host = $options['releaseHost'];
        $login = $options['releaseHostLogin'];
        $sitePath =  $options['releaseHostSitePath'];
        $version = $options['version'];
        $label = $options['label'];
        $uriPattern = $options['downloadUriPattern'];
        $productName = $options['productName'];
        $files = $options['files'];

        $downloads = [];
        foreach ($files as $file) {
            $downloads[] = sprintf('"%s,%s,%s"', basename($file), sha1($file), sprintf($uriPattern, basename($file)));
        }
        $this->shell->executeOrSimulate(sprintf('ssh %s%s "cd \"%s\" ; ./flow release:adddownload --product-name \"%s\" --version \"%s\" --label \"%s\" %s"', ($login ? $login . '@' : ''), $host, $sitePath, $productName, $version, $label, implode(' ', $downloads)), $node, $deployment);
    }