[!!!][TASK] Remove TCA option setToDefaultOnCopy 76/60276/6
authorBenni Mack <benni@typo3.org>
Sat, 16 Mar 2019 23:11:56 +0000 (00:11 +0100)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Mon, 25 Mar 2019 08:13:42 +0000 (09:13 +0100)
This special setting resets a certain field to its default
value when copying. This option was only there for
resetting some sys_action values to default, which can
easily be achieved by a hook if needed.

The option is removed to reduce the amount of checks and
the amount of available options for edge-cases in TCA, as this
option was not widely used - as identified by the Persistence
Initiative.

Resolves: #87989
Releases: master
Change-Id: Iae05d958ff31f0f0c4618486445baad7e624b73b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60276
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Migrations/TcaMigration.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-87989-TCAOptionSetToDefaultOnCopyRemoved.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php

index 43fe8c4..160b584 100644 (file)
@@ -3149,8 +3149,6 @@ class DataHandler implements LoggerAwareInterface
         $theNewID = StringUtility::getUniqueId('NEW');
         $enableField = isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']) ? $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'] : '';
         $headerField = $GLOBALS['TCA'][$table]['ctrl']['label'];
-        // Getting default data:
-        $defaultData = $this->newFieldArray($table);
         // Getting "copy-after" fields if applicable:
         $copyAfterFields = $destPid < 0 ? $this->fixCopyAfterDuplFields($table, $uid, abs($destPid), 0) : [];
         // Page TSconfig related:
@@ -3159,7 +3157,6 @@ class DataHandler implements LoggerAwareInterface
         $TSConfig = BackendUtility::getPagesTSconfig($tscPID)['TCEMAIN.'] ?? [];
         $tE = $this->getTableEntries($table, $TSConfig);
         // Traverse ALL fields of the selected record:
-        $setDefaultOnCopyArray = array_flip(GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['setToDefaultOnCopy']));
         foreach ($row as $field => $value) {
             if (!in_array($field, $nonFields, true)) {
                 // Get TCA configuration for the field:
@@ -3176,8 +3173,6 @@ class DataHandler implements LoggerAwareInterface
                 } elseif (array_key_exists($field, $copyAfterFields)) {
                     // Copy-after value if available:
                     $value = $copyAfterFields[$field];
-                } elseif ($GLOBALS['TCA'][$table]['ctrl']['setToDefaultOnCopy'] && isset($setDefaultOnCopyArray[$field])) {
-                    $value = $defaultData[$field];
                 } else {
                     // Hide at copy may override:
                     if ($first && $field == $enableField && $GLOBALS['TCA'][$table]['ctrl']['hideAtCopy'] && !$this->neverHideAtCopy && !$tE['disableHideAtCopy']) {
index bc8b7ef..ad86d5a 100644 (file)
@@ -50,6 +50,7 @@ class TcaMigration
         $tca = $this->migrateLocalizeChildrenAtParentLocalization($tca);
         $tca = $this->migratePagesLanguageOverlayRemoval($tca);
         $tca = $this->removeSelIconFieldPath($tca);
+        $tca = $this->removeSetToDefaultOnCopy($tca);
 
         return $tca;
     }
@@ -187,4 +188,23 @@ class TcaMigration
         }
         return $tca;
     }
+
+    /**
+     * Removes $TCA[$mytable][ctrl][setToDefaultOnCopy]
+     *
+     * @param array $tca
+     * @return array the modified TCA structure
+     */
+    protected function removeSetToDefaultOnCopy(array $tca): array
+    {
+        foreach ($tca as $table => &$configuration) {
+            if (isset($configuration['ctrl']['setToDefaultOnCopy'])) {
+                $this->messages[] = 'The TCA table \'' . $table . '\' defines '
+                    . '[ctrl][setToDefaultOnCopy] which should be removed from TCA, '
+                    . 'as it is not in use anymore.';
+                unset($configuration['ctrl']['setToDefaultOnCopy']);
+            }
+        }
+        return $tca;
+    }
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-87989-TCAOptionSetToDefaultOnCopyRemoved.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-87989-TCAOptionSetToDefaultOnCopyRemoved.rst
new file mode 100644 (file)
index 0000000..e9b6925
--- /dev/null
@@ -0,0 +1,38 @@
+.. include:: ../../Includes.txt
+
+========================================================
+Breaking: #87989 - TCA option setToDefaultOnCopy removed
+========================================================
+
+See :issue:`87989`
+
+Description
+===========
+
+The special TCA option :php:`$TCA[$tableName]['ctrl']['setToDefaultOnCopy']` is removed.
+
+It allowed to reset a certain field to its default value when copying a record.
+
+
+Impact
+======
+
+Having the setting set in TCA will trigger a deprecation warning when building TCA.
+
+Copying records with this TCA setting enabled, will now keep the copied state and avoid side-effects.
+
+
+Affected Installations
+======================
+
+TYPO3 installations with active usage of `sys_action` or other extensions using this TCA setting.
+
+
+Migration
+=========
+
+This option was only there for resetting some `sys_action` values to default, which
+can easily be achieved by a hook if needed. If an extension author uses this setting,
+this should be achieved with proper DataHandler hooks.
+
+.. index:: TCA, PartiallyScanned, ext:core
\ No newline at end of file
index 897be8a..d220256 100644 (file)
@@ -175,4 +175,42 @@ class TcaMigrationTest extends UnitTestCase
         $subject = new TcaMigration();
         $this->assertEquals($expected, $subject->migrate($input));
     }
+
+    /**
+     * @test
+     */
+    public function ctrlSetToDefaultOnCopyIsRemoved()
+    {
+        $input = [
+            'aTable' => [
+                'ctrl' => [
+                    'title' => 'aField',
+                    'setToDefaultOnCopy' => 'aField,anotherField',
+                ],
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'none',
+                        ],
+                    ],
+                ]
+            ]
+        ];
+        $expected = [
+            'aTable' => [
+                'ctrl' => [
+                    'title' => 'aField',
+                ],
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'none',
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $subject = new TcaMigration();
+        $this->assertEquals($expected, $subject->migrate($input));
+    }
 }