[BUGFIX][Cache] Typo3DbBackend forgets tag entries in flushByTag 17/22017/2
authorChristian Zenker <typo3@xopn.de>
Wed, 12 Jun 2013 14:45:57 +0000 (16:45 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 6 Jul 2013 14:03:17 +0000 (16:03 +0200)
flushByTags removes cache entries tagged with a given tag, but
if those cache entries have other tags assigned, they are not
deleted in the tags table.
The patch fixes this with an additional query.

Resolves: #48984
Releases: 6.2, 6.1, 6.0
Change-Id: I7096e63cf823633f0c8a47f698bd475d7d02b83c
Reviewed-on: https://review.typo3.org/22017
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/core/Classes/Cache/Backend/Typo3DatabaseBackend.php
typo3/sysext/core/Tests/Unit/Cache/Backend/Typo3DatabaseBackendTest.php

index a66df7b..4d6ae5b 100644 (file)
@@ -257,7 +257,6 @@ class Typo3DatabaseBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend
                $this->throwExceptionIfFrontendDoesNotExist();
                $tagsTableWhereClause = $this->tagsTable . '.tag = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tag, $this->tagsTable);
                $this->deleteCacheTableRowsByTagsTableWhereClause($tagsTableWhereClause);
-               $GLOBALS['TYPO3_DB']->exec_DELETEquery($this->tagsTable, $tagsTableWhereClause);
        }
 
        /**
@@ -366,10 +365,11 @@ class Typo3DatabaseBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend
                $GLOBALS['TYPO3_DB']->sql_free_result($cacheEntryIdentifierRowsResource);
                if (count($cacheEntryIdentifiers)) {
                        $GLOBALS['TYPO3_DB']->exec_DELETEquery($this->cacheTable, 'identifier IN (' . implode(', ', $cacheEntryIdentifiers) . ')');
+                       $GLOBALS['TYPO3_DB']->exec_DELETEquery($this->tagsTable, 'identifier IN (' . implode(', ', $cacheEntryIdentifiers) . ')');
                }
        }
 
 }
 
 
-?>
\ No newline at end of file
+?>
index d8a5840..d2ca2a4 100644 (file)
@@ -416,6 +416,23 @@ class Typo3DatabaseBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
+       public function flushByTagDoesNotLeaveOrphanedEntriesInTagsTable() {
+               $backend = $this->setUpBackend();
+               $this->setUpMockFrontendOfBackend($backend);
+               $data = 'some data' . microtime();
+               $backend->set('BackendDbTest1', $data, array('UnitTestTag%boring', 'UnitTestTag%special'));
+               $backend->set('BackendDbTest2', $data, array('UnitTestTag%boring2', 'UnitTestTag%special'));
+               $backend->flushByTag('UnitTestTag%special');
+
+               $tagEntriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $this->testingTagsTable, 'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('BackendDbTest1', $this->testingTagsTable));
+               $this->assertCount(0, $tagEntriesFound);
+               $tagEntriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $this->testingTagsTable, 'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('BackendDbTest2', $this->testingTagsTable));
+               $this->assertCount(0, $tagEntriesFound);
+       }
+
+       /**
+        * @test
+        */
        public function hasReturnsTheCorrectResultForEntryWithExceededLifetime() {
                $backend = $this->setUpBackend();
                $mockCache = $this->setUpMockFrontendOfBackend($backend);
@@ -507,4 +524,4 @@ class Typo3DatabaseBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
 }
 
-?>
\ No newline at end of file
+?>