[BUGFIX] Check if `$rows` is an array before iteration 11/48311/6
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 27 May 2016 08:59:26 +0000 (10:59 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Fri, 27 May 2016 10:29:43 +0000 (12:29 +0200)
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>
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index 6ae984d..0e3c9e7 100644 (file)
@@ -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());
                     }
                 }
             }