2 namespace TYPO3\CMS\Install\Service
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Utility\GeneralUtility
;
20 * Expected schema service
22 * @internal use in install tool only!
24 class SqlExpectedSchemaService
{
27 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
30 protected $objectManager = NULL;
33 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
36 protected $signalSlotDispatcher;
39 * Get expected schema array
41 * @return array Expected schema
43 public function getExpectedDatabaseSchema() {
44 /** @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService $schemaMigrationService */
45 $schemaMigrationService = $this->objectManager
->get('TYPO3\\CMS\\Install\\Service\\SqlSchemaMigrationService');
46 // Raw concatenated ext_tables.sql and friends string
47 $expectedSchemaString = $this->getTablesDefinitionString();
49 $cleanedExpectedSchemaString = implode(LF
, $schemaMigrationService->getStatementArray($expectedSchemaString, TRUE, '^CREATE TABLE '));
50 $expectedSchema = $schemaMigrationService->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
51 return $expectedSchema;
55 * Cycle through all loaded extensions and get full table definitions as concatenated string
57 * @param boolean $withStatic TRUE if sql from ext_tables_static+adt.sql should be loaded, too.
58 * @return string Concatenated SQL of loaded extensions ext_tables.sql
60 public function getTablesDefinitionString($withStatic = FALSE) {
63 // Find all ext_tables.sql of loaded extensions
64 $loadedExtensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
65 foreach ($loadedExtensionInformation as $extensionConfiguration) {
66 if ((is_array($extensionConfiguration) ||
$extensionConfiguration instanceof \ArrayAccess
) && $extensionConfiguration['ext_tables.sql']) {
67 $sqlString[] = GeneralUtility
::getUrl($extensionConfiguration['ext_tables.sql']);
70 && (is_array($extensionConfiguration) ||
$extensionConfiguration instanceof \ArrayAccess
)
71 && $extensionConfiguration['ext_tables_static+adt.sql']
73 $sqlString[] = GeneralUtility
::getUrl($extensionConfiguration['ext_tables_static+adt.sql']);
77 $sqlString = $this->emitTablesDefinitionIsBeingBuiltSignal($sqlString);
79 return implode(LF
. LF
. LF
. LF
, $sqlString);
83 * Emits a signal to manipulate the tables definitions
85 * @param array $sqlString
88 protected function emitTablesDefinitionIsBeingBuiltSignal(array $sqlString) {
89 $signalReturn = $this->signalSlotDispatcher
->dispatch(__CLASS__
, 'tablesDefinitionIsBeingBuilt', array('sqlString' => $sqlString));
90 $sqlString = $signalReturn['sqlString'];
91 if (!is_array($sqlString)) {
92 throw new Exception\
UnexpectedSignalReturnValueTypeException(
94 'The signal %s of class %s returned a value of type %s, but array was expected.',
95 'tablesDefinitionIsBeingBuilt',