[BUGFIX] Class references to SqlExpectedSchemaService
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / DataHandling / DatabaseSchemaService.php
1 <?php
2 namespace TYPO3\CMS\Core\DataHandling;
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 /**
18 * This service provides the sql schema database records.
19 */
20 class DatabaseSchemaService
21 {
22 const TABLE_TEMPLATE = 'CREATE TABLE %s (' . LF . '%s' . LF . ');';
23 const FIELD_L10N_STATE_TEMPLATE = ' l10n_state text';
24
25 /**
26 * Add l10n_state field to tables that provide localization
27 *
28 * @param array $sqlString Current SQL statements to be executed
29 * @return array Modified arguments of SqlReader::tablesDefinitionIsBeingBuilt signal
30 */
31 public function getLocalizationRequiredDatabaseSchema(array $sqlString)
32 {
33 $additionalSqlString = $this->buildLocalizationRequiredDatabaseSchema();
34 if (!empty($additionalSqlString)) {
35 $sqlString[] = $additionalSqlString;
36 }
37 return ['sqlString' => $sqlString];
38 }
39
40 /**
41 * Add l10n_state field to tables that provide localization
42 *
43 * @param array $sqlString Current SQL statements to be executed
44 * @param string $extensionKey Extension key currently processed
45 * @return array Modified arguments of InstallUtility::tablesDefinitionIsBeingBuilt signal
46 */
47 public function getLocalizationRequiredDatabaseSchemaForExtension(array $sqlString, string $extensionKey)
48 {
49 $additionalSqlString = $this->buildLocalizationRequiredDatabaseSchema();
50 if (!empty($additionalSqlString)) {
51 $sqlString[] = $additionalSqlString;
52 }
53 return ['sqlString' => $sqlString, 'extensionKey' => $extensionKey];
54 }
55
56 /**
57 * Add l10n_state field to tables that provide localization
58 *
59 * @return string Localization fields database schema
60 */
61 protected function buildLocalizationRequiredDatabaseSchema()
62 {
63 $tableSchemas = [];
64
65 foreach ($GLOBALS['TCA'] as $tableName => $tableDefinition) {
66 if (
67 empty($tableDefinition['columns'])
68 || empty($tableDefinition['ctrl']['languageField'])
69 || empty($tableDefinition['ctrl']['transOrigPointerField'])
70 ) {
71 continue;
72 }
73
74 $fieldSchemas = [];
75 $fieldSchemas[] = static::FIELD_L10N_STATE_TEMPLATE;
76
77 $tableSchemas[] = sprintf(
78 static::TABLE_TEMPLATE,
79 $tableName,
80 implode(',' . LF, $fieldSchemas)
81 );
82 }
83
84 return implode(LF, $tableSchemas);
85 }
86 }