[BUGFIX] Avoid exception if a class is loaded early 83/43683/3
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 1 Oct 2015 03:36:09 +0000 (23:36 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 1 Oct 2015 03:48:46 +0000 (05:48 +0200)
Ensure that the class cache is made available early

Resolves: #69133
Change-Id: I16d931ef78ad9000d28d98f8f78d782b3ae508b7
Reviewed-on: http://review.typo3.org/43683
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
ChangeLog
Classes/Cache/CachedClassLoader.php
Classes/Cache/ClassCacheManager.php
class.ext_update.php

index 576211e..796ac10 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,7 +11,8 @@
        * Update the manual
        * Resolves #70240: Follow-up to Remove class tx_staticinfotables_div
        * Resolves #66011: Fatal error when executing update script
-       * Resolves #70224: Follow-up tp Import SQL parser for Dbal-free parsing with TYPO3 CMS 7.5+
+       * Resolves #70224: Follow-up to Import SQL parser for Dbal-free parsing with TYPO3 CMS 7.5+
+       * Resolves #69133: Avoid exception if a class is loaded early
 
 2015-09-14  Stanislas Rolland  <typo3@sjbr.ca>
 
index 41dd4ab..9faee03 100644 (file)
@@ -82,14 +82,16 @@ class CachedClassLoader {
                if (strpos($className, static::$namespace) !== FALSE) {
                        // Lookup the class in the array of static info entities and check its presence in the class cache
                        $entities = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][static::$extensionKey]['entities'];
+                       $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+                       $cacheManager = $objectManager->get('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+                       // ClassCacheManager instantiation creates the class cache if not already available
+                       $classCacheManager = $objectManager->get('SJBR\\StaticInfoTables\\Cache\\ClassCacheManager');
+                       $classCache = $cacheManager->getCache(static::$extensionKey);
                        foreach ($entities as $entity) {
                                if ($className === static::$namespace . $entity) {
                                        $entryIdentifier = 'DomainModel' . $entity;
-                                       $cacheManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
-                                       $classCache = $cacheManager->getCache(static::$extensionKey);
                                        if (!$classCache->has($entryIdentifier)) {
                                                // The class cache needs to be rebuilt
-                                               $classCacheManager = GeneralUtility::makeInstance('SJBR\\StaticInfoTables\\Cache\\ClassCacheManager');
                                                $classCacheManager->reBuild();
                                        }
                                        $classCache->requireOnce($entryIdentifier);
index 5804c8f..aeb2001 100644 (file)
@@ -3,7 +3,7 @@ namespace SJBR\StaticInfoTables\Cache;
 /***************************************************************
  *  Copyright notice
  *  (c) 2012 Georg Ringer <typo3@ringerge.org>
- *  (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  (c) 2013-2015 Stanislas Rolland <typo3(arobas)sjbr.ca>
  *  All rights reserved
  *  This script is part of the TYPO3 project. The TYPO3 project is
  *  free software; you can redistribute it and/or modify
@@ -19,14 +19,15 @@ namespace SJBR\StaticInfoTables\Cache;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
-use \TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
-use \TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\ArrayUtility;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Class Cache Manager
  *
  */
-class ClassCacheManager {
+class ClassCacheManager implements \TYPO3\CMS\Core\SingletonInterface {
 
        /**
         * Extension key
@@ -36,6 +37,18 @@ class ClassCacheManager {
        protected $extensionKey = 'static_info_tables';
 
        /**
+        * @var array Cache configurations
+        */
+       protected $cacheConfiguration = array(
+               'static_info_tables' => array(
+                       'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\PhpFrontend',
+                       'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend',
+                       'options' => array(),
+                       'groups' => array('all')
+               )
+       );
+
+       /**
         * @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
         */
        protected $cacheInstance;
@@ -53,7 +66,14 @@ class ClassCacheManager {
         * @return void
         */
        protected function initializeCache() {
-               $cacheManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+               $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+               $cacheManager = $objectManager->get('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+               if (!$cacheManager->hasCache($this->extensionKey)) {
+                       if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$this->extensionKey])) {
+                                       ArrayUtility::mergeRecursiveWithOverrule($this->cacheConfiguration[$this->extensionKey], $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$this->extensionKey]);
+                       }
+                       $cacheManager->setCacheConfigurations($this->cacheConfiguration);
+               }
                $this->cacheInstance = $cacheManager->getCache($this->extensionKey);
        }
 
index a046012..7f8fe41 100644 (file)
@@ -1,29 +1,31 @@
 <?php
-use \TYPO3\CMS\Core\Utility\GeneralUtility;
-use \TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
-use \TYPO3\CMS\Extbase\Utility\LocalizationUtility;
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2013-2015 Stanislas Rolland <typo3(arobas)sjbr.ca>
-*  All rights reserved
-*
-*  This script is part of the Typo3 project. The Typo3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+ /***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013-2015 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  All rights reserved
+ *
+ *  This script is part of the Typo3 project. The Typo3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+
 /**
  * Class for updating the db
  */
@@ -34,12 +36,12 @@ class ext_update {
        protected $extensionName = 'StaticInfoTables';
 
        /**
-        * @var TYPO3\CMS\Extbase\Object\ObjectManager Extbase Object Manager
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManager Extbase Object Manager
         */
        protected $objectManager;
        
        /**
-        * @var TYPO3\CMS\Extensionmanager\Utility\InstallUtility Extbase Install Tool
+        * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility Extension Manager Install Tool
         */
        protected $installTool;
 
@@ -48,10 +50,10 @@ class ext_update {
         *
         * @return string HTML
         */
-       function main() {
+       public function main() {
                $content = '';
 
-               $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+               $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
                $this->installTool = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
                $databaseUpdateUtility = $this->objectManager->get('SJBR\\StaticInfoTables\\Utility\\DatabaseUpdateUtility');
                
@@ -121,8 +123,7 @@ class ext_update {
                }
        }
 
-       function access() {
+       public function access() {
                return TRUE;
        }
-}
-?>
\ No newline at end of file
+}
\ No newline at end of file