[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Service / SqlExpectedSchemaService.php
1 <?php
2 namespace TYPO3\CMS\Install\Service;
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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * Expected schema service
21 *
22 * @internal use in install tool only!
23 */
24 class SqlExpectedSchemaService {
25
26 /**
27 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
28 * @inject
29 */
30 protected $objectManager = NULL;
31
32 /**
33 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
34 * @inject
35 */
36 protected $signalSlotDispatcher;
37
38 /**
39 * Get expected schema array
40 *
41 * @return array Expected schema
42 */
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();
48 // Remove comments
49 $cleanedExpectedSchemaString = implode(LF, $schemaMigrationService->getStatementArray($expectedSchemaString, TRUE, '^CREATE TABLE '));
50 $expectedSchema = $schemaMigrationService->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
51 return $expectedSchema;
52 }
53
54 /**
55 * Cycle through all loaded extensions and get full table definitions as concatenated string
56 *
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
59 */
60 public function getTablesDefinitionString($withStatic = FALSE) {
61 $sqlString = array();
62
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']);
68 }
69 if ($withStatic
70 && (is_array($extensionConfiguration) || $extensionConfiguration instanceof \ArrayAccess)
71 && $extensionConfiguration['ext_tables_static+adt.sql']
72 ) {
73 $sqlString[] = GeneralUtility::getUrl($extensionConfiguration['ext_tables_static+adt.sql']);
74 }
75 }
76
77 $sqlString = $this->emitTablesDefinitionIsBeingBuiltSignal($sqlString);
78
79 return implode(LF . LF . LF . LF, $sqlString);
80 }
81
82 /**
83 * Emits a signal to manipulate the tables definitions
84 *
85 * @param array $sqlString
86 * @return mixed
87 */
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(
93 sprintf(
94 'The signal %s of class %s returned a value of type %s, but array was expected.',
95 'tablesDefinitionIsBeingBuilt',
96 __CLASS__,
97 gettype($sqlString)
98 ),
99 1382351456
100 );
101 }
102 return $sqlString;
103 }
104 }