From d7e89badaf1df326792b62bfebed3bf032d7e7ae Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Fri, 6 Mar 2015 13:56:23 +0100 Subject: [PATCH] [BUGFIX] Install tool image tests broken Switching the image manipulation from hardcoded cache table to the caching framework with #28484 triggers a fatal error in the install tool image tests. This cache was not properly reset in the install tool initialization. The patch resolves this by cleaning up the cache initialization that has been marked as todo since install tool rewrite. This is solved for now. The whole situation is still not perfect since bootstrap, install tool and extensionmanager manipulate this stuff and the static Cache class with its static properties in front of the caching framework does not help to encapsulate and separate the different needs. A further refactoring releasing the system from static dependencies and direct global access would help here to reduce complexity with another patch later. Resolves: #54498 Related: #28484 Releases: master Change-Id: Ied01a025ce8e5a3cce03732c95d0914e8fa7af23 Reviewed-on: http://review.typo3.org/37594 Reviewed-by: Nicole Cordes <typo3@cordes.co> Tested-by: Nicole Cordes <typo3@cordes.co> Reviewed-by: Markus Klein <klein.t3@reelworx.at> Tested-by: Markus Klein <klein.t3@reelworx.at> --- .../Classes/Controller/AbstractController.php | 37 ++++++-------- .../CachingFrameworkDatabaseSchemaService.php | 49 ++++++------------- 2 files changed, 32 insertions(+), 54 deletions(-) diff --git a/typo3/sysext/install/Classes/Controller/AbstractController.php b/typo3/sysext/install/Classes/Controller/AbstractController.php index d832dbdca8a4..fe63b074bec9 100644 --- a/typo3/sysext/install/Classes/Controller/AbstractController.php +++ b/typo3/sysext/install/Classes/Controller/AbstractController.php @@ -16,6 +16,7 @@ namespace TYPO3\CMS\Install\Controller; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Install\Service\EnableFileService; +use TYPO3\CMS\Core\Cache\Backend\NullBackend; /** * Controller abstract for shared parts of Tool, Step and Ajax controller @@ -401,40 +402,34 @@ class AbstractController { /** * Require dbal ext_localconf if extension is loaded - * Required extbase + fluid ext_localconf - * Set caching to null, we do not want dbal, fluid or extbase to cache anything + * Required extbase ext_localconf + * Set caching to NullBackend, install tool must not cache anything * * @return void */ protected function loadBaseExtensions() { if ($this->isDbalEnabled()) { require(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('dbal') . 'ext_localconf.php'); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal']['backend'] - = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal']['options'] = array(); } + // @todo: Find out if this could be left out require(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extbase') . 'ext_localconf.php'); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap']['backend'] - = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap']['options'] = array(); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_object']['backend'] - = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_object']['options'] = array(); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_reflection']['backend'] - = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_reflection']['options'] = array(); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns']['backend'] - = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns']['options'] = array(); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['backend'] - = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['options'] = array(); + $cacheConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']; + + $cacheConfigurationsWithCachesSetToNullBackend = array(); + foreach ($cacheConfigurations as $cacheName => $cacheConfiguration) { + // cache_core and cache_classes are handled in bootstrap already + if (is_array($cacheConfiguration) && $cacheName !== 'cache_core' && $cacheName !== 'cache_classes') { + $cacheConfiguration['backend'] = NullBackend::class; + $cacheConfiguration['options'] = array(); + } + $cacheConfigurationsWithCachesSetToNullBackend[$cacheName] = $cacheConfiguration; + } /** @var $cacheManager \TYPO3\CMS\Core\Cache\CacheManager */ $cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class); - $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); + $cacheManager->setCacheConfigurations($cacheConfigurationsWithCachesSetToNullBackend); } /** diff --git a/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php b/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php index 583b2a8980d5..687d20cfbe13 100644 --- a/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php +++ b/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php @@ -14,6 +14,9 @@ namespace TYPO3\CMS\Install\Service; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Cache\CacheFactory; + /** * This service provides the sql schema for the caching framework */ @@ -24,44 +27,24 @@ class CachingFrameworkDatabaseSchemaService { * * This method needs ext_localconf and ext_tables loaded! * - * This is a hack, but there was no smarter solution with current cache configuration setup: - * ToolController sets the extbase caches to NullBackend to ensure the install tool does not - * cache anything. The CacheManager gets the required SQL from database backends only, so we need to - * temporarily 'fake' the standard db backends for extbase caches so they are respected. - * - * Additionally, the extbase_object cache is already in use and instantiated, and the CacheManager singleton - * does not allow overriding this definition. The only option at the moment is to 'fake' another cache with - * a different name, and then substitute this name in the sql content with the real one. - * - * @TODO: http://forge.typo3.org/issues/54498 - * @TODO: It might be possible to reduce this ugly construct by circumventing the 'singleton' of CacheManager by using 'new' - * * @return string Cache framework SQL */ public function getCachingFrameworkRequiredDatabaseSchema() { - $cacheConfigurationBackup = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap'] = array( - 'groups' => array('system') - ); - $extbaseObjectFakeName = uniqid('extbase_object'); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$extbaseObjectFakeName] = array( - 'groups' => array('system') - ); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_reflection'] = array( - 'groups' => array('system') - ); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns'] = array( - 'groups' => array('system') - ); - /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */ - $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class); - $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); - $cacheSqlString = \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions(); - $sqlString = str_replace($extbaseObjectFakeName, 'extbase_object', $cacheSqlString); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = $cacheConfigurationBackup; + // Use new to circumvent the singleton pattern of CacheManager + $cacheManager = new CacheManager; $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); + // Cache manager needs cache factory. cache factory injects itself to manager in __construct() + new CacheFactory('production', $cacheManager); + + $tableDefinitions = ''; + foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) { + $backend = $cacheManager->getCache($cacheName)->getBackend(); + if (method_exists($backend, 'getTableDefinitions')) { + $tableDefinitions .= LF . $backend->getTableDefinitions(); + } + } - return $sqlString; + return $tableDefinitions; } /** -- GitLab