[BUGFIX] Check in TcaMigration if the type is set 17/51017/4
authorGeorg Ringer <georg.ringer@gmail.com>
Thu, 22 Dec 2016 08:30:51 +0000 (09:30 +0100)
committerJan Helke <typo3@helke.de>
Wed, 4 Jan 2017 11:35:53 +0000 (12:35 +0100)
The type field is essential for TCA and must be checked if available.

Resolves: #79059
Releases: master
Change-Id: I6b5a94db0372e25a18ecb21a3966cece8cc9f207
Reviewed-on: https://review.typo3.org/51017
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/core/Classes/Migrations/TcaMigration.php
typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php

index dc4ab3f..463afe3 100644 (file)
@@ -31,7 +31,12 @@ class TcaMigration
     protected $messages = [];
 
     /**
-     * Migrate old TCA to new TCA.
+     * Run some general TCA validations, then migrate old TCA to new TCA.
+     *
+     * This class is typically called within bootstrap with empty caches after all TCA
+     * files from extensions have been loaded. The migration is then applied and
+     * the migrated result is cached.
+     * For flex form TCA, this class is called dynamically if opening a record in the backend.
      *
      * See unit tests for details.
      *
@@ -40,6 +45,8 @@ class TcaMigration
      */
     public function migrate(array $tca)
     {
+        $this->validateTcaType($tca);
+
         $tca = $this->migrateT3editorWizardToRenderTypeT3editorIfNotEnabledByTypeConfig($tca);
         $tca = $this->migrateSpecialConfigurationAndRemoveShowItemStylePointerConfig($tca);
         $tca = $this->migrateT3editorWizardWithEnabledByTypeConfigToColumnsOverrides($tca);
@@ -74,6 +81,28 @@ class TcaMigration
     }
 
     /**
+     * Check for required TCA configuration
+     *
+     * @param array $tca Incoming TCA
+     */
+    protected function validateTcaType(array $tca)
+    {
+        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']) && empty($fieldConfig['config']['type'])) {
+                    throw new \UnexpectedValueException(
+                        'Missing "type" in TCA of field "[\'' . $table . '\'][\'' . $fieldName . '\'][\'config\']".',
+                        1482394401
+                    );
+                }
+            }
+        }
+    }
+
+    /**
      * Migrate type=text field with t3editor wizard to renderType=t3editor without this wizard
      *
      * @param array $tca Incoming TCA
index d05ef95..0f077a3 100644 (file)
@@ -24,6 +24,36 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
     /**
      * @test
      */
+    public function missingTypeThrowsException()
+    {
+        $input = [
+            'aTable' => [
+                'columns' => [
+                    'field_a' => [
+                        'label' => 'aLabel',
+                        'config' => [
+                            'type' => 'text',
+                        ],
+                    ],
+                    'field_b' => [
+                        'label' => 'bLabel',
+                        'config' => [
+                            'rows' => 42,
+                            'wizards' => []
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $this->expectException(\RuntimeException::class);
+        $this->expectExceptionCode(1482394401);
+        $subject = new TcaMigration();
+        $subject->migrate($input);
+    }
+
+    /**
+     * @test
+     */
     public function migrateReturnsGivenArrayUnchangedIfNoMigrationNeeded()
     {
         $input = $expected = [
@@ -427,6 +457,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                 'columns' => [
                     'bodytext' => [
                         'config' => [
+                            'type' => 'text',
                             'wizards' => [
                                 't3editorHtml' => [
                                     'icon' => 'wizard_table.gif',
@@ -443,6 +474,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                 'columns' => [
                     'bodytext' => [
                         'config' => [
+                            'type' => 'text',
                             'wizards' => [
                                 't3editorHtml' => [
                                     'icon' => 'content-table',
@@ -989,6 +1021,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                 'columns' => [
                     'aCol' => [
                         'config' => [
+                            'type' => 'input',
                             'wizards' => [
                                 'link' => [
                                     'module' => [
@@ -1009,6 +1042,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                 'columns' => [
                     'aCol' => [
                         'config' => [
+                            'type' => 'input',
                             'wizards' => [
                                 'link' => [
                                     'module' => [
@@ -1395,6 +1429,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                 'columns' => [
                     'aCol' => [
                         'config' => [
+                            'type' => 'input',
                             'wizards' => [
                                 'colorpicker' => [
                                     'type' => 'colorbox',
@@ -1415,6 +1450,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                 'columns' => [
                     'aCol' => [
                         'config' => [
+                            'type' => 'input',
                             'renderType' => 'colorpicker',
                         ],
                     ],
@@ -1439,6 +1475,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'config' => [
+                                    'type' => 'select',
                                     'renderType' => 'selectTree',
                                     'treeConfig' => [
                                         'appearance' => [
@@ -1456,6 +1493,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'config' => [
+                                    'type' => 'select',
                                     'renderType' => 'selectTree',
                                     'treeConfig' => [
                                         'appearance' => [
@@ -1474,6 +1512,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'config' => [
+                                    'type' => 'select',
                                     'renderType' => 'selectTree',
                                     'treeConfig' => [
                                         'appearance' => [
@@ -1492,6 +1531,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'config' => [
+                                    'type' => 'select',
                                     'renderType' => 'selectTree',
                                     'treeConfig' => [
                                         'appearance' => [
@@ -1511,6 +1551,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'config' => [
+                                    'type' => 'select',
                                     'renderType' => 'selectTree',
                                     'autoSizeMax' => 20,
                                     'size' => 10
@@ -1525,6 +1566,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'config' => [
+                                    'type' => 'select',
                                     'renderType' => 'selectTree',
                                     'size' => 20
                                 ]
@@ -1540,6 +1582,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'config' => [
+                                    'type' => 'select',
                                     'renderType' => 'not a select tree',
                                     'autoSizeMax' => 20,
                                     'size' => 10,
@@ -1561,6 +1604,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'config' => [
+                                    'type' => 'select',
                                     'renderType' => 'not a select tree',
                                     'autoSizeMax' => 20,
                                     'size' => 10,
@@ -1601,6 +1645,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aCol' => [
                                 'config' => [
+                                    'type' => 'input',
                                     'softref' => 'email,somethingelse'
                                 ],
                             ],
@@ -1612,6 +1657,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aCol' => [
                                 'config' => [
+                                    'type' => 'input',
                                     'softref' => 'email,somethingelse',
                                 ],
                             ],
@@ -1625,6 +1671,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aCol' => [
                                 'config' => [
+                                    'type' => 'input',
                                     'softref' => 'TStemplate,somethingelse'
                                 ],
                             ],
@@ -1636,6 +1683,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aCol' => [
                                 'config' => [
+                                    'type' => 'input',
                                     'softref' => 'somethingelse',
                                 ],
                             ],
@@ -1649,6 +1697,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aCol' => [
                                 'config' => [
+                                    'type' => 'input',
                                     'softref' => 'TStemplate,somethingelse,TSconfig'
                                 ],
                             ],
@@ -1660,6 +1709,7 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aCol' => [
                                 'config' => [
+                                    'type' => 'input',
                                     'softref' => 'somethingelse',
                                 ],
                             ],
@@ -1929,7 +1979,9 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'label' => 'foo',
-                                'config' => [],
+                                'config' => [
+                                    'type' => 'input',
+                                ],
                             ],
                         ],
                     ],
@@ -1940,7 +1992,9 @@ class TcaMigrationTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
                         'columns' => [
                             'aField' => [
                                 'label' => 'foo',
-                                'config' => [],
+                                'config' => [
+                                    'type' => 'input',
+                                ],
                                 'onChange' => 'reload',
                             ],
                         ],