TYPO3 CMS  TYPO3_7-6
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 
18 
25 {
29  protected $objectManager = null;
30 
35 
39  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
40  {
41  $this->objectManager = $objectManager;
42  }
43 
47  public function injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
48  {
49  $this->signalSlotDispatcher = $signalSlotDispatcher;
50  }
51 
57  public function getExpectedDatabaseSchema()
58  {
60  $schemaMigrationService = $this->objectManager->get(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class);
61  // Raw concatenated ext_tables.sql and friends string
62  $expectedSchemaString = $this->getTablesDefinitionString();
63  // Remove comments
64  $cleanedExpectedSchemaString = implode(LF, $schemaMigrationService->getStatementArray($expectedSchemaString, true, '^CREATE TABLE '));
65  $expectedSchema = $schemaMigrationService->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
66  return $expectedSchema;
67  }
68 
75  public function getTablesDefinitionString($withStatic = false)
76  {
77  $sqlString = [];
78 
79  // Find all ext_tables.sql of loaded extensions
80  $loadedExtensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
81  foreach ($loadedExtensionInformation as $extensionConfiguration) {
82  if ((is_array($extensionConfiguration) || $extensionConfiguration instanceof \ArrayAccess) && $extensionConfiguration['ext_tables.sql']) {
83  $sqlString[] = GeneralUtility::getUrl($extensionConfiguration['ext_tables.sql']);
84  }
85  if ($withStatic
86  && (is_array($extensionConfiguration) || $extensionConfiguration instanceof \ArrayAccess)
87  && $extensionConfiguration['ext_tables_static+adt.sql']
88  ) {
89  $sqlString[] = GeneralUtility::getUrl($extensionConfiguration['ext_tables_static+adt.sql']);
90  }
91  }
92 
93  $sqlString = $this->emitTablesDefinitionIsBeingBuiltSignal($sqlString);
94 
95  return implode(LF . LF . LF . LF, $sqlString);
96  }
97 
104  protected function emitTablesDefinitionIsBeingBuiltSignal(array $sqlString)
105  {
106  $signalReturn = $this->signalSlotDispatcher->dispatch(__CLASS__, 'tablesDefinitionIsBeingBuilt', [$sqlString]);
107  // This is important to support old associated returns
108  $signalReturn = array_values($signalReturn);
109  $sqlString = $signalReturn[0];
110  if (!is_array($sqlString)) {
111  throw new Exception\UnexpectedSignalReturnValueTypeException(
112  sprintf(
113  'The signal %s of class %s returned a value of type %s, but array was expected.',
114  'tablesDefinitionIsBeingBuilt',
115  __CLASS__,
116  gettype($sqlString)
117  ),
118  1382351456
119  );
120  }
121  return $sqlString;
122  }
123 }
static getUrl($url, $includeHeader=0, $requestHeaders=false, &$report=null)
injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']