From 485bbc5307c195ca93ea8d7621db08c72f6739a2 Mon Sep 17 00:00:00 2001 From: Andreas Fernandez <a.fernandez@scripting-base.de> Date: Fri, 27 May 2016 10:59:26 +0200 Subject: [PATCH] [BUGFIX] Check if `$rows` is an array before iteration In case `$rows` in the method `DataHandler::copySpecificPage()` is null, the foreach loop will throw an error. `$rows` may become null if an extension brings TCA but the table does not have `uid` field, for example. It's now checked whether the result being iterated is an array, otherwise an error is logged. Resolves: #74125 Releases: master, 7.6 Change-Id: I20cb101155632309b9e08600fcd33e655c1c9d2f Reviewed-on: https://review.typo3.org/48311 Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de> Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de> Reviewed-by: Markus Klein <markus.klein@typo3.org> Tested-by: Markus Klein <markus.klein@typo3.org> --- .../core/Classes/DataHandling/DataHandler.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php index 6ae984d30bed..0e3c9e7bdd6b 100644 --- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php +++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php @@ -3494,16 +3494,19 @@ class DataHandler true ); } - - foreach ($rows as $row) { - // Skip localized records that will be processed in - // copyL10nOverlayRecords() on copying the default language record - $transOrigPointer = $row[$transOrigPointerField]; - if ($row[$languageField] > 0 && $transOrigPointer > 0 && isset($rows[$transOrigPointer])) { - continue; + if (is_array($rows)) { + foreach ($rows as $row) { + // Skip localized records that will be processed in + // copyL10nOverlayRecords() on copying the default language record + $transOrigPointer = $row[$transOrigPointerField]; + if ($row[$languageField] > 0 && $transOrigPointer > 0 && isset($rows[$transOrigPointer])) { + continue; + } + // Copying each of the underlying records... + $this->copyRecord($table, $row['uid'], $theNewRootID); } - // Copying each of the underlying records... - $this->copyRecord($table, $row['uid'], $theNewRootID); + } elseif ($this->enableLogging) { + $this->log('pages', $uid, 5, 0, 1, 'An SQL error occurred: ' . $this->databaseConnection->sql_error()); } } } -- GitLab