[BUGFIX] Fix exception error when using caching framework and eID scripts
authorMichael Stucki <michael.stucki@typo3.org>
Wed, 6 Jul 2011 19:44:09 +0000 (21:44 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 8 Jul 2011 19:12:16 +0000 (21:12 +0200)
When using the caching framework and calling an eID script containing
locallang labels, it may happen that data from cache_hash is tried to be
accessed.

As there is no caching framework initialized at this time of execution,
an exception warning is issued:
A cache with identifier "cache_hash" does not exist.

Fix the error by checking if the caching framework is initialized,
otherwise skip its usage.

Change-Id: Iaeae13fe756b9b230f3eea919eaa3f045f2a6dcf
Branches: 4.5
Resolves: #25086
Reviewed-on: http://review.typo3.org/3068
Reviewed-by: Stefan Neufeind
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/class.t3lib_page.php

index 4ba7ed0..2df1764 100644 (file)
@@ -977,11 +977,16 @@ class t3lib_pageSelect {
 
                if (TYPO3_UseCachingFramework) {
                        if (is_object($GLOBALS['typo3CacheManager'])) {
-                               $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
-                               $cacheEntry = $contentHashCache->get($hash);
+                               try {
+                                       $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+                                       $cacheEntry = $contentHashCache->get($hash);
 
-                               if ($cacheEntry) {
-                                       $hashContent = $cacheEntry;
+                                       if ($cacheEntry) {
+                                               $hashContent = $cacheEntry;
+                                       }
+                               } catch (t3lib_cache_exception_NoSuchCache $exception) {
+                                       // Ignore if there is no such cache. This may only happen in eID context
+                                       // when no cache was initialized.
                                }
                        }
                } else {
@@ -1014,12 +1019,17 @@ class t3lib_pageSelect {
        public static function storeHash($hash, $data, $ident, $lifetime = 0) {
                if (TYPO3_UseCachingFramework) {
                        if (is_object($GLOBALS['typo3CacheManager'])) {
-                               $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
-                                       $hash,
-                                       $data,
-                                       array('ident_' . $ident),
-                                       intval($lifetime)
-                               );
+                               try {
+                                       $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
+                                               $hash,
+                                               $data,
+                                               array('ident_' . $ident),
+                                               intval($lifetime)
+                                       );
+                               } catch (t3lib_cache_exception_NoSuchCache $exception) {
+                                       // Ignore if there is no such cache. This may only happen in eID context
+                                       // when no cache was initialized.
+                               }
                        }
                } else {
                        $insertFields = array(