[BUGFIX][Cache] File backend: Create directory after flush()
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 11 Jul 2011 10:32:38 +0000 (12:32 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 11 Jul 2011 14:41:27 +0000 (16:41 +0200)
The file backend does not re-create the cache directory on
flush() which leads to problems if calling flush() and set()
afterwards again. One unit test had to manually clear cache
files because of that and can be simplified now.
This is an issue in TYPO3 v4 only, FLOW3 is not affected.

Change-Id: Ic7756b2c14641789696f10c223d76439ca7e9602
Resolves: #28090
Reviewed-on: http://review.typo3.org/3249
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/cache/backend/class.t3lib_cache_backend_filebackend.php
tests/t3lib/cache/backend/class.t3lib_cache_backend_filebackendTest.php
tests/t3lib/class.t3lib_divTest.php

index c85c005..6585912 100644 (file)
@@ -422,6 +422,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
         */
        public function flush() {
                t3lib_div::rmdir($this->cacheDirectory, TRUE);
+               $this->createFinalCacheDirectory($this->cacheDirectory);
        }
 
        /**
index 878254f..c687837 100644 (file)
@@ -468,6 +468,22 @@ class t3lib_cache_backend_FileBackendTest extends tx_phpunit_testcase {
                $this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
        }
 
+       /**
+        * @test
+        * @author Christian Kuhn <lolli@schwarzbu.ch>
+        */
+       public function flushCreatesCacheDirectoryAgain() {
+               $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
+               $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
+
+               $backend = $this->getMock('t3lib_cache_backend_FileBackend', array('dummy'), array(), '', FALSE);
+               $backend->setCacheDirectory('vfs://Foo/');
+               $backend->setCache($mockCache);
+
+               $backend->flush();
+               $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/');
+       }
+
        /**
         * @test
         * @author Robert Lemke <robert@typo3.org>
index 8ff5a93..78753b0 100644 (file)
@@ -1734,9 +1734,15 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $file = PATH_site . 'typo3temp/' . $unique . '.xml';
                t3lib_div::writeFileToTypo3tempDir($file, $xml);
 
+                       // Make sure there is no cached version of the label
+               $GLOBALS['typo3CacheManager']->getCache('t3lib_l10n')->flush();
+
                        // Get default value
                $defaultLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default');
 
+                       // Clear language cache again
+               $GLOBALS['typo3CacheManager']->getCache('t3lib_l10n')->flush();
+
                        // Set override file
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xml'][$unique] = $file;
 
@@ -1744,13 +1750,6 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $store = t3lib_div::makeInstance('t3lib_l10n_Store');
                $store->flushData('EXT:lang/locallang_core.xml');
 
-                       // Manually flush cache (because t3lib_l10n cannot be recreated automatically at this point)
-               $cacheDirectory = PATH_site . 'typo3temp/Cache/Data/t3lib_l10n/';
-               $cacheFiles = t3lib_div::getFilesInDir($cacheDirectory);
-               foreach ($cacheFiles as $cacheFile) {
-                       @unlink($cacheDirectory . $cacheFile);
-               }
-
                        // Get override value
                $overrideLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default');