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 textfile 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 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
49 protected $signalSlotDispatcher;
52 * Get expected schema array
54 * @return array Expected schema
56 public function getExpectedDatabaseSchema() {
57 /** @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService $schemaMigrationService */
58 $schemaMigrationService = $this->objectManager
->get('TYPO3\\CMS\\Install\\Service\\SqlSchemaMigrationService');
59 // Raw concatenated ext_tables.sql and friends string
60 $expectedSchemaString = $this->getTablesDefinitionString();
62 $cleanedExpectedSchemaString = implode(LF
, $schemaMigrationService->getStatementArray($expectedSchemaString, TRUE, '^CREATE TABLE '));
63 $expectedSchema = $schemaMigrationService->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
64 return $expectedSchema;
68 * Cycle through all loaded extensions and get full table definitions as concatenated string
70 * @param boolean $withStatic TRUE if sql from ext_tables_static+adt.sql should be loaded, too.
71 * @return string Concatenated SQL of loaded extensions ext_tables.sql
73 public function getTablesDefinitionString($withStatic = FALSE) {
76 // Find all ext_tables.sql of loaded extensions
77 $loadedExtensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
78 foreach ($loadedExtensionInformation as $extensionConfiguration) {
79 if ((is_array($extensionConfiguration) ||
$extensionConfiguration instanceof \ArrayAccess
) && $extensionConfiguration['ext_tables.sql']) {
80 $sqlString[] = GeneralUtility
::getUrl($extensionConfiguration['ext_tables.sql']);
83 && (is_array($extensionConfiguration) ||
$extensionConfiguration instanceof \ArrayAccess
)
84 && $extensionConfiguration['ext_tables_static+adt.sql']
86 $sqlString[] = GeneralUtility
::getUrl($extensionConfiguration['ext_tables_static+adt.sql']);
90 $sqlString = $this->emitTablesDefinitionIsBeingBuiltSignal($sqlString);
92 return implode(LF
. LF
. LF
. LF
, $sqlString);
96 * Emits a signal to manipulate the tables definitions
98 * @param array $sqlString
101 protected function emitTablesDefinitionIsBeingBuiltSignal(array $sqlString) {
102 $signalReturn = $this->signalSlotDispatcher
->dispatch(__CLASS__
, 'tablesDefinitionIsBeingBuilt', array('sqlString' => $sqlString));
103 $sqlString = $signalReturn['sqlString'];
104 if (!is_array($sqlString)) {
105 throw new Exception\
UnexpectedSignalReturnValueTypeException(
107 'The signal %s of class %s returned a value of type %s, but array was expected.',
108 'tablesDefinitionIsBeingBuilt',