[TASK] ImpExp: Streamline checks for data 77/46077/4
authorMarkus Klein <markus.klein@typo3.org>
Tue, 19 Jan 2016 13:32:24 +0000 (14:32 +0100)
committerFrank Nägler <frank.naegler@typo3.org>
Sat, 23 Jan 2016 10:46:57 +0000 (11:46 +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/46077
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
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 702140f..5bd8e82 100644 (file)
@@ -314,16 +314,14 @@ 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']);
             $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,35 +341,32 @@ 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.
-        if (is_array($this->dat['header']['records']['sys_file_storage'])) {
+        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']) {
-                    $storageExists = false;
-                    /** @var $localStorage \TYPO3\CMS\Core\Resource\ResourceStorage */
+                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
-                            $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
@@ -385,7 +380,11 @@ class Import extends ImportExport
                         $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!';
+                            $messages['resourceStorageFolderMissing_' . $storageRecordUid] =
+                                'The resource storage "'
+                                . $resourceStorage->getName()
+                                . $configuration['basePath']
+                                . '" does not exist. Please create the directory prior to starting the import!';
                         }
                     }
                 }
index 4f75bcb..4ea6a53 100644 (file)
@@ -294,56 +294,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;
             }
         }