From 6b33d8f4dfbcd429a9a23036281dce1c483fbe4e Mon Sep 17 00:00:00 2001 From: Oliver Hader <oliver@typo3.org> Date: Thu, 24 Aug 2023 13:09:00 +0200 Subject: [PATCH] [BUGFIX] Fix several undefined array key issues in DataHandler scope DataMapProcessor tries to access `$possibleChainedIds[0]` which might not be defined, since that array is the result of a previous `array_intersect` invokation, which keeps the array keys of the original input array. DataHandler tries to access `$this->copyMappingArray[$table][$uid]`, which might not be defined in case the previous copy command could not be executed (e.g. since the record was deleted already). Resolves: #101748 Releases: main, 12.4, 11.5 Change-Id: Ibcbc412c7df62ce17dfa2c0f6fc120ccebb953d8 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80670 Tested-by: core-ci <typo3@b13.com> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> --- Build/phpstan/phpstan-baseline.neon | 2 +- typo3/sysext/core/Classes/DataHandling/DataHandler.php | 10 +++++----- .../DataHandling/Localization/DataMapProcessor.php | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index 04b498b61827..16bdb2bf9ee2 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -396,7 +396,7 @@ parameters: path: ../../typo3/sysext/core/Classes/DataHandling/DataHandler.php - - message: "#^Offset string does not exist on array\\{\\}\\.$#" + message: "#^Offset string on array\\{\\} on left side of \\?\\? does not exist\\.$#" count: 1 path: ../../typo3/sysext/core/Classes/DataHandling/DataHandler.php diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php index 977daf6094f6..62f5640fa246 100644 --- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php +++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php @@ -3552,7 +3552,7 @@ class DataHandler implements LoggerAwareInterface } else { $this->copyRecord($table, (int)$id, $target, true, [], '', 0, $ignoreLocalization); } - $procId = $this->copyMappingArray[$table][$id]; + $procId = $this->copyMappingArray[$table][$id] ?? null; break; case 'localize': $this->useTransOrigPointerField = true; @@ -3573,7 +3573,7 @@ class DataHandler implements LoggerAwareInterface break; } $this->useTransOrigPointerField = $backupUseTransOrigPointerField; - if (is_array($pasteUpdate)) { + if (is_array($pasteUpdate) && $procId > 0) { $pasteDatamap[$table][$procId] = $pasteUpdate; } } @@ -3782,7 +3782,7 @@ class DataHandler implements LoggerAwareInterface $CPtable = $this->int_pageTreeInfo([], $uid, (int)$this->copyTree, $theNewRootID); // Now copying the subpages: foreach ($CPtable as $thePageUid => $thePagePid) { - $newPid = $this->copyMappingArray['pages'][$thePagePid]; + $newPid = $this->copyMappingArray['pages'][$thePagePid] ?? null; if (isset($newPid)) { $this->copySpecificPage($thePageUid, $newPid, $copyTablesAlongWithPage); } else { @@ -6744,7 +6744,7 @@ class DataHandler implements LoggerAwareInterface $thePidToUpdate = $theUidToUpdate; } elseif (isset($this->registerDBPids[$table][$uid])) { $thePidToUpdate = $this->registerDBPids[$table][$uid]; - $thePidToUpdate = $this->copyMappingArray_merged['pages'][$thePidToUpdate]; + $thePidToUpdate = $this->copyMappingArray_merged['pages'][$thePidToUpdate] ?? null; } // Update child records if change to pid is required @@ -6803,7 +6803,7 @@ class DataHandler implements LoggerAwareInterface $thePidToUpdate = $theUidToUpdate; } elseif (isset($this->registerDBPids[$table][$uid])) { $thePidToUpdate = $this->registerDBPids[$table][$uid]; - $thePidToUpdate = $this->copyMappingArray_merged['pages'][$thePidToUpdate]; + $thePidToUpdate = $this->copyMappingArray_merged['pages'][$thePidToUpdate] ?? null; } if ($thePidToUpdate && $updatePidForRecords !== []) { diff --git a/typo3/sysext/core/Classes/DataHandling/Localization/DataMapProcessor.php b/typo3/sysext/core/Classes/DataHandling/Localization/DataMapProcessor.php index aafd62607d40..cce37df8cdd5 100644 --- a/typo3/sysext/core/Classes/DataHandling/Localization/DataMapProcessor.php +++ b/typo3/sysext/core/Classes/DataHandling/Localization/DataMapProcessor.php @@ -1043,7 +1043,8 @@ class DataMapProcessor $ancestorIdMap[$ancestorId] ); if (!empty($possibleChainedIds)) { - $ancestorId = $possibleChainedIds[0]; + // use the first found id from `$possibleChainedIds` + $ancestorId = reset($possibleChainedIds); $dependentIdMap[$ancestorId] = $dependentId; } } -- GitLab