/** * @return void */ protected function importCacheTables() { if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 4006000) { $cacheTables = \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions(); $this->importDatabaseDefinitions($cacheTables); } }
/** * @return string */ protected function resolveTableDefinitions() { $tableDefinitions = ''; foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $loadedExtConf) { if (is_array($loadedExtConf) && $loadedExtConf['ext_tables.sql']) { $extensionSqlContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($loadedExtConf['ext_tables.sql']); $tableDefinitions .= PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL . $extensionSqlContent; } } // Add SQL content coming from the caching framework $tableDefinitions .= \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions(); // Add SQL content coming from the category registry $tableDefinitions .= \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->getDatabaseTableDefinitions(); return $tableDefinitions; }
/** * Get schema SQL of required cache framework tables. * * 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'); $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; $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); return $sqlString; }
/** * @param string $extKey * @return void */ public function checkForDbUpdate($extensionKey) { $this->dbUpdateNeeded = FALSE; if (ExtensionManagementUtility::isLoaded($extensionKey)) { $sqlFile = ExtensionManagementUtility::extPath($extensionKey) . 'ext_tables.sql'; if (@file_exists($sqlFile)) { $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); if (class_exists('TYPO3\\CMS\\Install\\Service\\SqlSchemaMigrationService')) { /* @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService $sqlHandler */ $sqlHandler = $this->objectManager->get('TYPO3\\CMS\\Install\\Service\\SqlSchemaMigrationService'); } else { /* @var \TYPO3\CMS\Install\Sql\SchemaMigrator $sqlHandler */ $sqlHandler = $this->objectManager->get('TYPO3\\CMS\\Install\\Sql\\SchemaMigrator'); } $sqlContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($sqlFile); /** @var $cacheManager \TYPO3\CMS\Core\Cache\CacheManager */ $cacheManager = $GLOBALS['typo3CacheManager']; $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); $sqlContent .= \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions(); $fieldDefinitionsFromFile = $sqlHandler->getFieldDefinitions_fileContent($sqlContent); if (count($fieldDefinitionsFromFile)) { $fieldDefinitionsFromCurrentDatabase = $sqlHandler->getFieldDefinitions_database(); $updateTableDefinition = $sqlHandler->getDatabaseExtra($fieldDefinitionsFromFile, $fieldDefinitionsFromCurrentDatabase); $this->updateStatements = $sqlHandler->getUpdateSuggestions($updateTableDefinition); if (!empty($updateTableDefinition['extra']) || !empty($updateTableDefinition['diff']) || !empty($updateTableDefinition['diff_currentValues'])) { $this->dbUpdateNeeded = TRUE; } } } } }
/** * Gets the content of the ext_tables.sql and ext_tables_static+adt.sql files * Additionally adds the table definitions for the cache tables * * @param string $extension * @return void */ public function processDatabaseUpdates($extension) { $extTablesSqlFile = PATH_site . $extension['siteRelPath'] . '/ext_tables.sql'; if (file_exists($extTablesSqlFile)) { $extTablesSqlContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extTablesSqlFile); // @TODO: This should probably moved to TYPO3\CMS\Core\Cache\Cache->getDatabaseTableDefinitions ?! $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); $extTablesSqlContent .= \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions(); $this->updateDbWithExtTablesSql($extTablesSqlContent); } $extTablesStaticSqlFile = PATH_site . $extension['siteRelPath'] . '/ext_tables_static+adt.sql'; if (file_exists($extTablesStaticSqlFile)) { $extTablesStaticSqlContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extTablesStaticSqlFile); $this->importStaticSql($extTablesStaticSqlContent); } }
/** * Generates update wizard * * @return void * @todo Define visibility */ public function updateWizard() { \TYPO3\CMS\Core\Extension\ExtensionManager::removeCacheFiles(); // Forces creation / update of caching framework tables that are needed by some update wizards $cacheTablesConfiguration = implode(LF, $this->sqlHandler->getStatementArray(\TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions(), 1, '^CREATE TABLE ')); $neededTableDefinition = $this->sqlHandler->getFieldDefinitions_fileContent($cacheTablesConfiguration); $currentTableDefinition = $this->sqlHandler->getFieldDefinitions_database(); $updateTableDefenition = $this->sqlHandler->getDatabaseExtra($neededTableDefinition, $currentTableDefinition); $updateStatements = $this->sqlHandler->getUpdateSuggestions($updateTableDefenition); if (isset($updateStatements['create_table']) && count($updateStatements['create_table']) > 0) { $this->sqlHandler->performUpdateQueries($updateStatements['create_table'], $updateStatements['create_table']); } if (isset($updateStatements['add']) && count($updateStatements['add']) > 0) { $this->sqlHandler->performUpdateQueries($updateStatements['add'], $updateStatements['add']); } if (isset($updateStatements['change']) && count($updateStatements['change']) > 0) { $this->sqlHandler->performUpdateQueries($updateStatements['change'], $updateStatements['change']); } // call wizard $action = $this->INSTALL['database_type'] ? $this->INSTALL['database_type'] : 'checkForUpdate'; $this->updateWizard_parts($action); $this->output($this->outputWrapper($this->printAll())); }
/** * Loop through caching configurations * to find the usage of database backends and * parse and analyze table definitions * * @return void */ protected function analyzeCachingTables() { $this->parseAndAnalyzeSql(\TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions()); }
/** * Imports the data from the stddb tables.sql file. * * Example/intended usage: * * <pre> * protected function setUp() { * $this->createDatabase(); * $db = $this->useTestDatabase(); * $this->importStdDB(); * $this->importExtensions(array('cms', 'static_info_tables', 'templavoila')); * } * </pre> * * @return void */ protected function importStdDb() { /* @var TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */ $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); /** @var TYPO3\CMS\Install\Service\SqlExpectedSchemaService $sqlExpectedSchemaService */ $sqlExpectedSchemaService = $objectManager->get('TYPO3\\CMS\\Install\\Service\\SqlExpectedSchemaService'); $databaseDefinitions = $sqlExpectedSchemaService->getTablesDefinitionString(TRUE); $this->importDatabaseDefinitions($databaseDefinitions); // make sure missing caching framework tables do not get into the way $cacheTables = Cache::getDatabaseTableDefinitions(); $this->importDatabaseDefinitions($cacheTables); }
/** * Gets the defined field definitions from the ext_tables.sql files. * * @return array The accordant definitions */ protected function getDefinedFieldDefinitions() { $content = ''; $cacheTables = ''; if (class_exists('t3lib_cache') && method_exists(t3lib_cache, 'getDatabaseTableDefinitions')) { $cacheTables = \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions(); } if (method_exists($this->install, 'getFieldDefinitions_fileContent')) { $content = $this->install->getFieldDefinitions_fileContent(implode(chr(10), $this->getAllRawStructureDefinitions()) . $cacheTables); } else { $content = $this->install->getFieldDefinitions_sqlContent(implode(chr(10), $this->getAllRawStructureDefinitions()) . $cacheTables); } return $content; }
/** * Get the update statement of the database * * @return array */ public static function getSqlUpdateStatements() { $tblFileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(PATH_typo3 . 'sysext/core/ext_tables.sql'); foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $loadedExtConf) { if (is_array($loadedExtConf) && $loadedExtConf['ext_tables.sql']) { $tblFileContent .= chr(10) . chr(10) . chr(10) . chr(10) . \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($loadedExtConf['ext_tables.sql']); } } if (class_exists('\\TYPO3\\CMS\\Core\\Category\\CategoryRegistry') && version_compare(TYPO3_version, '7.6.0', '>=')) { $tblFileContent .= \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->getDatabaseTableDefinitions(); $tableDefinitions = \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->addCategoryDatabaseSchemaToTablesDefinition(array()); $tblFileContent .= $tableDefinitions['sqlString ']; $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $cachingFrameworkDatabaseSchemaService = $objectManager->get('TYPO3\\CMS\\Core\\Cache\\DatabaseSchemaService'); $tableDefinitionsCache = $cachingFrameworkDatabaseSchemaService->addCachingFrameworkRequiredDatabaseSchemaForSqlExpectedSchemaService(array()); $tblFileContent .= implode(LF, $tableDefinitionsCache[0]); } else { $tblFileContent .= \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions(); } $installClass = self::getInstallSqlClass(); $instObj = new $installClass(); $fdDb = self::getDatabaseSchema(); if ($tblFileContent) { $fileContent = implode(chr(10), $instObj->getStatementArray($tblFileContent, 1, '^CREATE TABLE ')); // just support for old version if (method_exists($installClass, 'getFieldDefinitions_fileContent') === true) { $fdFile = $instObj->getFieldDefinitions_fileContent($fileContent); } else { $fdFile = $instObj->getFieldDefinitions_sqlContent($fileContent); } $diff = $instObj->getDatabaseExtra($fdFile, $fdDb); $updateStatements = $instObj->getUpdateSuggestions($diff); $diff = $instObj->getDatabaseExtra($fdDb, $fdFile); $removeStatements = $instObj->getUpdateSuggestions($diff, 'remove'); return array('update' => $updateStatements, 'remove' => $removeStatements); } else { return array('update' => null, 'remove' => null); } }