[TASK] ImpExp: Streamline checks for data 78/46078/3
authorMarkus Klein <markus.klein@typo3.org>
Tue, 19 Jan 2016 13:33:03 +0000 (14:33 +0100)
committerFrank Nägler <frank.naegler@typo3.org>
Mon, 25 Jan 2016 09:25:04 +0000 (10:25 +0100)
Remove checks where not necessary, add them where necessary.

Resolves: #72816
Releases: master, 7.6
Change-Id: I6aa9a90782a26d2665a38e78187052882a26ca90
Reviewed-on: https://review.typo3.org/46078
Reviewed-by: Reinhard Führicht <rf@typoheads.at>
Tested-by: Reinhard Führicht <rf@typoheads.at>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/impexp/Classes/Import.php
typo3/sysext/impexp/Classes/ImportExport.php

index fbe6de5..63850e5 100644 (file)
@@ -314,16 +314,15 @@ class Import extends ImportExport
     protected function isEquivalentObjectStorage(ResourceStorage $storageObject, array $storageRecord)
     {
         // compare the properties: driver, writable and online
-        if (
-            $storageObject->getDriverType() === $storageRecord['driver']
+        if ($storageObject->getDriverType() === $storageRecord['driver']
             && (bool)$storageObject->isWritable() === (bool)$storageRecord['is_writable']
             && (bool)$storageObject->isOnline() === (bool)$storageRecord['is_online']
         ) {
-            $storageRecordConfiguration = ResourceFactory::getInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
+            $storageRecordConfiguration = ResourceFactory::getInstance()
+                ->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
             $storageObjectConfiguration = $storageObject->getConfiguration();
             // compare the properties: pathType and basePath
-            if (
-                $storageRecordConfiguration['pathType'] === $storageObjectConfiguration['pathType']
+            if ($storageRecordConfiguration['pathType'] === $storageObjectConfiguration['pathType']
                 && $storageRecordConfiguration['basePath'] === $storageObjectConfiguration['basePath']
             ) {
                 return true;
@@ -343,48 +342,51 @@ class Import extends ImportExport
 
         // Check #1: Extension dependencies
         $extKeysToInstall = array();
-        if (is_array($this->dat['header']['extensionDependencies'])) {
-            foreach ($this->dat['header']['extensionDependencies'] as $extKey) {
-                if (!ExtensionManagementUtility::isLoaded($extKey)) {
-                    $extKeysToInstall[] = $extKey;
-                }
+        foreach ($this->dat['header']['extensionDependencies'] as $extKey) {
+            if (!ExtensionManagementUtility::isLoaded($extKey)) {
+                $extKeysToInstall[] = $extKey;
             }
         }
         if (!empty($extKeysToInstall)) {
-            $messages['missingExtensions'] = 'Before you can install this T3D file you need to install the extensions "' . implode('", "', $extKeysToInstall) . '".';
+            $messages['missingExtensions'] = 'Before you can install this T3D file you need to install the extensions "'
+                . implode('", "', $extKeysToInstall) . '".';
         }
 
         // 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 (!empty($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']
+                ) {
+                    foreach ($this->storageObjects as $localStorage) {
+                        if ($this->isEquivalentObjectStorage($localStorage, $storageRecord)) {
+                            // There is already an existing storage
+                            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!';
+                        // 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()
+                                . $configuration['basePath']
+                                . '" does not exist. Please create the directory prior to starting the import!';
+                        }
                     }
                 }
             }
@@ -2122,7 +2124,7 @@ class Import extends ImportExport
      */
     protected function cleanupImportData()
     {
-        if (is_array($this->dat['header']['extensionDependencies'])) {
+        if (isset($this->dat['header']['extensionDependencies']) && is_array($this->dat['header']['extensionDependencies'])) {
             $this->dat['header']['extensionDependencies'] = array_filter($this->dat['header']['extensionDependencies']);
         } else {
             $this->dat['header']['extensionDependencies'] = array();
index 4ad68bc..04cda0b 100644 (file)
@@ -285,56 +285,56 @@ abstract class ImportExport
      */
     public function displayContentOverview()
     {
+        if (!isset($this->dat['header'])) {
+            return [];
+        }
         // Check extension dependencies:
-        if (is_array($this->dat['header']['extensionDependencies'])) {
-            foreach ($this->dat['header']['extensionDependencies'] as $extKey) {
-                if (!ExtensionManagementUtility::isLoaded($extKey)) {
-                    $this->error('DEPENDENCY: The extension with key "' . $extKey . '" must be installed!');
-                }
+        foreach ($this->dat['header']['extensionDependencies'] as $extKey) {
+            if (!ExtensionManagementUtility::isLoaded($extKey)) {
+                $this->error('DEPENDENCY: The extension with key "' . $extKey . '" must be installed!');
             }
         }
+
         // Probably this is done to save memory space?
         unset($this->dat['files']);
 
         $viewData = array();
         // Traverse header:
-        if (is_array($this->dat['header'])) {
-            $this->remainHeader = $this->dat['header'];
-            // If there is a page tree set, show that:
-            if (is_array($this->dat['header']['pagetree'])) {
-                reset($this->dat['header']['pagetree']);
-                $lines = array();
-                $this->traversePageTree($this->dat['header']['pagetree'], $lines);
-
-                $viewData['dat'] = $this->dat;
-                $viewData['update'] = $this->update;
-                $viewData['showDiff'] = $this->showDiff;
-                if (!empty($lines)) {
-                    foreach ($lines as &$r) {
-                        $r['controls'] = $this->renderControls($r);
-                        $r['fileSize'] = GeneralUtility::formatSize($r['size']);
-                        $r['message'] = ($r['msg'] && !$this->doesImport ? '<span class="text-danger">' . htmlspecialchars($r['msg']) . '</span>' : '');
-                    }
-                    $viewData['pagetreeLines'] = $lines;
-                } else {
-                    $viewData['pagetreeLines'] = array();
+        $this->remainHeader = $this->dat['header'];
+        // If there is a page tree set, show that:
+        if (is_array($this->dat['header']['pagetree'])) {
+            reset($this->dat['header']['pagetree']);
+            $lines = array();
+            $this->traversePageTree($this->dat['header']['pagetree'], $lines);
+
+            $viewData['dat'] = $this->dat;
+            $viewData['update'] = $this->update;
+            $viewData['showDiff'] = $this->showDiff;
+            if (!empty($lines)) {
+                foreach ($lines as &$r) {
+                    $r['controls'] = $this->renderControls($r);
+                    $r['fileSize'] = GeneralUtility::formatSize($r['size']);
+                    $r['message'] = ($r['msg'] && !$this->doesImport ? '<span class="text-danger">' . htmlspecialchars($r['msg']) . '</span>' : '');
                 }
+                $viewData['pagetreeLines'] = $lines;
+            } else {
+                $viewData['pagetreeLines'] = array();
             }
-            // Print remaining records that were not contained inside the page tree:
-            if (is_array($this->remainHeader['records'])) {
-                $lines = array();
-                if (is_array($this->remainHeader['records']['pages'])) {
-                    $this->traversePageRecords($this->remainHeader['records']['pages'], $lines);
-                }
-                $this->traverseAllRecords($this->remainHeader['records'], $lines);
-                if (!empty($lines)) {
-                    foreach ($lines as &$r) {
-                        $r['controls'] = $this->renderControls($r);
-                        $r['fileSize'] = GeneralUtility::formatSize($r['size']);
-                        $r['message'] = ($r['msg'] && !$this->doesImport ? '<span class="text-danger">' . htmlspecialchars($r['msg']) . '</span>' : '');
-                    }
-                    $viewData['remainingRecords'] = $lines;
+        }
+        // Print remaining records that were not contained inside the page tree:
+        if (is_array($this->remainHeader['records'])) {
+            $lines = array();
+            if (is_array($this->remainHeader['records']['pages'])) {
+                $this->traversePageRecords($this->remainHeader['records']['pages'], $lines);
+            }
+            $this->traverseAllRecords($this->remainHeader['records'], $lines);
+            if (!empty($lines)) {
+                foreach ($lines as &$r) {
+                    $r['controls'] = $this->renderControls($r);
+                    $r['fileSize'] = GeneralUtility::formatSize($r['size']);
+                    $r['message'] = ($r['msg'] && !$this->doesImport ? '<span class="text-danger">' . htmlspecialchars($r['msg']) . '</span>' : '');
                 }
+                $viewData['remainingRecords'] = $lines;
             }
         }