From 1fb503652dbf1eff4f7da0c9e95178bd1031f47f Mon Sep 17 00:00:00 2001
From: Andreas Fernandez <a.fernandez@scripting-base.de>
Date: Mon, 20 Apr 2020 15:25:37 +0200
Subject: [PATCH] [BUGFIX] Resolve pid for records being pasted

Pasted records use a negative integer to determine their location which
is passed as "pid". The DataHandler now resolves the real pid of the
records before executing any checks.

Resolves: #91144
Related: #89555
Releases: master
Change-Id: I10f74542bee5a8a15113731b975580f540748cdb
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64257
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <look@susi.dev>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <look@susi.dev>
---
 typo3/sysext/core/Classes/DataHandling/DataHandler.php | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index afa9277a76b6..39328f985b96 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -3261,9 +3261,12 @@ class DataHandler implements LoggerAwareInterface
             return null;
         }
 
+        // NOT using \TYPO3\CMS\Backend\Utility\BackendUtility::getTSCpid() because we need the real pid - not the ID of a page, if the input is a page...
+        $tscPID = BackendUtility::getTSconfig_pidValue($table, $uid, $destPid);
+
         // Check if table is allowed on destination page
-        if (!$this->isTableAllowedForThisPage($destPid, $table)) {
-            $this->log($table, $uid, SystemLogDatabaseAction::INSERT, 0, SystemLogErrorClassification::USER_ERROR, 'Attempt to insert record "%s:%s" on a page (%s) that can\'t store record type.', -1, [$table, $uid, $destPid]);
+        if (!$this->isTableAllowedForThisPage($tscPID, $table)) {
+            $this->log($table, $uid, SystemLogDatabaseAction::INSERT, 0, SystemLogErrorClassification::USER_ERROR, 'Attempt to insert record "%s:%s" on a page (%s) that can\'t store record type.', -1, [$table, $uid, $tscPID]);
             return null;
         }
 
@@ -3286,8 +3289,6 @@ class DataHandler implements LoggerAwareInterface
         // Getting "copy-after" fields if applicable:
         $copyAfterFields = $destPid < 0 ? $this->fixCopyAfterDuplFields($table, $uid, abs($destPid), 0) : [];
         // Page TSconfig related:
-        // NOT using \TYPO3\CMS\Backend\Utility\BackendUtility::getTSCpid() because we need the real pid - not the ID of a page, if the input is a page...
-        $tscPID = BackendUtility::getTSconfig_pidValue($table, $uid, $destPid);
         $TSConfig = BackendUtility::getPagesTSconfig($tscPID)['TCEMAIN.'] ?? [];
         $tE = $this->getTableEntries($table, $TSConfig);
         // Traverse ALL fields of the selected record:
-- 
GitLab