From df98de6ecc0e6c4aa8c1c021a3d60b9094e1bf5d Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Fri, 20 Jan 2017 11:03:06 +0100 Subject: [PATCH] [!!!][TASK] Make commands compatible with Flow 4.0 Flow 4.0 has now the Neos namespace and needs a different fully qualified name for the commands. This change is breaking as the default Flow version is now set to 4.0 and configurations might need to be adapted. Resolves: #49 --- src/Application/Neos/Flow.php | 39 ++++++++++++++++--- src/Task/Neos/Flow/FlushCacheListTask.php | 4 +- src/Task/Neos/Flow/MigrateTask.php | 7 +--- src/Task/Neos/Flow/PublishResourcesTask.php | 2 +- src/Task/Neos/Flow/SetFilePermissionsTask.php | 19 +++++---- src/Task/Neos/Neos/ImportSiteTask.php | 7 +++- 6 files changed, 52 insertions(+), 26 deletions(-) diff --git a/src/Application/Neos/Flow.php b/src/Application/Neos/Flow.php index 7c7b3520..4c986c64 100644 --- a/src/Application/Neos/Flow.php +++ b/src/Application/Neos/Flow.php @@ -25,7 +25,7 @@ class Flow extends BaseApplication * The Neos Flow major and minor version of this application * @var string */ - protected $version = '3.0'; + protected $version = '4.0'; /** * Constructor @@ -150,9 +150,8 @@ public function getBuildEssentialsDirectoryName() { if ($this->getVersion() <= '1.1') { return 'Common'; - } else { - return 'BuildEssentials'; } + return 'BuildEssentials'; } /** @@ -166,8 +165,38 @@ public function getFlowScriptName() { if ($this->getVersion() <= '1.1') { return 'flow3'; - } else { - return 'flow'; } + return 'flow'; + } + + /** + * + * + * @return string + */ + public function getCommandPackageKey() + { + if ($this->getVersion() < '2.0') { + return 'typo3.flow3'; + } + if ($this->getVersion() < '4.0') { + return 'typo3.flow'; + } + return 'neos.flow'; + } + + /** + * Returns a executable flow command including the context + * + * @param string $targetPath the path where the command should be executed + * @param string $command the actual command for example `cache:flush` + * @param array $arguments list of arguments which will be appended to the command + * @return string + */ + public function buildCommand($targetPath, $command, array $arguments = []) + { + return 'cd ' . $targetPath . ' && FLOW_CONTEXT=' . $this->getContext() . + ' ./' . $this->getFlowScriptName() . ' ' . $this->getCommandPackageKey() . ':' . $command . ' ' + . join(' ', array_map('escapeshellarg', $arguments)); } } diff --git a/src/Task/Neos/Flow/FlushCacheListTask.php b/src/Task/Neos/Flow/FlushCacheListTask.php index 94cf55e6..2ea3b06b 100644 --- a/src/Task/Neos/Flow/FlushCacheListTask.php +++ b/src/Task/Neos/Flow/FlushCacheListTask.php @@ -21,7 +21,7 @@ * You can configure the list of cache identifiers in the task option ```flushCacheList```, like:: * * $workflow->setTaskOptions('TYPO3\\Surf\\Task\\Neos\\Flow\\FlushCacheListTask', [ - * 'flushCacheList' => 'TYPO3_TypoScript_Content, Flow_Session_MetaData, Flow_Session_Storage' + * 'flushCacheList' => 'Neos_Fusion_Content, Flow_Session_MetaData, Flow_Session_Storage' * ]) * */ @@ -57,7 +57,7 @@ public function execute(Node $node, Application $application, Deployment $deploy $targetPath = $deployment->getApplicationReleasePath($application); foreach ($caches as $cache) { $deployment->getLogger()->debug(sprintf('Flush cache with identifier "%s"', $cache)); - $this->shell->executeOrSimulate('cd ' . $targetPath . ' && ' . 'FLOW_CONTEXT=' . $application->getContext() . ' ./' . $application->getFlowScriptName() . ' ' . sprintf('typo3.flow:cache:flushone --identifier %s', + $this->shell->executeOrSimulate('cd ' . $targetPath . ' && ' . 'FLOW_CONTEXT=' . $application->getContext() . ' ./' . $application->getFlowScriptName() . ' ' . sprintf('flow:cache:flushone --identifier %s', $cache), $node, $deployment); } } else { diff --git a/src/Task/Neos/Flow/MigrateTask.php b/src/Task/Neos/Flow/MigrateTask.php index 8dc1f9b3..ada1f67c 100644 --- a/src/Task/Neos/Flow/MigrateTask.php +++ b/src/Task/Neos/Flow/MigrateTask.php @@ -39,13 +39,8 @@ public function execute(Node $node, Application $application, Deployment $deploy throw new InvalidConfigurationException(sprintf('Flow application needed for MigrateTask, got "%s"', get_class($application)), 1358863288); } - $commandPackageKey = 'typo3.flow'; - if ($application->getVersion() < '2.0') { - $commandPackageKey = 'typo3.flow3'; - } - $targetPath = $deployment->getApplicationReleasePath($application); - $this->shell->executeOrSimulate('cd ' . $targetPath . ' && FLOW_CONTEXT=' . $application->getContext() . ' ./' . $application->getFlowScriptName() . ' ' . $commandPackageKey . ':doctrine:migrate', $node, $deployment); + $this->shell->executeOrSimulate($application->buildCommand($targetPath, 'doctrine:migrate'), $node, $deployment); } /** diff --git a/src/Task/Neos/Flow/PublishResourcesTask.php b/src/Task/Neos/Flow/PublishResourcesTask.php index 9339ac0c..3550af1f 100644 --- a/src/Task/Neos/Flow/PublishResourcesTask.php +++ b/src/Task/Neos/Flow/PublishResourcesTask.php @@ -39,7 +39,7 @@ public function execute(Node $node, Application $application, Deployment $deploy if ($application->getVersion() >= '3.0') { $targetPath = $deployment->getApplicationReleasePath($application); - $this->shell->executeOrSimulate('cd ' . $targetPath . ' && ' . 'FLOW_CONTEXT=' . $application->getContext() . ' ./' . $application->getFlowScriptName() . ' ' . 'typo3.flow:resource:publish', $node, $deployment); + $this->shell->executeOrSimulate($application->buildCommand($targetPath, 'resource:publish'), $node, $deployment); } } diff --git a/src/Task/Neos/Flow/SetFilePermissionsTask.php b/src/Task/Neos/Flow/SetFilePermissionsTask.php index 73ea4749..0a2fb7a3 100644 --- a/src/Task/Neos/Flow/SetFilePermissionsTask.php +++ b/src/Task/Neos/Flow/SetFilePermissionsTask.php @@ -35,21 +35,20 @@ class SetFilePermissionsTask extends Task implements ShellCommandServiceAwareInt public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (!$application instanceof Flow) { - throw new InvalidConfigurationException(sprintf('Flow application needed for SetFilePermissionsTask, got "%s"', get_class($application)), 1358863436); + throw new InvalidConfigurationException(sprintf('Flow application needed for SetFilePermissionsTask, got "%s"', + get_class($application)), 1358863436); } $targetPath = $deployment->getApplicationReleasePath($application); - $arguments = isset($options['shellUsername']) ? $options['shellUsername'] : (isset($options['username']) ? $options['username'] : 'root'); - $arguments .= ' ' . (isset($options['webserverUsername']) ? $options['webserverUsername'] : 'www-data'); - $arguments .= ' ' . (isset($options['webserverGroupname']) ? $options['webserverGroupname'] : 'www-data'); + $arguments = [ + isset($options['shellUsername']) ? $options['shellUsername'] : (isset($options['username']) ? $options['username'] : 'root'), + isset($options['webserverUsername']) ? $options['webserverUsername'] : 'www-data', + isset($options['webserverGroupname']) ? $options['webserverGroupname'] : 'www-data' + ]; - $commandPackageKey = 'typo3.flow'; - if ($application->getVersion() < '2.0') { - $commandPackageKey = 'typo3.flow3'; - } - - $this->shell->executeOrSimulate('cd ' . $targetPath . ' && FLOW_CONTEXT=' . $application->getContext() . ' ./' . $application->getFlowScriptName() . ' ' . $commandPackageKey . ':core:setfilepermissions ' . $arguments, $node, $deployment); + $this->shell->executeOrSimulate($application->buildCommand($targetPath, 'core:setfilepermissions', + [$arguments]), $node, $deployment); } /** diff --git a/src/Task/Neos/Neos/ImportSiteTask.php b/src/Task/Neos/Neos/ImportSiteTask.php index 0b44e328..ccaf0936 100644 --- a/src/Task/Neos/Neos/ImportSiteTask.php +++ b/src/Task/Neos/Neos/ImportSiteTask.php @@ -43,8 +43,11 @@ public function execute(Node $node, Application $application, Deployment $deploy } $targetPath = $deployment->getApplicationReleasePath($application); - $sitePackageKey = $options['sitePackageKey']; - $this->shell->executeOrSimulate('cd ' . $targetPath . ' && FLOW_CONTEXT=' . $application->getContext() . ' ./flow typo3.neos:site:import --package-key ' . $sitePackageKey, $node, $deployment); + $arguments = [ + '--package-key', + $options['sitePackageKey'] + ]; + $this->shell->executeOrSimulate($application->buildCommand($targetPath, 'site:import', $arguments), $node, $deployment); } /**