2 namespace TYPO3\CMS\Install\Service
;
4 /***************************************************************
7 * (c) 2011-2013 Christian Kuhn <lolli@schwarzbu.ch>
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
30 use TYPO3\CMS\Core\Utility\GeneralUtility
;
33 * Expected schema service
35 * @internal use in install tool only!
37 class SqlExpectedSchemaService
{
40 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
43 protected $objectManager = NULL;
46 * Get expected schema array
48 * @return array Expected schema
50 public function getExpectedDatabaseSchema() {
51 /** @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService $schemaMigrationService */
52 $schemaMigrationService = $this->objectManager
->get('TYPO3\\CMS\\Install\\Service\\SqlSchemaMigrationService');
53 // Raw concatenated ext_tables.sql and friends string
54 $expectedSchemaString = $this->getTablesDefinitionString();
56 $cleanedExpectedSchemaString = implode(LF
, $schemaMigrationService->getStatementArray($expectedSchemaString, TRUE, '^CREATE TABLE '));
57 $expectedSchema = $schemaMigrationService->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
58 return $expectedSchema;
62 * Cycle through all loaded extensions and get full table definitions as concatenated string
64 * @param boolean $withStatic TRUE if sql from ext_tables_static+adt.sql should be loaded, too.
65 * @return string Concatenated SQL of loaded extensions ext_tables.sql
67 public function getTablesDefinitionString($withStatic = FALSE) {
70 // Find all ext_tables.sql of loaded extensions
71 $loadedExtensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
72 foreach ($loadedExtensionInformation as $extensionConfiguration) {
73 if ((is_array($extensionConfiguration) ||
$extensionConfiguration instanceof \ArrayAccess
) && $extensionConfiguration['ext_tables.sql']) {
74 $sqlString[] = GeneralUtility
::getUrl($extensionConfiguration['ext_tables.sql']);
77 && (is_array($extensionConfiguration) ||
$extensionConfiguration instanceof \ArrayAccess
)
78 && $extensionConfiguration['ext_tables_static+adt.sql']
80 $sqlString[] = GeneralUtility
::getUrl($extensionConfiguration['ext_tables_static+adt.sql']);
84 // Add caching framework sql definition
85 $sqlString[] = $this->getCachingFrameworkRequiredDatabaseSchema();
87 // Add category registry sql definition
88 $sqlString[] = \TYPO3\CMS\Core\Category\CategoryRegistry
::getInstance()->getDatabaseTableDefinitions();
90 return implode(LF
. LF
. LF
. LF
, $sqlString);
94 * Get schema SQL of required cache framework tables.
96 * This method needs ext_localconf and ext_tables loaded!
98 * This is a hack, but there was no smarter solution with current cache configuration setup:
99 * ToolController sets the extbase caches to NullBackend to ensure the install tool does not
100 * cache anything. The CacheManager gets the required SQL from database backends only, so we need to
101 * temporarily 'fake' the standard db backends for extbase caches so they are respected.
103 * Additionally, the extbase_object cache is already in use and instantiated, and the CacheManager singleton
104 * does not allow overriding this definition. The only option at the moment is to 'fake' another cache with
105 * a different name, and then substitute this name in the sql content with the real one.
107 * @TODO: This construct needs to be improved. It does not recognise if some custom ext overwrote the extbase cache config
108 * @TODO: Solve this as soon as cache configuration is separated from ext_localconf / ext_tables
109 * @TODO: It might be possible to reduce this ugly construct by circumventing the 'singleton' of CacheManager by using 'new'
111 * @return string Cache framework SQL
113 public function getCachingFrameworkRequiredDatabaseSchema() {
114 $cacheConfigurationBackup = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'];
115 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap'] = array(
116 'groups' => array('system')
118 $extbaseObjectFakeName = uniqid('extbase_object');
119 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$extbaseObjectFakeName] = array(
120 'groups' => array('system')
122 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_reflection'] = array(
123 'groups' => array('system')
125 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns'] = array(
126 'groups' => array('system')
128 /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */
129 $cacheManager = $GLOBALS['typo3CacheManager'];
130 $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
131 $cacheSqlString = \TYPO3\CMS\Core\Cache\Cache
::getDatabaseTableDefinitions();
132 $sqlString = str_replace($extbaseObjectFakeName, 'extbase_object', $cacheSqlString);
133 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = $cacheConfigurationBackup;
134 $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);