From 9495098238e6467deeceac9c56d85d390f27d3c2 Mon Sep 17 00:00:00 2001
From: Manuel Selbach <manuel_selbach@yahoo.de>
Date: Tue, 14 Apr 2020 13:48:00 +0200
Subject: [PATCH] [BUGFIX] Let DataHandler::getAutoVersionId return proper
 integer

With this change the method DataHandler::getAutoVersionId will return
null or a proper integer value to reduce the complexity at other places
to bring it in the right format.

Resolves: #91022
Releases: master
Change-Id: I3e05e7f31314bebcac5c5d47e88c381f85a399d3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64160
Tested-by: Alexander Schnitzler <git@alexanderschnitzler.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Alexander Schnitzler <git@alexanderschnitzler.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack <benni@typo3.org>
---
 .../core/Classes/DataHandling/DataHandler.php       | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index 253ea843925a..e163072b121a 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -5597,7 +5597,7 @@ class DataHandler implements LoggerAwareInterface
                 foreach ($dbAnalysis->itemArray as &$item) {
                     $updatePidForRecords[$item['table']][] = $item['id'];
                     $versionedId = $this->getAutoVersionId($item['table'], $item['id']);
-                    if (!empty($versionedId)) {
+                    if ($versionedId !== null) {
                         $updatePidForRecords[$item['table']][] = $versionedId;
                         $item['id'] = $versionedId;
                     }
@@ -5628,14 +5628,13 @@ class DataHandler implements LoggerAwareInterface
                     }
                     $updateValues = ['pid' => $thePidToUpdate];
                     foreach ($updatePidForRecords as $tableName => $uids) {
-                        $uids = array_map('trim', $uids);
                         if (empty($tableName) || empty($uids)) {
                             continue;
                         }
                         $conn = GeneralUtility::makeInstance(ConnectionPool::class)
                             ->getConnectionForTable($tableName);
-                        foreach ($uids as $uid) {
-                            $conn->update($tableName, $updateValues, ['uid' => (int)$uid]);
+                        foreach ($uids as $updateUid) {
+                            $conn->update($tableName, $updateValues, ['uid' => $updateUid]);
                         }
                     }
                 }
@@ -8337,13 +8336,13 @@ class DataHandler implements LoggerAwareInterface
      *
      * @param string $table Name of the table
      * @param int $id Uid of the record
-     * @return int
+     * @return int|null
      */
-    public function getAutoVersionId($table, $id)
+    public function getAutoVersionId($table, $id): ?int
     {
         $result = null;
         if (isset($this->autoVersionIdMap[$table][$id])) {
-            $result = $this->autoVersionIdMap[$table][$id];
+            $result = (int)trim($this->autoVersionIdMap[$table][$id]);
         }
         return $result;
     }
-- 
GitLab