From eb52636d07265657dab0a4a3c126ee50d4d0eda4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Reinhard=20F=C3=BChricht?= <rf@typoheads.at>
Date: Sat, 16 Jan 2016 09:28:41 +0100
Subject: [PATCH] [BUGFIX] PHP warning when importing a t3d without file
 storages

Added is_array() check before the foreach loop
running through the file storages.

Resolves: #72759
Releases: master
Change-Id: If78634e5474c0d86be529f4aa131a0d6a6f2f200
Reviewed-on: https://review.typo3.org/45987
Reviewed-by: Martin Kutschker <martin.kutschker@ymail.com>
Reviewed-by: Bernhard Kraft <kraftb@think-open.at>
Tested-by: Bernhard Kraft <kraftb@think-open.at>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
---
 typo3/sysext/impexp/Classes/Import.php | 58 +++++++++++++-------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/typo3/sysext/impexp/Classes/Import.php b/typo3/sysext/impexp/Classes/Import.php
index 8472ea1e30b9..f1d1efe51c1e 100644
--- a/typo3/sysext/impexp/Classes/Import.php
+++ b/typo3/sysext/impexp/Classes/Import.php
@@ -354,37 +354,39 @@ class Import extends ImportExport
 
         // Check #2: If the path for every local storage object exists.
         // Else files can't get moved into a newly imported storage.
-        foreach ($this->dat['header']['records']['sys_file_storage'] as $sysFileStorageUid => $_) {
-            $storageRecord = $this->dat['records']['sys_file_storage:' . $sysFileStorageUid]['data'];
-            // continue with Local, writable and online storage only
-            if ($storageRecord['driver'] === 'Local' && $storageRecord['is_writable'] && $storageRecord['is_online']) {
-                $storageExists = false;
-                /** @var $localStorage \TYPO3\CMS\Core\Resource\ResourceStorage */
-                foreach ($this->storageObjects as $localStorage) {
-                    if ($this->isEquivalentObjectStorage($localStorage, $storageRecord)) {
-                        // There is already an existing storage
-                        $storageExists = true;
-                        break;
+        if(is_array($this->dat['header']['records']['sys_file_storage'])) {
+            foreach ($this->dat['header']['records']['sys_file_storage'] as $sysFileStorageUid => $_) {
+                $storageRecord = $this->dat['records']['sys_file_storage:' . $sysFileStorageUid]['data'];
+                // continue with Local, writable and online storage only
+                if ($storageRecord['driver'] === 'Local' && $storageRecord['is_writable'] && $storageRecord['is_online']) {
+                    $storageExists = false;
+                    /** @var $localStorage \TYPO3\CMS\Core\Resource\ResourceStorage */
+                    foreach ($this->storageObjects as $localStorage) {
+                        if ($this->isEquivalentObjectStorage($localStorage, $storageRecord)) {
+                            // There is already an existing storage
+                            $storageExists = true;
+                            break;
+                        }
                     }
-                }
 
-                if (!$storageExists) {
-                    // The storage from the import does not have an equivalent storage
-                    // in the current instance (same driver, same path, etc.). Before
-                    // the storage record can get inserted later on take care the path
-                    // it points to really exists and is accessible.
-                    $storageRecordUid = $storageRecord['uid'];
-                    // Unset the storage record UID when trying to create the storage object
-                    // as the record does not already exist in DB. The constructor of the
-                    // storage object will check whether the target folder exists and set the
-                    // isOnline flag depending on the outcome.
-                    $storageRecord['uid'] = 0;
-                    $resourceStorage = ResourceFactory::getInstance()->createStorageObject($storageRecord);
-                    if (!$resourceStorage->isOnline()) {
-                        $configuration = $resourceStorage->getConfiguration();
-                        $messages['resourceStorageFolderMissing_' . $storageRecordUid] = 'The resource storage "' . $resourceStorage->getName() . '" will get imported. The storage target directory "' . $configuration['basePath'] . '" does not exist. Please create the directory prior to starting the import!';
-                    }
+                    if (!$storageExists) {
+                        // The storage from the import does not have an equivalent storage
+                        // in the current instance (same driver, same path, etc.). Before
+                        // the storage record can get inserted later on take care the path
+                        // it points to really exists and is accessible.
+                        $storageRecordUid = $storageRecord['uid'];
+                        // Unset the storage record UID when trying to create the storage object
+                        // as the record does not already exist in DB. The constructor of the
+                        // storage object will check whether the target folder exists and set the
+                        // isOnline flag depending on the outcome.
+                        $storageRecord['uid'] = 0;
+                        $resourceStorage = ResourceFactory::getInstance()->createStorageObject($storageRecord);
+                        if (!$resourceStorage->isOnline()) {
+                            $configuration = $resourceStorage->getConfiguration();
+                            $messages['resourceStorageFolderMissing_' . $storageRecordUid] = 'The resource storage "' . $resourceStorage->getName() . '" will get imported. The storage target directory "' . $configuration['basePath'] . '" does not exist. Please create the directory prior to starting the import!';
+                        }
 
+                    }
                 }
             }
         }
-- 
GitLab