From 3306d7e2fe87a9152a73eb2c0b40cf3b1d6aced2 Mon Sep 17 00:00:00 2001 From: Dominique Feyer Date: Thu, 23 Apr 2015 09:38:50 +0200 Subject: [PATCH] [TASK] Add a task to flush specific cache on deployment This change add FlushCacheListTask. This task work only for Flow >= 2.3 and support clearing one or multiple cache. The option `flushCacheList` must contains a comma-separated list of cache identifier. Change-Id: Ieb6ba9458c88b03a3e88bd65476442f3b9f1a27e Releases: master --- .../Task/TYPO3/Flow/FlushCacheListTask.php | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Classes/TYPO3/Surf/Task/TYPO3/Flow/FlushCacheListTask.php diff --git a/Classes/TYPO3/Surf/Task/TYPO3/Flow/FlushCacheListTask.php b/Classes/TYPO3/Surf/Task/TYPO3/Flow/FlushCacheListTask.php new file mode 100644 index 00000000..41e72963 --- /dev/null +++ b/Classes/TYPO3/Surf/Task/TYPO3/Flow/FlushCacheListTask.php @@ -0,0 +1,93 @@ +setTaskOptions('typo3.surf:typo3:flow:flushcachelist', [ + * 'flushCacheList' => 'TYPO3_TypoScript_Content, Flow_Session_MetaData, Flow_Session_Storage' + * ]) + * + */ +class FlushCacheListTask extends Task { + + /** + * @Flow\Inject + * @var ShellCommandService + */ + protected $shell; + + /** + * Execute this task + * + * @param Node $node + * @param Application $application + * @param Deployment $deployment + * @param array $options + * @return void + * @throws InvalidConfigurationException + */ + public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { + if (!$application instanceof FlowApplication) { + throw new InvalidConfigurationException(sprintf('Flow application needed for MigrateTask, got "%s"', get_class($application)), 1429774224); + } + + if (!isset($options['flushCacheList']) || trim($options['flushCacheList']) === '') { + throw new InvalidConfigurationException('Missing option "flushCacheList" for FlushCacheListTask', 1429774229); + } + + if ($application->getVersion() >= '2.3') { + $caches = is_array($options['flushCacheList']) ? $options['flushCacheList'] : explode(',', $options['flushCacheList']); + $targetPath = $deployment->getApplicationReleasePath($application); + foreach ($caches as $cache) { + $deployment->getLogger()->log(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', $cache), $node, $deployment); + } + } else { + throw new InvalidConfigurationException(sprintf('FlushCacheListTask is available since Flow Framework 2.3, your application version is "%s"', $application->getVersion()), 1434126060); + } + } + + /** + * Simulate this task + * + * @param Node $node + * @param Application $application + * @param Deployment $deployment + * @param array $options + * @return void + */ + public function simulate(Node $node, Application $application, Deployment $deployment, array $options = array()) { + $this->execute($node, $application, $deployment, $options); + } + + /** + * Rollback the task + * + * @param Node $node + * @param Application $application + * @param Deployment $deployment + * @param array $options + * @return void + */ + public function rollback(Node $node, Application $application, Deployment $deployment, array $options = array()) { + // Unable to rollback a clear cache command + } + +} \ No newline at end of file