‪TYPO3CMS  10.4
TcaMigration.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
26 {
32  protected ‪$messages = [];
33 
47  public function ‪migrate(array ‪$tca): array
48  {
49  $this->‪validateTcaType($tca);
50 
51  ‪$tca = $this->‪migrateColumnsConfig($tca);
54  ‪$tca = $this->‪removeSelIconFieldPath($tca);
55  ‪$tca = $this->‪removeSetToDefaultOnCopy($tca);
61 
62  return ‪$tca;
63  }
64 
70  public function ‪getMessages(): array
71  {
72  return ‪$this->messages;
73  }
74 
80  protected function ‪validateTcaType(array ‪$tca)
81  {
82  foreach (‪$tca as $table => $tableDefinition) {
83  if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
84  continue;
85  }
86  foreach ($tableDefinition['columns'] as $fieldName => $fieldConfig) {
87  if (isset($fieldConfig['config']) && is_array($fieldConfig['config']) && empty($fieldConfig['config']['type'])) {
88  throw new \UnexpectedValueException(
89  'Missing "type" in TCA of field "[\'' . $table . '\'][\'' . $fieldName . '\'][\'config\']".',
90  1482394401
91  );
92  }
93  }
94  }
95  }
96 
104  protected function ‪migrateColumnsConfig(array ‪$tca): array
105  {
106  foreach (‪$tca as $table => &$tableDefinition) {
107  if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
108  continue;
109  }
110  foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
111  if ((!isset($fieldConfig['config']) || !is_array($fieldConfig['config'])) && !isset($fieldConfig['type'])) {
112  $fieldConfig['config'] = [
113  'type' => 'none',
114  ];
115  $this->messages[] = 'TCA table "' . $table . '" columns field "' . $fieldName . '"'
116  . ' had no mandatory "config" section. This has been added with default type "none":'
117  . ' TCA "' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'type\'] = \'none\'"';
118  }
119  }
120  }
121  return ‪$tca;
122  }
123 
131  protected function ‪migrateLocalizeChildrenAtParentLocalization(array ‪$tca): array
132  {
133  foreach (‪$tca as $table => &$tableDefinition) {
134  if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
135  continue;
136  }
137  foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
138  if (($fieldConfig['config']['type'] ?? null) !== 'inline') {
139  continue;
140  }
141 
142  $localizeChildrenAtParentLocalization = ($fieldConfig['config']['behaviour']['localizeChildrenAtParentLocalization'] ?? null);
143  if ($localizeChildrenAtParentLocalization === null) {
144  continue;
145  }
146 
147  if ($localizeChildrenAtParentLocalization) {
148  $this->messages[] = 'The TCA setting \'localizeChildrenAtParentLocalization\' is deprecated '
149  . ' and should be removed from TCA for ' . $table . '[\'columns\']'
150  . '[\'' . $fieldName . '\'][\'config\'][\'behaviour\'][\'localizeChildrenAtParentLocalization\']';
151  } else {
152  $this->messages[] = 'The TCA setting \'localizeChildrenAtParentLocalization\' is deprecated '
153  . ', as this functionality is always enabled. The option should be removed from TCA for '
154  . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'behaviour\']'
155  . '[\'localizeChildrenAtParentLocalization\']';
156  }
157  unset($fieldConfig['config']['behaviour']['localizeChildrenAtParentLocalization']);
158  }
159  }
160  return ‪$tca;
161  }
162 
169  protected function ‪migratePagesLanguageOverlayRemoval(array ‪$tca)
170  {
171  if (isset(‪$tca['pages_language_overlay'])) {
172  $this->messages[] = 'The TCA table \'pages_language_overlay\' is'
173  . ' not used anymore and has been removed automatically in'
174  . ' order to avoid negative side-effects.'
175  . ' To ensure migration is possible, a definition still exists in sysext:frontend.'
176  . ' Check your extensions for additional definitions, those need to be removed.'
177  . ' You can ignore this message, when only the core definition still exists.'
178  ;
179  unset(‪$tca['pages_language_overlay']);
180  }
181  return ‪$tca;
182  }
183 
190  protected function ‪removeEnableMultiSelectFilterTextfieldConfiguration(array ‪$tca): array
191  {
192  foreach (‪$tca as $table => &$tableDefinition) {
193  if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
194  continue;
195  }
196  foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
197  if (!isset($fieldConfig['config']['enableMultiSelectFilterTextfield'])) {
198  continue;
199  }
200 
201  $this->messages[] = 'The TCA setting \'enableMultiSelectFilterTextfield\' is deprecated '
202  . ' and should be removed from TCA for ' . $table . '[\'columns\']'
203  . '[\'' . $fieldName . '\'][\'config\'][\'enableMultiSelectFilterTextfield\']';
204  unset($fieldConfig['config']['enableMultiSelectFilterTextfield']);
205  }
206  }
207  return ‪$tca;
208  }
209 
216  protected function ‪removeSelIconFieldPath(array ‪$tca): array
217  {
218  foreach (‪$tca as $table => &$configuration) {
219  if (isset($configuration['ctrl']['selicon_field_path'])) {
220  $this->messages[] = 'The TCA table \'' . $table . '\' defines '
221  . '[ctrl][selicon_field_path] which should be removed from TCA, '
222  . 'as it is not in use anymore.';
223  unset($configuration['ctrl']['selicon_field_path']);
224  }
225  }
226  return $tca;
227  }
228 
235  protected function removeSetToDefaultOnCopy(array $tca): array
236  {
237  foreach ($tca as $table => &$configuration) {
238  if (isset($configuration['ctrl']['setToDefaultOnCopy'])) {
239  $this->messages[] = 'The TCA table \'' . $table . '\' defines '
240  . '[ctrl][setToDefaultOnCopy] which should be removed from TCA, '
241  . 'as it is not in use anymore.';
242  unset($configuration['ctrl']['setToDefaultOnCopy']);
243  }
244  }
245  return $tca;
246  }
247 
260  protected function sanitizeControlSectionIntegrity(array $tca): array
261  {
262  $controlSectionNames = [
263  'origUid',
264  'languageField',
265  'transOrigPointerField',
266  'translationSource'
267  ];
268  foreach ($tca as $tableName => &$configuration) {
269  foreach ($controlSectionNames as $controlSectionName) {
270  $columnName = $configuration['ctrl'][$controlSectionName] ?? null;
271  if (empty($columnName) || !empty($configuration['columns'][$columnName])) {
272  continue;
273  }
274  $configuration['columns'][$columnName] = [
275  'config' => [
276  'type' => 'passthrough',
277  'default' => 0,
278  ],
279  ];
280  }
281  }
282  return $tca;
283  }
284 
292  protected function removeExcludeFieldForTransOrigPointerField(array $tca): array
293  {
294  foreach ($tca as $table => &$configuration) {
295  if (isset($configuration['ctrl']['transOrigPointerField'],
296  $configuration['columns'][$configuration['ctrl']['transOrigPointerField']]['exclude'])
297  ) {
298  $this->messages[] = 'The \'' . $table . '\' TCA tables transOrigPointerField '
299  . '\'' . $configuration['ctrl']['transOrigPointerField'] . '\' is defined '
300  . ' as excluded field which is no longer needed and should therefore be removed. ';
301  unset($configuration['columns'][$configuration['ctrl']['transOrigPointerField']]['exclude']);
302  }
303  }
304 
305  return $tca;
306  }
307 
315  protected function removeShowRecordFieldListField(array $tca): array
316  {
317  foreach ($tca as $table => &$configuration) {
318  if (!isset($configuration['interface']['showRecordFieldList'])) {
319  continue;
320  }
321  $this->messages[] = 'The \'' . $table . '\' TCA configuration \'showRecordFieldList\''
322  . ' inside the section \'interface\' is not evaluated anymore and should therefore be removed.';
323  unset($configuration['interface']['showRecordFieldList']);
324  if ($configuration['interface'] === []) {
325  unset($configuration['interface']);
326  }
327  }
328 
329  return ‪$tca;
330  }
331 
340  {
341  foreach (‪$tca as $table => $tableDefinition) {
342  if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
343  continue;
344  }
345 
346  foreach ($tableDefinition['columns'] as $fieldName => $fieldConfig) {
347  if (($fieldConfig['config']['type'] ?? '') !== 'select' || ($fieldConfig['config']['authMode'] ?? '') !== 'individual') {
348  continue;
349  }
350 
351  foreach ($fieldConfig['config']['items'] ?? [] as $index => $item) {
352  if (in_array($item[4] ?? '', ['EXPL_ALLOW', 'EXPL_DENY'], true)) {
353  ‪$tca[$table]['columns'][$fieldName]['config']['items'][$index][5] = $item[4];
354  ‪$tca[$table]['columns'][$fieldName]['config']['items'][$index][4] = '';
355 
356  // This migration does not log any message
357  }
358  }
359  }
360  }
361 
362  return ‪$tca;
363  }
364 }
‪TYPO3\CMS\Core\Migrations\TcaMigration\removeExcludeFieldForTransOrigPointerField
‪array removeExcludeFieldForTransOrigPointerField(array $tca)
Definition: TcaMigration.php:291
‪TYPO3\CMS\Core\Migrations\TcaMigration
Definition: TcaMigration.php:26
‪TYPO3\CMS\Core\Migrations\TcaMigration\migrateSelectAuthModeIndividualItemsKeywordToNewPosition
‪array migrateSelectAuthModeIndividualItemsKeywordToNewPosition(array $tca)
Definition: TcaMigration.php:338
‪TYPO3\CMS\Core\Migrations\TcaMigration\migrate
‪array migrate(array $tca)
Definition: TcaMigration.php:46
‪TYPO3\CMS\Core\Migrations\TcaMigration\migrateColumnsConfig
‪array migrateColumnsConfig(array $tca)
Definition: TcaMigration.php:103
‪TYPO3\CMS\Core\Migrations\TcaMigration\sanitizeControlSectionIntegrity
‪array sanitizeControlSectionIntegrity(array $tca)
Definition: TcaMigration.php:259
‪TYPO3\CMS\Core\Migrations\TcaMigration\getMessages
‪array getMessages()
Definition: TcaMigration.php:69
‪TYPO3\CMS\Core\Migrations\TcaMigration\$messages
‪array $messages
Definition: TcaMigration.php:31
‪TYPO3\CMS\Core\Migrations\TcaMigration\removeShowRecordFieldListField
‪array removeShowRecordFieldListField(array $tca)
Definition: TcaMigration.php:314
‪TYPO3\CMS\Core\Migrations\TcaMigration\validateTcaType
‪validateTcaType(array $tca)
Definition: TcaMigration.php:79
‪TYPO3\CMS\Core\Migrations\TcaMigration\removeSelIconFieldPath
‪array removeSelIconFieldPath(array $tca)
Definition: TcaMigration.php:215
‪TYPO3\CMS\Core\Migrations
Definition: TcaMigration.php:18
‪TYPO3\CMS\Core\Migrations\TcaMigration\removeSetToDefaultOnCopy
‪array removeSetToDefaultOnCopy(array $tca)
Definition: TcaMigration.php:234
‪TYPO3\CMS\Core\Migrations\TcaMigration\migrateLocalizeChildrenAtParentLocalization
‪array migrateLocalizeChildrenAtParentLocalization(array $tca)
Definition: TcaMigration.php:130
‪$tca
‪$tca
Definition: sys_file_metadata.php:5
‪TYPO3\CMS\Core\Migrations\TcaMigration\migratePagesLanguageOverlayRemoval
‪array migratePagesLanguageOverlayRemoval(array $tca)
Definition: TcaMigration.php:168
‪TYPO3\CMS\Core\Migrations\TcaMigration\removeEnableMultiSelectFilterTextfieldConfiguration
‪array removeEnableMultiSelectFilterTextfieldConfiguration(array $tca)
Definition: TcaMigration.php:189