TYPO3 CMS  TYPO3_8-7
SqlExpectedSchemaService.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
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.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
26 {
31 
36  {
37  $this->signalSlotDispatcher = $signalSlotDispatcher ?: GeneralUtility::makeInstance(Dispatcher::class);
38  }
39 
45  public function getExpectedDatabaseSchema()
46  {
48  $schemaMigrationService = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class);
49  // Raw concatenated ext_tables.sql and friends string
50  $expectedSchemaString = $this->getTablesDefinitionString();
51  // Remove comments
52  $cleanedExpectedSchemaString = implode(LF, $schemaMigrationService->getStatementArray($expectedSchemaString, true, '^CREATE TABLE '));
53  $expectedSchema = $schemaMigrationService->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
54 
55  return $expectedSchema;
56  }
57 
64  public function getTablesDefinitionString($withStatic = false)
65  {
66  $sqlString = [];
67 
68  // Find all ext_tables.sql of loaded extensions
69  $loadedExtensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
70  foreach ($loadedExtensionInformation as $extensionConfiguration) {
71  if ((is_array($extensionConfiguration) || $extensionConfiguration instanceof \ArrayAccess) && $extensionConfiguration['ext_tables.sql']) {
72  $sqlString[] = file_get_contents($extensionConfiguration['ext_tables.sql']);
73  }
74  if ($withStatic
75  && (is_array($extensionConfiguration) || $extensionConfiguration instanceof \ArrayAccess)
76  && $extensionConfiguration['ext_tables_static+adt.sql']
77  ) {
78  $sqlString[] = file_get_contents($extensionConfiguration['ext_tables_static+adt.sql']);
79  }
80  }
81 
82  $sqlString = $this->emitTablesDefinitionIsBeingBuiltSignal($sqlString);
83 
84  return implode(LF . LF . LF . LF, $sqlString);
85  }
86 
93  protected function emitTablesDefinitionIsBeingBuiltSignal(array $sqlString)
94  {
95  $signalReturn = $this->signalSlotDispatcher->dispatch(__CLASS__, 'tablesDefinitionIsBeingBuilt', [$sqlString]);
96  // This is important to support old associated returns
97  $signalReturn = array_values($signalReturn);
98  $sqlString = $signalReturn[0];
99  if (!is_array($sqlString)) {
100  throw new Exception\UnexpectedSignalReturnValueTypeException(
101  sprintf(
102  'The signal %s of class %s returned a value of type %s, but array was expected.',
103  'tablesDefinitionIsBeingBuilt',
104  __CLASS__,
105  gettype($sqlString)
106  ),
107  1476109357
108  );
109  }
110  return $sqlString;
111  }
112 }
__construct(Dispatcher $signalSlotDispatcher=null)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']