[BUGFIX] TceformsUpdateWizard shows up too often
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Service / SqlExpectedSchemaService.php
1 <?php
2 namespace TYPO3\CMS\Install\Service;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
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.
15 *
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 text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
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.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * Expected schema service
34 *
35 * @internal use in install tool only!
36 */
37 class SqlExpectedSchemaService {
38
39 /**
40 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
41 * @inject
42 */
43 protected $objectManager = NULL;
44
45 /**
46 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
47 * @inject
48 */
49 protected $signalSlotDispatcher;
50
51 /**
52 * Get expected schema array
53 *
54 * @return array Expected schema
55 */
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();
61 // Remove comments
62 $cleanedExpectedSchemaString = implode(LF, $schemaMigrationService->getStatementArray($expectedSchemaString, TRUE, '^CREATE TABLE '));
63 $expectedSchema = $schemaMigrationService->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
64 return $expectedSchema;
65 }
66
67 /**
68 * Cycle through all loaded extensions and get full table definitions as concatenated string
69 *
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
72 */
73 public function getTablesDefinitionString($withStatic = FALSE) {
74 $sqlString = array();
75
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']);
81 }
82 if ($withStatic
83 && (is_array($extensionConfiguration) || $extensionConfiguration instanceof \ArrayAccess)
84 && $extensionConfiguration['ext_tables_static+adt.sql']
85 ) {
86 $sqlString[] = GeneralUtility::getUrl($extensionConfiguration['ext_tables_static+adt.sql']);
87 }
88 }
89
90 $sqlString = $this->emitTablesDefinitionIsBeingBuiltSignal($sqlString);
91
92 return implode(LF . LF . LF . LF, $sqlString);
93 }
94
95 /**
96 * Emits a signal to manipulate the tables definitions
97 *
98 * @param array $sqlString
99 * @return mixed
100 */
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(
106 sprintf(
107 'The signal %s of class %s returned a value of type %s, but array was expected.',
108 'tablesDefinitionIsBeingBuilt',
109 __CLASS__,
110 gettype($sqlString)
111 ),
112 1382351456
113 );
114 }
115 return $sqlString;
116 }
117 }