[BUGFIX] Do not fix uniqueInPid for empty values 13/38413/2
authorMarkus Klein <klein.t3@reelworx.at>
Wed, 1 Apr 2015 16:04:52 +0000 (18:04 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Wed, 1 Apr 2015 20:15:02 +0000 (22:15 +0200)
This patch adds the necessary condition to avoid creating useless
values in fields that have eval=uniqueInPid.
The behaviour is triggered when moving records around in BE.

This empty-check is already present in other places, but was
obviously forgotten to be added to fixUniqueInPid().

Releases: master, 6.2
Resolves: #59224
Change-Id: Ie7d99f40facfd603c783f3dcca30b8f8b253fe09
Reviewed-on: http://review.typo3.org/38413
Reviewed-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Tested-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Reviewed-by: Jo Hasenau <info@cybercraft.de>
Tested-by: Jo Hasenau <info@cybercraft.de>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index 2c91073..b3b4f36 100644 (file)
@@ -6669,24 +6669,26 @@ class DataHandler {
         * @return void
         */
        public function fixUniqueInPid($table, $uid) {
-               if ($GLOBALS['TCA'][$table]) {
-                       $curData = $this->recordInfo($table, $uid, '*');
-                       $newData = array();
-                       foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $conf) {
-                               if ($conf['config']['type'] == 'input') {
-                                       $evalCodesArray = GeneralUtility::trimExplode(',', $conf['config']['eval'], TRUE);
-                                       if (in_array('uniqueInPid', $evalCodesArray, TRUE)) {
-                                               $newV = $this->getUnique($table, $field, $curData[$field], $uid, $curData['pid']);
-                                               if ((string)$newV !== (string)$curData[$field]) {
-                                                       $newData[$field] = $newV;
-                                               }
+               if (empty($GLOBALS['TCA'][$table])) {
+                       return;
+               }
+
+               $curData = $this->recordInfo($table, $uid, '*');
+               $newData = array();
+               foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $conf) {
+                       if ($conf['config']['type'] === 'input' && (string)$curData[$field] !== '') {
+                               $evalCodesArray = GeneralUtility::trimExplode(',', $conf['config']['eval'], TRUE);
+                               if (in_array('uniqueInPid', $evalCodesArray, TRUE)) {
+                                       $newV = $this->getUnique($table, $field, $curData[$field], $uid, $curData['pid']);
+                                       if ((string)$newV !== (string)$curData[$field]) {
+                                               $newData[$field] = $newV;
                                        }
                                }
                        }
-                       // IF there are changed fields, then update the database
-                       if (count($newData)) {
-                               $this->updateDB($table, $uid, $newData);
-                       }
+               }
+               // IF there are changed fields, then update the database
+               if (!empty($newData)) {
+                       $this->updateDB($table, $uid, $newData);
                }
        }