Commit 8830ba39 authored by Benni Mack's avatar Benni Mack Committed by Christian Kuhn
Browse files

[!!!][TASK] Remove Cache helper class

The Cache class that acted as a central point when the caching
framework was optionally enabled for 4.3 is now moved
into separate methods.

The duplicate code for creating the database statement is now
moved from the Install Tool to EXT:core to be used in the Extension
Manager as well.

Resolves: #56319
Releases: master
Change-Id: I871a9a6ea506795335e2e8f5b6a410604feba506
Reviewed-on: http://review.typo3.org/40500


Reviewed-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent b3c025d1
<?php
namespace TYPO3\CMS\Core\Cache;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* A cache handling helper class
*/
class Cache {
/**
* @var bool TRUE if caching framework was fully initialized
*/
static protected $isCachingFrameworkInitialized = FALSE;
/**
* @var CacheManager
*/
static protected $cacheManager;
/**
* @var CacheFactory
*/
static protected $cacheFactory;
/**
* Initializes the caching framework by loading the cache manager and factory
* into the global context.
*
* @return CacheManager
*/
static public function initializeCachingFramework() {
if (!self::isCachingFrameworkInitialized()) {
// New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
self::$cacheManager = new CacheManager();
GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, self::$cacheManager);
self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
// New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
self::$cacheFactory = new CacheFactory('production', self::$cacheManager);
GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheFactory::class, self::$cacheFactory);
self::$isCachingFrameworkInitialized = TRUE;
}
return self::$cacheManager;
}
/**
* Determines whether the caching framework is initialized.
* The caching framework could be disabled for the core but used by an extension.
*
* @return bool True if caching framework is initialized
*/
static public function isCachingFrameworkInitialized() {
return self::$isCachingFrameworkInitialized;
}
/**
* Resets the isCachingFrameworkInitialized state
* Beware! This is not public API and necessary for edge cases in the install tool.
*
* @return void
*/
static public function flagCachingFrameworkForReinitialization() {
self::$isCachingFrameworkInitialized = FALSE;
GeneralUtility::removeSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, self::$cacheManager);
GeneralUtility::removeSingletonInstance(\TYPO3\CMS\Core\Cache\CacheFactory::class, self::$cacheFactory);
self::$cacheManager = NULL;
self::$cacheFactory = NULL;
}
/**
* Helper method for install tool and extension manager to determine
* required table structure of all caches that depend on it
*
* This is not a public API method!
*
* @return string Required table structure of all registered caches
*/
static public function getDatabaseTableDefinitions() {
$tableDefinitions = '';
foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
$backend = self::$cacheManager->getCache($cacheName)->getBackend();
if (method_exists($backend, 'getTableDefinitions')) {
$tableDefinitions .= LF . $backend->getTableDefinitions();
}
}
return $tableDefinitions;
}
/**
* A slot method to inject the required caching framework database tables to the
* tables definitions string
*
* @param array $sqlString
* @param string $extensionKey
* @return array
*/
public function addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition(array $sqlString, $extensionKey) {
self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
$sqlString[] = static::getDatabaseTableDefinitions();
return array('sqlString' => $sqlString, 'extensionKey' => $extensionKey);
}
}
<?php
namespace TYPO3\CMS\Install\Service;
namespace TYPO3\CMS\Core\Cache;
/*
* This file is part of the TYPO3 CMS project.
......@@ -14,13 +14,10 @@ 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
*/
class CachingFrameworkDatabaseSchemaService {
class DatabaseSchemaService {
/**
* Get schema SQL of required cache framework tables.
......@@ -47,6 +44,19 @@ class CachingFrameworkDatabaseSchemaService {
return $tableDefinitions;
}
/**
* A slot method to inject the required caching framework database tables to the
* tables definitions string
*
* @param array $sqlString
* @param string $extensionKey
* @return array
*/
public function addCachingFrameworkRequiredDatabaseSchemaForInstallUtility(array $sqlString, $extensionKey) {
$sqlString[] = $this->getCachingFrameworkRequiredDatabaseSchema();
return array($sqlString, $extensionKey);
}
/**
* A slot method to inject the required caching framework database tables to the
* tables definitions string
......@@ -54,9 +64,9 @@ class CachingFrameworkDatabaseSchemaService {
* @param array $sqlString
* @return array
*/
public function addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition(array $sqlString) {
public function addCachingFrameworkRequiredDatabaseSchemaForSqlExpectedSchemaService(array $sqlString) {
$sqlString[] = $this->getCachingFrameworkRequiredDatabaseSchema();
return array('sqlString' => $sqlString);
return array($sqlString);
}
}
......@@ -534,13 +534,21 @@ class Bootstrap {
}
/**
* Initialize caching framework
* Initialize caching framework, and re-initializes it (e.g. in the install tool) by recreating the instances
* again despite the Singleton instance
*
* @return Bootstrap
* @internal This is not a public API method, do not use in own extensions
*/
public function initializeCachingFramework() {
$this->setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework());
$cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
$cacheFactory = new \TYPO3\CMS\Core\Cache\CacheFactory('production', $cacheManager);
GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheFactory::class, $cacheFactory);
$this->setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
return $this;
}
......
......@@ -308,7 +308,8 @@ class DatabaseConnection extends \TYPO3\CMS\Core\Database\DatabaseConnection {
* @return void
*/
protected function analyzeCachingTables() {
$this->parseAndAnalyzeSql(\TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions());
$schemaService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\DatabaseSchemaService::class);
$this->parseAndAnalyzeSql($schemaService->getCachingFrameworkRequiredDatabaseSchema());
}
/**
......
......@@ -22,8 +22,8 @@ if (TYPO3_MODE === 'BE') {
$signalSlotDispatcher->connect(
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
'tablesDefinitionIsBeingBuilt',
\TYPO3\CMS\Core\Cache\Cache::class,
'addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition'
\TYPO3\CMS\Core\Cache\DatabaseSchemaService::class,
'addCachingFrameworkRequiredDatabaseSchemaForInstallUtility'
);
$signalSlotDispatcher->connect(
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
......
......@@ -279,8 +279,8 @@ class UpgradeWizard extends Action\AbstractAction {
/** @var $sqlHandler \TYPO3\CMS\Install\Service\SqlSchemaMigrationService */
$sqlHandler = $this->objectManager->get(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class);
/** @var \TYPO3\CMS\Install\Service\CachingFrameworkDatabaseSchemaService $cachingFrameworkDatabaseSchemaService */
$cachingFrameworkDatabaseSchemaService = $this->objectManager->get(\TYPO3\CMS\Install\Service\CachingFrameworkDatabaseSchemaService::class);
/** @var \TYPO3\CMS\Core\Cache\DatabaseSchemaService $cachingFrameworkDatabaseSchemaService */
$cachingFrameworkDatabaseSchemaService = $this->objectManager->get(\TYPO3\CMS\Core\Cache\DatabaseSchemaService::class);
$expectedSchemaString = $cachingFrameworkDatabaseSchemaService->getCachingFrameworkRequiredDatabaseSchema();
$cleanedExpectedSchemaString = implode(LF, $sqlHandler->getStatementArray($expectedSchemaString, TRUE, '^CREATE TABLE '));
$neededTableDefinition = $sqlHandler->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
......
......@@ -48,9 +48,6 @@ class ClearCacheService {
GeneralUtility::flushDirectory(PATH_site . 'typo3temp/Cache', TRUE, TRUE);
$bootstrap = \TYPO3\CMS\Core\Core\Bootstrap::getInstance();
\TYPO3\CMS\Core\Cache\Cache::flagCachingFrameworkForReinitialization();
$bootstrap
->initializeCachingFramework()
->initializePackageManagement(\TYPO3\CMS\Core\Package\PackageManager::class);
......
......@@ -14,8 +14,8 @@ $signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TY
$signalSlotDispatcher->connect(
\TYPO3\CMS\Install\Service\SqlExpectedSchemaService::class,
'tablesDefinitionIsBeingBuilt',
\TYPO3\CMS\Install\Service\CachingFrameworkDatabaseSchemaService::class,
'addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition'
\TYPO3\CMS\Core\Cache\DatabaseSchemaService::class,
'addCachingFrameworkRequiredDatabaseSchemaForSqlExpectedSchemaService'
);
$signalSlotDispatcher->connect(
\TYPO3\CMS\Install\Service\SqlExpectedSchemaService::class,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment