From fc399718a8583cd8f2c535a9b2e0c7e26fdadfa7 Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Thu, 21 Sep 2023 16:51:20 +0200 Subject: [PATCH] [FEATURE] Auto DB fields from TCA for type "flex" Tables with TCA columns set to type="flex" do not need an ext_tables.sql entry anymore. The core now creates this field automatically. This is one of many patches in this area: The v13 goal is to obsolete ext_tables.sql in most cases by creating default "business" fields of TCA tables automatically. The patch adds the main magic in class DefaultTcaSchema and removes own ext_tables.sql definitions having type=flex. Resolves: #101997 Related: #101553 Releases: main Change-Id: Ide5458994cfbfca0113be08b0e87b51babaeb540 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81158 Reviewed-by: Nikita Hovratov <nikita.h@live.de> Tested-by: Nikita Hovratov <nikita.h@live.de> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: core-ci <typo3@b13.com> --- .../Database/Schema/DefaultTcaSchema.php | 30 ++++++++++++++----- ...1553-Auto-createDBFieldsFromTCAColumns.rst | 1 + .../ext_tables.sql | 1 - .../test_irre_foreignfield/ext_tables.sql | 3 +- .../ext_tables.sql | 3 +- .../test_select_flex_mm/ext_tables.sql | 1 - .../Database/Schema/DefaultTcaSchemaTest.php | 22 ++++++++++++++ typo3/sysext/core/ext_tables.sql | 1 - typo3/sysext/frontend/ext_tables.sql | 1 - ...ewImportPageAndRecordsByUpdateWithDiff.php | 2 +- ...pages-and-ttcontent-with-corrupt-image.xml | 12 ++++---- ...-ttcontent-with-image-but-not-included.xml | 12 ++++---- .../pages-and-ttcontent-with-image.xml | 12 ++++---- 13 files changed, 67 insertions(+), 34 deletions(-) diff --git a/typo3/sysext/core/Classes/Database/Schema/DefaultTcaSchema.php b/typo3/sysext/core/Classes/Database/Schema/DefaultTcaSchema.php index ef07cb103a47..3cf480c5b344 100644 --- a/typo3/sysext/core/Classes/Database/Schema/DefaultTcaSchema.php +++ b/typo3/sysext/core/Classes/Database/Schema/DefaultTcaSchema.php @@ -657,7 +657,7 @@ class DefaultTcaSchema } $tables[$tablePosition]->addColumn( $this->quote($fieldName), - 'integer', + Types::INTEGER, [ 'default' => 0, 'notnull' => true, @@ -676,23 +676,39 @@ class DefaultTcaSchema if (isset($fieldConfig['config']['MM'])) { $tables[$tablePosition]->addColumn( $this->quote($fieldName), - 'integer', + Types::INTEGER, [ - 'default' => 0, - 'notnull' => true, - 'unsigned' => true, - ] + 'default' => 0, + 'notnull' => true, + 'unsigned' => true, + ] ); } else { $tables[$tablePosition]->addColumn( $this->quote($fieldName), - 'text', + Types::TEXT, [ 'notnull' => false, ] ); } } + + // Add fields for all tables, defining flex columns (TCA type=flex) + foreach ($tableDefinition['columns'] as $fieldName => $fieldConfig) { + if ((string)($fieldConfig['config']['type'] ?? '') !== 'flex' + || $this->isColumnDefinedForTable($tables, $tableName, $fieldName) + ) { + continue; + } + $tables[$tablePosition]->addColumn( + $this->quote($fieldName), + Types::TEXT, + [ + 'notnull' => false, + ] + ); + } } return $tables; diff --git a/typo3/sysext/core/Documentation/Changelog/13.0/Feature-101553-Auto-createDBFieldsFromTCAColumns.rst b/typo3/sysext/core/Documentation/Changelog/13.0/Feature-101553-Auto-createDBFieldsFromTCAColumns.rst index 7659ea870cfe..a79f14f18487 100644 --- a/typo3/sysext/core/Documentation/Changelog/13.0/Feature-101553-Auto-createDBFieldsFromTCAColumns.rst +++ b/typo3/sysext/core/Documentation/Changelog/13.0/Feature-101553-Auto-createDBFieldsFromTCAColumns.rst @@ -60,6 +60,7 @@ Columns are auto-created for these :php:`TCA` :php:`columns` types: * :php:`type = 'imageManipulation'` - new with core v13 * :php:`type = 'language'` - new with core v13 * :php:`type = 'group'` - new with core v13 +* :php:`type = 'flex'` - new with core v13 .. index:: TCA, ext:core, NotScanned diff --git a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_flex_section_container/ext_tables.sql b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_flex_section_container/ext_tables.sql index 8ab428b27c46..be29bbaef777 100644 --- a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_flex_section_container/ext_tables.sql +++ b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_flex_section_container/ext_tables.sql @@ -1,3 +1,2 @@ CREATE TABLE tx_testflexsectioncontainer ( - flex_1 text ); diff --git a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield/ext_tables.sql b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield/ext_tables.sql index 22b73e7c28fe..559f397cf6a2 100644 --- a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield/ext_tables.sql +++ b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield/ext_tables.sql @@ -37,6 +37,5 @@ CREATE TABLE pages CREATE TABLE tt_content ( - tx_testirreforeignfield_hotels int(11) DEFAULT '0' NOT NULL, - tx_testirreforeignfield_flexform mediumtext + tx_testirreforeignfield_hotels int(11) DEFAULT '0' NOT NULL ); diff --git a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield_non_ws/ext_tables.sql b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield_non_ws/ext_tables.sql index efcf797153a7..4529c6e08d7c 100644 --- a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield_non_ws/ext_tables.sql +++ b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield_non_ws/ext_tables.sql @@ -32,6 +32,5 @@ CREATE TABLE pages CREATE TABLE tt_content ( - tx_testirreforeignfieldnonws_hotels int(11) DEFAULT '0' NOT NULL, - tx_testirreforeignfieldnonws_flexform mediumtext + tx_testirreforeignfieldnonws_hotels int(11) DEFAULT '0' NOT NULL ); diff --git a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_select_flex_mm/ext_tables.sql b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_select_flex_mm/ext_tables.sql index 61fdaf982d1f..5b20d63c063d 100644 --- a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_select_flex_mm/ext_tables.sql +++ b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_select_flex_mm/ext_tables.sql @@ -1,5 +1,4 @@ CREATE TABLE tx_testselectflexmm_local ( - flex_1 text ); # MM tables for fields defined in flex form data structures diff --git a/typo3/sysext/core/Tests/Unit/Database/Schema/DefaultTcaSchemaTest.php b/typo3/sysext/core/Tests/Unit/Database/Schema/DefaultTcaSchemaTest.php index fafb77559441..e58d88cb905b 100644 --- a/typo3/sysext/core/Tests/Unit/Database/Schema/DefaultTcaSchemaTest.php +++ b/typo3/sysext/core/Tests/Unit/Database/Schema/DefaultTcaSchemaTest.php @@ -1170,4 +1170,26 @@ final class DefaultTcaSchemaTest extends UnitTestCase ); self::assertSame($expectedColumn->toArray(), $result[0]->getColumn('groupWithMM')->toArray()); } + + /** + * @test + */ + public function enrichAddsFlex(): void + { + $GLOBALS['TCA']['aTable']['columns']['flex'] = [ + 'label' => 'aLabel', + 'config' => [ + 'type' => 'flex', + ], + ]; + $result = $this->subject->enrich([$this->defaultTable]); + $expectedColumn = new Column( + '`flex`', + Type::getType('text'), + [ + 'notnull' => false, + ] + ); + self::assertSame($expectedColumn->toArray(), $result[0]->getColumn('flex')->toArray()); + } } diff --git a/typo3/sysext/core/ext_tables.sql b/typo3/sysext/core/ext_tables.sql index 0288286cf405..8037f185e5da 100644 --- a/typo3/sysext/core/ext_tables.sql +++ b/typo3/sysext/core/ext_tables.sql @@ -145,7 +145,6 @@ CREATE TABLE sys_filemounts ( CREATE TABLE sys_file_storage ( name varchar(255) DEFAULT '' NOT NULL, driver tinytext, - configuration text, is_public tinyint(4) DEFAULT '0' NOT NULL, processingfolder tinytext ); diff --git a/typo3/sysext/frontend/ext_tables.sql b/typo3/sysext/frontend/ext_tables.sql index 66d5cc1e2e38..2f28d7950a7c 100644 --- a/typo3/sysext/frontend/ext_tables.sql +++ b/typo3/sysext/frontend/ext_tables.sql @@ -106,7 +106,6 @@ CREATE TABLE tt_content ( target varchar(30) DEFAULT '' NOT NULL, recursive tinyint(3) unsigned DEFAULT '0' NOT NULL, imageheight mediumint(8) unsigned DEFAULT '0' NOT NULL, - pi_flexform mediumtext, accessibility_title varchar(30) DEFAULT '' NOT NULL, accessibility_bypass_text varchar(30) DEFAULT '' NOT NULL, category_field varchar(64) DEFAULT '' NOT NULL, diff --git a/typo3/sysext/impexp/Tests/Functional/Fixtures/ArrayAssertions/RenderPreviewImportPageAndRecordsByUpdateWithDiff.php b/typo3/sysext/impexp/Tests/Functional/Fixtures/ArrayAssertions/RenderPreviewImportPageAndRecordsByUpdateWithDiff.php index d0a50f5bc28f..be5f466ea058 100644 --- a/typo3/sysext/impexp/Tests/Functional/Fixtures/ArrayAssertions/RenderPreviewImportPageAndRecordsByUpdateWithDiff.php +++ b/typo3/sysext/impexp/Tests/Functional/Fixtures/ArrayAssertions/RenderPreviewImportPageAndRecordsByUpdateWithDiff.php @@ -134,6 +134,7 @@ return [ 'updateMode' => sprintf('<select class="form-select form-select-sm" name="tx_impexp[import_mode][sys_file_storage:1]" style="width: 100px"><option value="0">Update</option><option value="%s">Import as new</option><option value="%s">Ignore PID</option><option value="%s">Exclude</option></select>', \TYPO3\CMS\Impexp\Import::IMPORT_MODE_AS_NEW, \TYPO3\CMS\Impexp\Import::IMPORT_MODE_IGNORE_PID, \TYPO3\CMS\Impexp\Import::IMPORT_MODE_EXCLUDE), 'showDiffContent' => '<strong class="text-nowrap">[sys_file_storage:1 => 1]:</strong>' . "\n" . '<table class="table table-striped table-hover">' . "\n" + . '<tr><td>Is default storage? (is_default)</td><td><del>Yes</del><ins>No</ins></td></tr>' . "\n" . '<tr><td>Driver Configuration (configuration)</td><td>' . "\n\n" . '<del> \\n \\n \\n \\n fileadmin/\\n \\n \\n relative\\n \\n \\n 1\\n \\n \\n \\n \\n</del><ins>' . "\t\n" . "\t\t\n" @@ -151,7 +152,6 @@ return [ . "\t\t\n" . "\t\n" . '</ins></td></tr> -<tr><td>Is default storage? (is_default)</td><td><del>Yes</del><ins>No</ins></td></tr> <tr><td>Description (description)</td><td><strong>Field missing</strong> in database</td></tr> </table>', 'controls' => '', diff --git a/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-corrupt-image.xml b/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-corrupt-image.xml index e4c31d0b2fad..f08177c8671d 100644 --- a/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-corrupt-image.xml +++ b/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-corrupt-image.xml @@ -341,7 +341,12 @@ <field index="description" type="NULL"></field> <field index="name">fileadmin</field> <field index="driver">Local</field> - <field index="configuration"><?xml version="1.0" encoding="utf-8" standalone="yes" ?> + <field index="is_public">1</field> + <field index="is_browsable">1</field> + <field index="is_default">0</field> + <field index="is_writable">1</field> + <field index="is_online">1</field> + <field index="configuration"><?xml version="1.0" encoding="utf-8" standalone="yes" ?> <T3FlexForms> <data> <sheet index="sDEF"> @@ -359,11 +364,6 @@ </sheet> </data> </T3FlexForms></field> - <field index="is_public">1</field> - <field index="is_browsable">1</field> - <field index="is_default">0</field> - <field index="is_writable">1</field> - <field index="is_online">1</field> </fieldlist> <related index="rels" type="array"> <field index="configuration" type="array"> diff --git a/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-image-but-not-included.xml b/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-image-but-not-included.xml index 5de972506618..dcad71503f10 100644 --- a/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-image-but-not-included.xml +++ b/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-image-but-not-included.xml @@ -341,7 +341,12 @@ <field index="description" type="NULL"></field> <field index="name">fileadmin</field> <field index="driver">Local</field> - <field index="configuration"><?xml version="1.0" encoding="utf-8" standalone="yes" ?> + <field index="is_public">1</field> + <field index="is_browsable">1</field> + <field index="is_default">0</field> + <field index="is_writable">1</field> + <field index="is_online">1</field> + <field index="configuration"><?xml version="1.0" encoding="utf-8" standalone="yes" ?> <T3FlexForms> <data> <sheet index="sDEF"> @@ -359,11 +364,6 @@ </sheet> </data> </T3FlexForms></field> - <field index="is_public">1</field> - <field index="is_browsable">1</field> - <field index="is_default">0</field> - <field index="is_writable">1</field> - <field index="is_online">1</field> </fieldlist> <related index="rels" type="array"> <field index="configuration" type="array"> diff --git a/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-image.xml b/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-image.xml index ad922e962461..d115ed1c0d6d 100644 --- a/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-image.xml +++ b/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlExports/pages-and-ttcontent-with-image.xml @@ -341,7 +341,12 @@ <field index="description" type="NULL"></field> <field index="name">fileadmin</field> <field index="driver">Local</field> - <field index="configuration"><?xml version="1.0" encoding="utf-8" standalone="yes" ?> + <field index="is_public">1</field> + <field index="is_browsable">1</field> + <field index="is_default">0</field> + <field index="is_writable">1</field> + <field index="is_online">1</field> + <field index="configuration"><?xml version="1.0" encoding="utf-8" standalone="yes" ?> <T3FlexForms> <data> <sheet index="sDEF"> @@ -359,11 +364,6 @@ </sheet> </data> </T3FlexForms></field> - <field index="is_public">1</field> - <field index="is_browsable">1</field> - <field index="is_default">0</field> - <field index="is_writable">1</field> - <field index="is_online">1</field> </fieldlist> <related index="rels" type="array"> <field index="configuration" type="array"> -- GitLab