[TASK] All TCA columns should have a config section 57/54857/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 29 Nov 2017 11:31:18 +0000 (12:31 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 29 Nov 2017 18:55:54 +0000 (19:55 +0100)
Having a TCA columns field without 'config' array doesn't make
sense. ['config']['type'] is marked as mandatory field anyway
and the TCA migration throws an exception if ['config'] exists
but ['type'] is missing for a while.
The patch now adds code to add ['config']['type'] = 'none' if
['config'] does not exist at all.

Change-Id: I18b9a9866f16ca3ba5750ec2970436282aa01719
Resolves: #83152
Releases: master
Reviewed-on: https://review.typo3.org/54857
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Migrations/TcaMigration.php
typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php

index 2add591..dd1df11 100644 (file)
@@ -48,6 +48,7 @@ class TcaMigration
     {
         $this->validateTcaType($tca);
 
+        $tca = $this->migrateColumnsConfig($tca);
         $tca = $this->migrateT3editorWizardToRenderTypeT3editorIfNotEnabledByTypeConfig($tca);
         $tca = $this->migrateSpecialConfigurationAndRemoveShowItemStylePointerConfig($tca);
         $tca = $this->migrateT3editorWizardWithEnabledByTypeConfigToColumnsOverrides($tca);
@@ -125,6 +126,33 @@ class TcaMigration
     }
 
     /**
+     * Find columns fields that don't have a 'config' section at all, add
+     * ['config']['type'] = 'none'; for those to enforce config
+     *
+     * @param array $tca Incoming TCA
+     * @return array
+     */
+    protected function migrateColumnsConfig(array $tca): array
+    {
+        foreach ($tca as $table => &$tableDefinition) {
+            if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
+                continue;
+            }
+            foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
+                if ((!isset($fieldConfig['config']) || !is_array($fieldConfig['config'])) && !isset($fieldConfig['type'])) {
+                    $fieldConfig['config'] = [
+                        'type' => 'none',
+                    ];
+                    $this->messages[] = 'TCA table "' . $table . '" columns field "' . $fieldName . '"'
+                        . ' had no mandatory "config" section. This has been added with default type "none":'
+                        . ' TCA "' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'type\'] = \'none\'"';
+                }
+            }
+        }
+        return $tca;
+    }
+
+    /**
      * Migrate type=text field with t3editor wizard to renderType=t3editor without this wizard
      *
      * @param array $tca Incoming TCA
index 4879e42..d0fe5ab 100644 (file)
@@ -84,6 +84,61 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
+    public function migrateAddsMissingColumnsConfig()
+    {
+        $input = [
+            'aTable' => [
+                'columns' => [
+                    'aField' => [
+                        'exclude' => true,
+                    ],
+                    'bField' => [
+                    ],
+                    'cField' => [
+                        'config' => 'i am a string but should be an array',
+                    ],
+                    'dField' => [
+                        // This kept as is, 'config' is not added. This is relevant
+                        // for "flex" data structure arrays with section containers
+                        // that have 'type'=>'array' on this level and an 'el' sub array
+                        // with details.
+                        'type' => 'array',
+                    ],
+                ]
+            ],
+        ];
+        $expected = [
+            'aTable' => [
+                'columns' => [
+                    'aField' => [
+                        'exclude' => true,
+                        'config' => [
+                            'type' => 'none',
+                        ],
+                    ],
+                    'bField' => [
+                        'config' => [
+                            'type' => 'none',
+                        ],
+                    ],
+                    'cField' => [
+                        'config' => [
+                            'type' => 'none',
+                        ],
+                    ],
+                    'dField' => [
+                        'type' => 'array',
+                    ],
+                ],
+            ],
+        ];
+        $subject = new TcaMigration();
+        $this->assertEquals($expected, $subject->migrate($input));
+    }
+
+    /**
+     * @test
+     */
     public function migrateChangesT3editorWizardToT3editorRenderTypeIfNotEnabledByTypeConfig()
     {
         $input = [
@@ -212,6 +267,9 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                 'columns' => [
                     'anotherField' => [
                         'defaultExtras' => 'nowrap',
+                        'config' => [
+                            'type' => 'text',
+                        ],
                     ],
                 ],
                 'types' => [
@@ -227,6 +285,7 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                     'anotherField' => [
                         'config' => [
                             'wrap' => 'off',
+                            'type' => 'text',
                         ],
                     ],
                 ],
@@ -411,6 +470,9 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             'aTable' => [
                 'columns' => [
                     'anotherField' => [
+                        'config' => [
+                            'type' => 'text',
+                        ],
                     ],
                 ],
                 'types' => [
@@ -2094,6 +2156,9 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                         'columns' => [
                             'aColumn' => [
                                 'l10n_mode' => 'noCopy',
+                                'config' => [
+                                    'type' => 'text',
+                                ],
                             ],
                         ],
                     ],
@@ -2102,6 +2167,9 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                     'aTable' => [
                         'columns' => [
                             'aColumn' => [
+                                'config' => [
+                                    'type' => 'text',
+                                ],
                             ],
                         ],
                     ],
@@ -2113,6 +2181,9 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                         'columns' => [
                             'aColumn' => [
                                 'l10n_mode' => 'mergeIfNotBlank',
+                                'config' => [
+                                    'type' => 'text',
+                                ],
                             ],
                         ],
                     ],
@@ -2122,6 +2193,7 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                         'columns' => [
                             'aColumn' => [
                                 'config' => [
+                                    'type' => 'text',
                                     'behaviour' => [
                                         'allowLanguageSynchronization' => true,
                                     ]
@@ -2226,66 +2298,6 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                     ],
                 ]
             ],
-            'superfluous l10n_mode' => [
-                [
-                    'pages' => [
-                        'columns' => [
-                            'aColumn' => [],
-                        ],
-                    ],
-                    'pages_language_overlay' => [
-                        'columns' => [
-                            'aColumn' => [
-                                'config' => [
-                                    'type' => 'input',
-                                ],
-                                'l10n_mode' => 'any-possible-value',
-                            ],
-                        ],
-                    ],
-                ],
-                [
-                    'pages' => [
-                        'columns' => [
-                            'aColumn' => [],
-                        ],
-                    ],
-                ]
-            ],
-            'superfluous allowLanguageSynchronization' => [
-                [
-                    'pages' => [
-                        'columns' => [
-                            'aColumn' => [],
-                        ],
-                    ],
-                    'pages_language_overlay' => [
-                        'columns' => [
-                            'aColumn' => [
-                                'config' => [
-                                    'type' => 'input',
-                                    'behaviour' => [
-                                        'allowLanguageSynchronization' => true,
-                                    ]
-                                ],
-                            ],
-                        ],
-                    ],
-                ],
-                [
-                    'pages' => [
-                        'columns' => [
-                            'aColumn' => [
-                                'config' => [
-                                    'behaviour' => [
-                                        'allowLanguageSynchronization' => true,
-                                    ]
-                                ],
-                            ],
-                        ],
-                    ],
-                ]
-            ],
         ];
     }
 
@@ -2458,8 +2470,16 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                             'requestUpdate' => 'aField, bField, cField, ',
                         ],
                         'columns' => [
-                            'aField' => [],
-                            'cField' => [],
+                            'aField' => [
+                                'config' => [
+                                    'type' => 'none',
+                                ],
+                            ],
+                            'cField' => [
+                                'config' => [
+                                    'type' => 'none',
+                                ],
+                            ],
                         ],
                     ],
                 ],
@@ -2468,9 +2488,15 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                         'ctrl' => [],
                         'columns' => [
                             'aField' => [
+                                'config' => [
+                                    'type' => 'none',
+                                ],
                                 'onChange' => 'reload',
                             ],
                             'cField' => [
+                                'config' => [
+                                    'type' => 'none',
+                                ],
                                 'onChange' => 'reload',
                             ],
                         ],