Browse Source

v8-2695 site cache is not cleared on update

Olivier Massot 4 years ago
parent
commit
56d0bde3d8
1 changed files with 31 additions and 5 deletions
  1. 31 5
      ot_core/Classes/Cache/OtCacheManager.php

+ 31 - 5
ot_core/Classes/Cache/OtCacheManager.php

@@ -3,10 +3,9 @@
 namespace Opentalent\OtCore\Cache;
 
 use Opentalent\OtCore\Website\OtPageRepository;
-use TYPO3\CMS\Core\Service\OpcodeCacheService;
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
-use TYPO3\CMS\Install\Service\ClearCacheService;
 use TYPO3\CMS\Core\Cache\CacheManager;
 
 class OtCacheManager
@@ -30,7 +29,7 @@ class OtCacheManager
      * @param int $pageUid
      * @param bool $clearAll if true, all caches will be cleared, and not only the frontend one
      */
-    public static function clearSiteCache(int $pageUid, $clearAll=false) {
+    public static function clearSiteCache(int $pageUid, bool $clearAll) {
 
         $pageRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtPageRepository::class);
         $rootPage = $pageRepository->getRootPageFor($pageUid);
@@ -43,10 +42,37 @@ class OtCacheManager
             return 'pageId_' . $page['uid'];
         }, $pages);
 
-        if (!$clearAll) {
+        if ($clearAll) {
+            $cacheManager->flushCachesByTags($tags);
+        } else {
             $cacheManager->flushCachesInGroupByTags('pages', $tags);
+        }
+
+        // << BUGFIX: without this, the fluid templates caches are not cleared
+        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
+        $cnn = $connectionPool->getConnectionByName('Default');
+        $cnn->beginTransaction();
+        $sql = "update typo3.cache_hash h inner join typo3.cache_hash_tags t on h.id = t.id
+                set h.expires = 0
+                where t.tag = 'ident_TS_TEMPLATE';";
+        $stmt = $cnn->prepare($sql);
+        $stmt->executeQuery();
+        $cnn->commit();
+        // >>
+    }
+
+    /**
+     * Clears cache
+     *
+     * @param bool $clearAll if true, all caches will be cleared, and not only the frontend one
+     */
+    public static function clearCache($clearAll) {
+        $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
+
+        if ($clearAll) {
+            $cacheManager->flushCachesInGroup('pages');
         } else {
-            $cacheManager->flushCachesByTags($tags);
+            $cacheManager->flushCaches();
         }
     }