From 26788e306322a937a4c0e120b6c2e0476d04940f Mon Sep 17 00:00:00 2001
From: Thomas Hohn <tho@gyldendal.dk>
Date: Mon, 7 Aug 2023 10:20:05 +0200
Subject: [PATCH] [BUGFIX] Fix PHP 8 warnings in DataHandler

Moved assignment of $destPid = $sortInfo['pid'] after check if
$sortInfo is an array, since the method call to getSortNumber
can return other values than an array.

Resolves: #101606
Releases: main, 12.4, 11.5
Change-Id: I3cfef35b351a0cd1fa8197702cce9e3b05871fcf
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80430
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 typo3/sysext/core/Classes/DataHandling/DataHandler.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index 68dbc61b021d..6d62342645e5 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -4268,10 +4268,10 @@ class DataHandler implements LoggerAwareInterface
             // Save the position to which the original record is requested to be moved
             $originalRecordDestinationPid = $destPid;
             $sortInfo = $this->getSortNumber($table, $uid, $destPid);
-            // Setting the destPid to the new pid of the record.
-            $destPid = $sortInfo['pid'];
             // If not an array, there was an error (which is already logged)
             if (is_array($sortInfo)) {
+                // Setting the destPid to the new pid of the record.
+                $destPid = $sortInfo['pid'];
                 if ($table !== 'pages' || $this->destNotInsideSelf($destPid, $uid)) {
                     // clear cache before moving
                     $this->registerRecordIdForPageCacheClearing($table, $uid);
-- 
GitLab