[CLEANUP] ImportExport code needs some love 24/32324/4
authorMarkus Klein <klein.t3@reelworx.at>
Fri, 22 Aug 2014 15:46:10 +0000 (17:46 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 8 Sep 2014 11:41:50 +0000 (13:41 +0200)
* Fix undefined variables
* Add missing return values
* Reduce indentation level by using guards
* Optimize readability
* CGL compliance

No functional changes.

Resolves: #61152
Releases: 6.3
Change-Id: Ifa2ed030d5fd721ef3ea2c4ef3a819b2d1f8762b
Reviewed-on: http://review.typo3.org/32324
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/impexp/Classes/ImportExport.php

index 9b95ab7..d6a63bb 100644 (file)
@@ -16,10 +16,11 @@ namespace TYPO3\CMS\Impexp;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Exception;
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 
-/**
+/*
  * EXAMPLE for using the impexp-class for exporting stuff:
  *
  * Create and initialize:
@@ -48,6 +49,7 @@ use TYPO3\CMS\Core\Utility\PathUtility;
  * Write export
  * $out = $this->export->compileMemoryToFileContent();
  */
+
 /**
  * T3D file Import/Export library (TYPO3 Record Document)
  *
@@ -58,6 +60,7 @@ class ImportExport {
        /**
         * If set, static relations (not exported) will be shown in overview as well
         *
+        * @var bool
         * @todo Define visibility
         */
        public $showStaticRelations = FALSE;
@@ -65,6 +68,7 @@ class ImportExport {
        /**
         * Name of the "fileadmin" folder where files for export/import should be located
         *
+        * @var string
         * @todo Define visibility
         */
        public $fileadminFolderName = '';
@@ -72,6 +76,7 @@ class ImportExport {
        /**
         * Whether "import" or "export" mode of object. Set through init() function
         *
+        * @var string
         * @todo Define visibility
         */
        public $mode = '';
@@ -79,6 +84,7 @@ class ImportExport {
        /**
         * Updates all records that has same UID instead of creating new!
         *
+        * @var bool
         * @todo Define visibility
         */
        public $update = FALSE;
@@ -86,6 +92,7 @@ class ImportExport {
        /**
         * Is set by importData() when an import has been done.
         *
+        * @var bool
         * @todo Define visibility
         */
        public $doesImport = FALSE;
@@ -95,13 +102,16 @@ class ImportExport {
         * for the import and accordingly display validation information. This triggers the visual view of the
         * import/export memory to validate if import is possible
         *
+        * @var array
         * @todo Define visibility
         */
-       public $display_import_pid_record = '';
+       public $display_import_pid_record = array();
 
        /**
-        * Used to register the forged UID values for imported records that we want to create with the same UIDs as in the import file. Admin-only feature.
+        * Used to register the forged UID values for imported records that we want
+        * to create with the same UIDs as in the import file. Admin-only feature.
         *
+        * @var array
         * @todo Define visibility
         */
        public $suggestedInsertUids = array();
@@ -109,6 +119,7 @@ class ImportExport {
        /**
         * Setting import modes during update state: as_new, exclude, force_uid
         *
+        * @var array
         * @todo Define visibility
         */
        public $import_mode = array();
@@ -116,6 +127,7 @@ class ImportExport {
        /**
         * If set, PID correct is ignored globally
         *
+        * @var bool
         * @todo Define visibility
         */
        public $global_ignore_pid = FALSE;
@@ -123,6 +135,7 @@ class ImportExport {
        /**
         * If set, all UID values are forced! (update or import)
         *
+        * @var bool
         * @todo Define visibility
         */
        public $force_all_UIDS = FALSE;
@@ -130,6 +143,7 @@ class ImportExport {
        /**
         * If set, a diff-view column is added to the overview.
         *
+        * @var bool
         * @todo Define visibility
         */
        public $showDiff = FALSE;
@@ -137,6 +151,7 @@ class ImportExport {
        /**
         * If set, and if the user is admin, allow the writing of PHP scripts to fileadmin/ area.
         *
+        * @var bool
         * @todo Define visibility
         */
        public $allowPHPScripts = FALSE;
@@ -144,6 +159,7 @@ class ImportExport {
        /**
         * Disable logging when importing
         *
+        * @var bool
         * @todo Define visibility
         */
        public $enableLogging = FALSE;
@@ -151,6 +167,7 @@ class ImportExport {
        /**
         * Array of values to substitute in editable softreferences.
         *
+        * @var array
         * @todo Define visibility
         */
        public $softrefInputValues = array();
@@ -158,6 +175,7 @@ class ImportExport {
        /**
         * Mapping between the fileID from import memory and the final filenames they are written to.
         *
+        * @var array
         * @todo Define visibility
         */
        public $fileIDMap = array();
@@ -165,6 +183,7 @@ class ImportExport {
        /**
         * 1MB max file size
         *
+        * @var int
         * @todo Define visibility
         */
        public $maxFileSize = 1000000;
@@ -172,6 +191,7 @@ class ImportExport {
        /**
         * 1MB max record size
         *
+        * @var int
         * @todo Define visibility
         */
        public $maxRecordSize = 1000000;
@@ -179,20 +199,25 @@ class ImportExport {
        /**
         * 10MB max export size
         *
+        * @var int
         * @todo Define visibility
         */
        public $maxExportSize = 10000000;
 
        /**
-        * Add table names here which are THE ONLY ones which will be included into export if found as relations. '_ALL' will allow all tables.
+        * Add table names here which are THE ONLY ones which will be included
+        * into export if found as relations. '_ALL' will allow all tables.
         *
+        * @var array
         * @todo Define visibility
         */
        public $relOnlyTables = array();
 
        /**
-        * Add tables names here which should not be exported with the file. (Where relations should be mapped to same UIDs in target system).
+        * Add tables names here which should not be exported with the file.
+        * (Where relations should be mapped to same UIDs in target system).
         *
+        * @var array
         * @todo Define visibility
         */
        public $relStaticTables = array();
@@ -200,6 +225,7 @@ class ImportExport {
        /**
         * Exclude map. Keys are table:uid  pairs and if set, records are not added to the export.
         *
+        * @var array
         * @todo Define visibility
         */
        public $excludeMap = array();
@@ -207,6 +233,7 @@ class ImportExport {
        /**
         * Soft Reference Token ID modes.
         *
+        * @var array
         * @todo Define visibility
         */
        public $softrefCfg = array();
@@ -214,6 +241,7 @@ class ImportExport {
        /**
         * Listing extension dependencies.
         *
+        * @var array
         * @todo Define visibility
         */
        public $extensionDependencies = array();
@@ -221,20 +249,23 @@ class ImportExport {
        /**
         * Set  by user: If set, compression in t3d files is disabled
         *
+        * @var bool
         * @todo Define visibility
         */
-       public $dontCompress = 0;
+       public $dontCompress = FALSE;
 
        /**
-        * Boolean, if set, HTML file resources are included.
+        * If set, HTML file resources are included.
         *
+        * @var bool
         * @todo Define visibility
         */
-       public $includeExtFileResources = 0;
+       public $includeExtFileResources = FALSE;
 
        /**
         * Files with external media (HTML/css style references inside)
         *
+        * @var string
         * @todo Define visibility
         */
        public $extFileResourceExtensions = 'html,htm,css';
@@ -242,14 +273,17 @@ class ImportExport {
        /**
         * After records are written this array is filled with [table][original_uid] = [new_uid]
         *
+        * @var array
         * @todo Define visibility
         */
        public $import_mapId = array();
 
        /**
-        * Keys are [tablename]:[new NEWxxx ids (or when updating it is uids)] while values are arrays with table/uid of the original record it is based on.
-        * By the array keys the new ids can be looked up inside tcemain
+        * Keys are [tablename]:[new NEWxxx ids (or when updating it is uids)]
+        * while values are arrays with table/uid of the original record it is based on.
+        * With the array keys the new ids can be looked up inside tcemain
         *
+        * @var array
         * @todo Define visibility
         */
        public $import_newId = array();
@@ -257,6 +291,7 @@ class ImportExport {
        /**
         * Page id map for page tree (import)
         *
+        * @var array
         * @todo Define visibility
         */
        public $import_newId_pids = array();
@@ -264,6 +299,7 @@ class ImportExport {
        /**
         * Internal data accumulation for writing records during import
         *
+        * @var array
         * @todo Define visibility
         */
        public $import_data = array();
@@ -271,6 +307,7 @@ class ImportExport {
        /**
         * Error log.
         *
+        * @var array
         * @todo Define visibility
         */
        public $errorLog = array();
@@ -278,6 +315,7 @@ class ImportExport {
        /**
         * Cache for record paths
         *
+        * @var array
         * @todo Define visibility
         */
        public $cache_getRecordPath = array();
@@ -285,20 +323,23 @@ class ImportExport {
        /**
         * Cache of checkPID values.
         *
+        * @var array
         * @todo Define visibility
         */
        public $checkPID_cache = array();
 
        /**
         * Set internally if the gzcompress function exists
+        * Used by ImportExportController
         *
-        * @todo Define visibility
+        * @var bool
         */
-       public $compress = 0;
+       public $compress = FALSE;
 
        /**
         * Internal import/export memory
         *
+        * @var array
         * @todo Define visibility
         */
        public $dat = array();
@@ -307,9 +348,8 @@ class ImportExport {
         * File processing object
         *
         * @var \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility
-        * @todo Define visibility
         */
-       public $fileProcObj = '';
+       protected $fileProcObj = NULL;
 
        /**
         * Keys are [recordname], values are an array of fields to be included
@@ -392,15 +432,40 @@ class ImportExport {
        protected $saveFilesOutsideExportFile = FALSE;
 
        /**
-        * @var null|string
+        * @var NULL|string
         */
        protected $temporaryFilesPathForExport = NULL;
 
        /**
-        * @var null|string
+        * @var NULL|string
         */
        protected $filesPathForImport = NULL;
 
+       /**
+        * @var array
+        */
+       protected $unlinkFiles = array();
+
+       /**
+        * @var array
+        */
+       protected $alternativeFileName = array();
+
+       /**
+        * @var array
+        */
+       protected $alternativeFilePath = array();
+
+       /**
+        * @var array
+        */
+       protected $filePathMap = array();
+
+       /**
+        * @var array
+        */
+       protected $remainHeader = array();
+
        /**************************
         * Initialize
         *************************/
@@ -408,12 +473,11 @@ class ImportExport {
        /**
         * Init the object, both import and export
         *
-        * @param boolean $dontCompress If set, compression in t3d files is disabled
+        * @param bool $dontCompress If set, compression of t3d files is disabled
         * @param string $mode Mode of usage, either "import" or "export
         * @return void
-        * @todo Define visibility
         */
-       public function init($dontCompress = 0, $mode = '') {
+       public function init($dontCompress = FALSE, $mode = '') {
                $this->compress = function_exists('gzcompress');
                $this->dontCompress = $dontCompress;
                $this->mode = $mode;
@@ -597,7 +661,7 @@ class ImportExport {
        public function flatInversePageTree_pid($idH, $a = array(), $pid = -1) {
                if (is_array($idH)) {
                        $idH = array_reverse($idH);
-                       foreach ($idH as $k => $v) {
+                       foreach ($idH as $v) {
                                $a[$v['uid']] = $pid;
                                if (is_array($v['subrow'])) {
                                        $a = $this->flatInversePageTree_pid($v['subrow'], $a, $v['uid']);
@@ -710,18 +774,18 @@ class ImportExport {
                                foreach ($relation['newValueFiles'] as $key => $fileRelationData) {
                                        $absoluteFilePath = $fileRelationData['ID_absFile'];
                                        if (GeneralUtility::isFirstPartOfStr($absoluteFilePath, PATH_site)) {
-                                               $relatedFilePath = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($absoluteFilePath);
+                                               $relatedFilePath = PathUtility::stripPathSitePrefix($absoluteFilePath);
                                                $relations[$field]['newValueFiles'][$key]['ID'] = md5($relatedFilePath);
                                        }
                                }
                        }
-                       if ($relation['type'] == 'flex') {
+                       if ($relation['type'] === 'flex') {
                                if (is_array($relation['flexFormRels']['file'])) {
                                        foreach ($relation['flexFormRels']['file'] as $key => $subList) {
                                                foreach ($subList as $subKey => $fileRelationData) {
                                                        $absoluteFilePath = $fileRelationData['ID_absFile'];
                                                        if (GeneralUtility::isFirstPartOfStr($absoluteFilePath, PATH_site)) {
-                                                               $relatedFilePath = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($absoluteFilePath);
+                                                               $relatedFilePath = PathUtility::stripPathSitePrefix($absoluteFilePath);
                                                                $relations[$field]['flexFormRels']['file'][$key][$subKey]['ID'] = md5($relatedFilePath);
                                                        }
                                                }
@@ -736,7 +800,8 @@ class ImportExport {
 
        /**
         * This analyses the existing added records, finds all database relations to records and adds these records to the export file.
-        * This function can be called repeatedly until it returns an empty array. In principle it should not allow to infinite recursivity, but you better set a limit...
+        * This function can be called repeatedly until it returns an empty array.
+        * In principle it should not allow to infinite recursivity, but you better set a limit...
         * Call this BEFORE the ext_addFilesFromRelations (so files from added relations are also included of course)
         *
         * @param integer $relationLevel Recursion level
@@ -745,50 +810,37 @@ class ImportExport {
         * @todo Define visibility
         */
        public function export_addDBRelations($relationLevel = 0) {
-               // Initialize:
-               $addR = array();
                // Traverse all "rels" registered for "records"
-               if (is_array($this->dat['records'])) {
-                       foreach ($this->dat['records'] as $k => $value) {
-                               if (is_array($this->dat['records'][$k])) {
-                                       foreach ($this->dat['records'][$k]['rels'] as $fieldname => $vR) {
-                                               // For all DB types of relations:
-                                               if ($vR['type'] == 'db') {
-                                                       foreach ($vR['itemArray'] as $fI) {
+               if (!is_array($this->dat['records'])) {
+                       $this->error('There were no records available.');
+                       return array();
+               }
+               $addR = array();
+               foreach ($this->dat['records'] as $k => $value) {
+                       if (!is_array($this->dat['records'][$k])) {
+                               continue;
+                       }
+                       foreach ($this->dat['records'][$k]['rels'] as $fieldname => $vR) {
+                               // For all DB types of relations:
+                               if ($vR['type'] == 'db') {
+                                       foreach ($vR['itemArray'] as $fI) {
+                                               $this->export_addDBRelations_registerRelation($fI, $addR);
+                                       }
+                               }
+                               // For all flex/db types of relations:
+                               if ($vR['type'] == 'flex') {
+                                       // DB relations in flex form fields:
+                                       if (is_array($vR['flexFormRels']['db'])) {
+                                               foreach ($vR['flexFormRels']['db'] as $subList) {
+                                                       foreach ($subList as $fI) {
                                                                $this->export_addDBRelations_registerRelation($fI, $addR);
                                                        }
                                                }
-                                               // For all flex/db types of relations:
-                                               if ($vR['type'] == 'flex') {
-                                                       // DB relations in flex form fields:
-                                                       if (is_array($vR['flexFormRels']['db'])) {
-                                                               foreach ($vR['flexFormRels']['db'] as $subList) {
-                                                                       foreach ($subList as $fI) {
-                                                                               $this->export_addDBRelations_registerRelation($fI, $addR);
-                                                                       }
-                                                               }
-                                                       }
-                                                       // DB oriented soft references in flex form fields:
-                                                       if (is_array($vR['flexFormRels']['softrefs'])) {
-                                                               foreach ($vR['flexFormRels']['softrefs'] as $subList) {
-                                                                       foreach ($subList['keys'] as $spKey => $elements) {
-                                                                               foreach ($elements as $el) {
-                                                                                       if ($el['subst']['type'] === 'db' && $this->includeSoftref($el['subst']['tokenID'])) {
-                                                                                               list($tempTable, $tempUid) = explode(':', $el['subst']['recordRef']);
-                                                                                               $fI = array(
-                                                                                                       'table' => $tempTable,
-                                                                                                       'id' => $tempUid
-                                                                                               );
-                                                                                               $this->export_addDBRelations_registerRelation($fI, $addR, $el['subst']['tokenID']);
-                                                                                       }
-                                                                               }
-                                                                       }
-                                                               }
-                                                       }
-                                               }
-                                               // In any case, if there are soft refs:
-                                               if (is_array($vR['softrefs']['keys'])) {
-                                                       foreach ($vR['softrefs']['keys'] as $spKey => $elements) {
+                                       }
+                                       // DB oriented soft references in flex form fields:
+                                       if (is_array($vR['flexFormRels']['softrefs'])) {
+                                               foreach ($vR['flexFormRels']['softrefs'] as $subList) {
+                                                       foreach ($subList['keys'] as $spKey => $elements) {
                                                                foreach ($elements as $el) {
                                                                        if ($el['subst']['type'] === 'db' && $this->includeSoftref($el['subst']['tokenID'])) {
                                                                                list($tempTable, $tempUid) = explode(':', $el['subst']['recordRef']);
@@ -803,12 +855,26 @@ class ImportExport {
                                                }
                                        }
                                }
+                               // In any case, if there are soft refs:
+                               if (is_array($vR['softrefs']['keys'])) {
+                                       foreach ($vR['softrefs']['keys'] as $spKey => $elements) {
+                                               foreach ($elements as $el) {
+                                                       if ($el['subst']['type'] === 'db' && $this->includeSoftref($el['subst']['tokenID'])) {
+                                                               list($tempTable, $tempUid) = explode(':', $el['subst']['recordRef']);
+                                                               $fI = array(
+                                                                       'table' => $tempTable,
+                                                                       'id' => $tempUid
+                                                               );
+                                                               $this->export_addDBRelations_registerRelation($fI, $addR, $el['subst']['tokenID']);
+                                                       }
+                                               }
+                                       }
+                               }
                        }
-               } else {
-                       $this->error('There were no records available.');
                }
+
                // Now, if there were new records to add, do so:
-               if (count($addR)) {
+               if (!empty($addR)) {
                        foreach ($addR as $fI) {
                                // Get and set record:
                                $row = BackendUtility::getRecord($fI['table'], $fI['id']);
@@ -816,7 +882,8 @@ class ImportExport {
                                        $this->export_addRecord($fI['table'], $row, $relationLevel + 1);
                                }
                                // Set status message
-                               // Relation pointers always larger than zero except certain "select" types with negative values pointing to uids - but that is not supported here.
+                               // Relation pointers always larger than zero except certain "select" types with
+                               // negative values pointing to uids - but that is not supported here.
                                if ($fI['id'] > 0) {
                                        $rId = $fI['table'] . ':' . $fI['id'];
                                        if (!isset($this->dat['records'][$rId])) {
@@ -842,7 +909,10 @@ class ImportExport {
         */
        public function export_addDBRelations_registerRelation($fI, &$addR, $tokenID = '') {
                $rId = $fI['table'] . ':' . $fI['id'];
-               if (isset($GLOBALS['TCA'][$fI['table']]) && !$this->isTableStatic($fI['table']) && !$this->isExcluded($fI['table'], $fI['id']) && (!$tokenID || $this->includeSoftref($tokenID)) && $this->inclRelation($fI['table'])) {
+               if (
+                       isset($GLOBALS['TCA'][$fI['table']]) && !$this->isTableStatic($fI['table']) && !$this->isExcluded($fI['table'], $fI['id'])
+                       && (!$tokenID || $this->includeSoftref($tokenID)) && $this->inclRelation($fI['table'])
+               ) {
                        if (!isset($this->dat['records'][$rId])) {
                                // Set this record to be included since it is not already.
                                $addR[$rId] = $fI;
@@ -860,59 +930,38 @@ class ImportExport {
         */
        public function export_addFilesFromRelations() {
                // Traverse all "rels" registered for "records"
-               if (is_array($this->dat['records'])) {
-                       foreach ($this->dat['records'] as $k => $value) {
-                               if (isset($this->dat['records'][$k]['rels']) && is_array($this->dat['records'][$k]['rels'])) {
-                                       foreach ($this->dat['records'][$k]['rels'] as $fieldname => $vR) {
-                                               // For all file type relations:
-                                               if ($vR['type'] == 'file') {
-                                                       foreach ($vR['newValueFiles'] as $key => $fI) {
+               if (!is_array($this->dat['records'])) {
+                       $this->error('There were no records available.');
+                       return;
+               }
+               foreach ($this->dat['records'] as $k => $value) {
+                       if (!isset($this->dat['records'][$k]['rels']) || !is_array($this->dat['records'][$k]['rels'])) {
+                               continue;
+                       }
+                       foreach ($this->dat['records'][$k]['rels'] as $fieldname => $vR) {
+                               // For all file type relations:
+                               if ($vR['type'] == 'file') {
+                                       foreach ($vR['newValueFiles'] as $key => $fI) {
+                                               $this->export_addFile($fI, $k, $fieldname);
+                                               // Remove the absolute reference to the file so it doesn't expose absolute paths from source server:
+                                               unset($this->dat['records'][$k]['rels'][$fieldname]['newValueFiles'][$key]['ID_absFile']);
+                                       }
+                               }
+                               // For all flex type relations:
+                               if ($vR['type'] == 'flex') {
+                                       if (is_array($vR['flexFormRels']['file'])) {
+                                               foreach ($vR['flexFormRels']['file'] as $key => $subList) {
+                                                       foreach ($subList as $subKey => $fI) {
                                                                $this->export_addFile($fI, $k, $fieldname);
                                                                // Remove the absolute reference to the file so it doesn't expose absolute paths from source server:
-                                                               unset($this->dat['records'][$k]['rels'][$fieldname]['newValueFiles'][$key]['ID_absFile']);
+                                                               unset($this->dat['records'][$k]['rels'][$fieldname]['flexFormRels']['file'][$key][$subKey]['ID_absFile']);
                                                        }
                                                }
-                                               // For all flex type relations:
-                                               if ($vR['type'] == 'flex') {
-                                                       if (is_array($vR['flexFormRels']['file'])) {
-                                                               foreach ($vR['flexFormRels']['file'] as $key => $subList) {
-                                                                       foreach ($subList as $subKey => $fI) {
-                                                                               $this->export_addFile($fI, $k, $fieldname);
-                                                                               // Remove the absolute reference to the file so it doesn't expose absolute paths from source server:
-                                                                               unset($this->dat['records'][$k]['rels'][$fieldname]['flexFormRels']['file'][$key][$subKey]['ID_absFile']);
-                                                                       }
-                                                               }
-                                                       }
-                                                       // DB oriented soft references in flex form fields:
-                                                       if (is_array($vR['flexFormRels']['softrefs'])) {
-                                                               foreach ($vR['flexFormRels']['softrefs'] as $key => $subList) {
-                                                                       foreach ($subList['keys'] as $spKey => $elements) {
-                                                                               foreach ($elements as $subKey => $el) {
-                                                                                       if ($el['subst']['type'] === 'file' && $this->includeSoftref($el['subst']['tokenID'])) {
-                                                                                               // Create abs path and ID for file:
-                                                                                               $ID_absFile = GeneralUtility::getFileAbsFileName(PATH_site . $el['subst']['relFileName']);
-                                                                                               $ID = md5($el['subst']['relFileName']);
-                                                                                               if ($ID_absFile) {
-                                                                                                       if (!$this->dat['files'][$ID]) {
-                                                                                                               $fI = array(
-                                                                                                                       'filename' => PathUtility::basename($ID_absFile),
-                                                                                                                       'ID_absFile' => $ID_absFile,
-                                                                                                                       'ID' => $ID,
-                                                                                                                       'relFileName' => $el['subst']['relFileName']
-                                                                                                               );
-                                                                                                               $this->export_addFile($fI, '_SOFTREF_');
-                                                                                                       }
-                                                                                                       $this->dat['records'][$k]['rels'][$fieldname]['flexFormRels']['softrefs'][$key]['keys'][$spKey][$subKey]['file_ID'] = $ID;
-                                                                                               }
-                                                                                       }
-                                                                               }
-                                                                       }
-                                                               }
-                                                       }
-                                               }
-                                               // In any case, if there are soft refs:
-                                               if (is_array($vR['softrefs']['keys'])) {
-                                                       foreach ($vR['softrefs']['keys'] as $spKey => $elements) {
+                                       }
+                                       // DB oriented soft references in flex form fields:
+                                       if (is_array($vR['flexFormRels']['softrefs'])) {
+                                               foreach ($vR['flexFormRels']['softrefs'] as $key => $subList) {
+                                                       foreach ($subList['keys'] as $spKey => $elements) {
                                                                foreach ($elements as $subKey => $el) {
                                                                        if ($el['subst']['type'] === 'file' && $this->includeSoftref($el['subst']['tokenID'])) {
                                                                                // Create abs path and ID for file:
@@ -928,7 +977,7 @@ class ImportExport {
                                                                                                );
                                                                                                $this->export_addFile($fI, '_SOFTREF_');
                                                                                        }
-                                                                                       $this->dat['records'][$k]['rels'][$fieldname]['softrefs']['keys'][$spKey][$subKey]['file_ID'] = $ID;
+                                                                                       $this->dat['records'][$k]['rels'][$fieldname]['flexFormRels']['softrefs'][$key]['keys'][$spKey][$subKey]['file_ID'] = $ID;
                                                                                }
                                                                        }
                                                                }
@@ -936,9 +985,31 @@ class ImportExport {
                                                }
                                        }
                                }
+                               // In any case, if there are soft refs:
+                               if (is_array($vR['softrefs']['keys'])) {
+                                       foreach ($vR['softrefs']['keys'] as $spKey => $elements) {
+                                               foreach ($elements as $subKey => $el) {
+                                                       if ($el['subst']['type'] === 'file' && $this->includeSoftref($el['subst']['tokenID'])) {
+                                                               // Create abs path and ID for file:
+                                                               $ID_absFile = GeneralUtility::getFileAbsFileName(PATH_site . $el['subst']['relFileName']);
+                                                               $ID = md5($el['subst']['relFileName']);
+                                                               if ($ID_absFile) {
+                                                                       if (!$this->dat['files'][$ID]) {
+                                                                               $fI = array(
+                                                                                       'filename' => PathUtility::basename($ID_absFile),
+                                                                                       'ID_absFile' => $ID_absFile,
+                                                                                       'ID' => $ID,
+                                                                                       'relFileName' => $el['subst']['relFileName']
+                                                                               );
+                                                                               $this->export_addFile($fI, '_SOFTREF_');
+                                                                       }
+                                                                       $this->dat['records'][$k]['rels'][$fieldname]['softrefs']['keys'][$spKey][$subKey]['file_ID'] = $ID;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
                        }
-               } else {
-                       $this->error('There were no records available.');
                }
        }
 
@@ -953,7 +1024,7 @@ class ImportExport {
                }
                foreach (array_keys($this->dat['header']['records']['sys_file']) as $sysFileUid) {
                        $recordData = $this->dat['records']['sys_file:' . $sysFileUid]['data'];
-                       $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->createFileObject($recordData);
+                       $file = ResourceFactory::getInstance()->createFileObject($recordData);
                        $this->export_addSysFile($file);
                }
        }
@@ -969,6 +1040,7 @@ class ImportExport {
                        $this->error('File ' . $file->getPublicUrl() . ' was larger (' . GeneralUtility::formatSize($file->getProperty('size')) . ') than the maxFileSize (' . GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.');
                        return;
                }
+               $fileContent = '';
                try {
                        if (!$this->saveFilesOutsideExportFile) {
                                $fileContent = $file->getContents();
@@ -1030,121 +1102,121 @@ class ImportExport {
         * @todo Define visibility
         */
        public function export_addFile($fI, $recordRef = '', $fieldname = '') {
-               if (@is_file($fI['ID_absFile'])) {
-                       if (filesize($fI['ID_absFile']) < $this->maxFileSize) {
-                               $fileInfo = stat($fI['ID_absFile']);
-                               $fileRec = array();
-                               $fileRec['filesize'] = $fileInfo['size'];
-                               $fileRec['filename'] = PathUtility::basename($fI['ID_absFile']);
-                               $fileRec['filemtime'] = $fileInfo['mtime'];
-                               //for internal type file_reference
-                               $fileRec['relFileRef'] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($fI['ID_absFile']);
-                               if ($recordRef) {
-                                       $fileRec['record_ref'] = $recordRef . '/' . $fieldname;
-                               }
-                               if ($fI['relFileName']) {
-                                       $fileRec['relFileName'] = $fI['relFileName'];
-                               }
-                               // Setting this data in the header
-                               $this->dat['header']['files'][$fI['ID']] = $fileRec;
-                               // ... and for the recordlisting, why not let us know WHICH relations there was...
-                               if ($recordRef && $recordRef !== '_SOFTREF_') {
-                                       $refParts = explode(':', $recordRef, 2);
-                                       if (!is_array($this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'])) {
-                                               $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'] = array();
+               if (!@is_file($fI['ID_absFile'])) {
+                       $this->error($fI['ID_absFile'] . ' was not a file! Skipping.');
+                       return;
+               }
+               if (filesize($fI['ID_absFile']) >= $this->maxFileSize) {
+                       $this->error($fI['ID_absFile'] . ' was larger (' . GeneralUtility::formatSize(filesize($fI['ID_absFile'])) . ') than the maxFileSize (' . GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.');
+                       return;
+               }
+               $fileInfo = stat($fI['ID_absFile']);
+               $fileRec = array();
+               $fileRec['filesize'] = $fileInfo['size'];
+               $fileRec['filename'] = PathUtility::basename($fI['ID_absFile']);
+               $fileRec['filemtime'] = $fileInfo['mtime'];
+               //for internal type file_reference
+               $fileRec['relFileRef'] = PathUtility::stripPathSitePrefix($fI['ID_absFile']);
+               if ($recordRef) {
+                       $fileRec['record_ref'] = $recordRef . '/' . $fieldname;
+               }
+               if ($fI['relFileName']) {
+                       $fileRec['relFileName'] = $fI['relFileName'];
+               }
+               // Setting this data in the header
+               $this->dat['header']['files'][$fI['ID']] = $fileRec;
+               // ... and for the recordlisting, why not let us know WHICH relations there was...
+               if ($recordRef && $recordRef !== '_SOFTREF_') {
+                       $refParts = explode(':', $recordRef, 2);
+                       if (!is_array($this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'])) {
+                               $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'] = array();
+                       }
+                       $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'][] = $fI['ID'];
+               }
+               $fileMd5 = md5_file($fI['ID_absFile']);
+               if (!$this->saveFilesOutsideExportFile) {
+                       // ... and finally add the heavy stuff:
+                       $fileRec['content'] = GeneralUtility::getUrl($fI['ID_absFile']);
+               } else {
+                       GeneralUtility::upload_copy_move($fI['ID_absFile'], $this->getTemporaryFilesPathForExport() . $fileMd5);
+               }
+               $fileRec['content_md5'] = $fileMd5;
+               $this->dat['files'][$fI['ID']] = $fileRec;
+               // For soft references, do further processing:
+               if ($recordRef === '_SOFTREF_') {
+                       // RTE files?
+                       if ($RTEoriginal = $this->getRTEoriginalFilename(PathUtility::basename($fI['ID_absFile']))) {
+                               $RTEoriginal_absPath = PathUtility::dirname($fI['ID_absFile']) . '/' . $RTEoriginal;
+                               if (@is_file($RTEoriginal_absPath)) {
+                                       $RTEoriginal_ID = md5($RTEoriginal_absPath);
+                                       $fileInfo = stat($RTEoriginal_absPath);
+                                       $fileRec = array();
+                                       $fileRec['filesize'] = $fileInfo['size'];
+                                       $fileRec['filename'] = PathUtility::basename($RTEoriginal_absPath);
+                                       $fileRec['filemtime'] = $fileInfo['mtime'];
+                                       $fileRec['record_ref'] = '_RTE_COPY_ID:' . $fI['ID'];
+                                       $this->dat['header']['files'][$fI['ID']]['RTE_ORIG_ID'] = $RTEoriginal_ID;
+                                       // Setting this data in the header
+                                       $this->dat['header']['files'][$RTEoriginal_ID] = $fileRec;
+                                       $fileMd5 = md5_file($RTEoriginal_absPath);
+                                       if (!$this->saveFilesOutsideExportFile) {
+                                               // ... and finally add the heavy stuff:
+                                               $fileRec['content'] = GeneralUtility::getUrl($RTEoriginal_absPath);
+                                       } else {
+                                               GeneralUtility::upload_copy_move($RTEoriginal_absPath, $this->getTemporaryFilesPathForExport() . $fileMd5);
                                        }
-                                       $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'][] = $fI['ID'];
+                                       $fileRec['content_md5'] = $fileMd5;
+                                       $this->dat['files'][$RTEoriginal_ID] = $fileRec;
+                               } else {
+                                       $this->error('RTE original file "' . PathUtility::stripPathSitePrefix($RTEoriginal_absPath) . '" was not found!');
                                }
-                               $fileMd5 = md5_file($fI['ID_absFile']);
-                               if (!$this->saveFilesOutsideExportFile) {
-                                       // ... and finally add the heavy stuff:
-                                       $fileRec['content'] = GeneralUtility::getUrl($fI['ID_absFile']);
+                       }
+                       // Files with external media?
+                       // This is only done with files grabbed by a softreference parser since it is deemed improbable that hard-referenced files should undergo this treatment.
+                       $html_fI = pathinfo(PathUtility::basename($fI['ID_absFile']));
+                       if ($this->includeExtFileResources && GeneralUtility::inList($this->extFileResourceExtensions, strtolower($html_fI['extension']))) {
+                               $uniquePrefix = '###' . md5($GLOBALS['EXEC_TIME']) . '###';
+                               if (strtolower($html_fI['extension']) === 'css') {
+                                       $prefixedMedias = explode($uniquePrefix, preg_replace('/(url[[:space:]]*\\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\\))/i', '\\1' . $uniquePrefix . '\\2' . $uniquePrefix . '\\3', $fileRec['content']));
                                } else {
-                                       GeneralUtility::upload_copy_move($fI['ID_absFile'], $this->getTemporaryFilesPathForExport() . $fileMd5);
+                                       // html, htm:
+                                       $htmlParser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\HtmlParser');
+                                       $prefixedMedias = explode($uniquePrefix, $htmlParser->prefixResourcePath($uniquePrefix, $fileRec['content'], array(), $uniquePrefix));
                                }
-                               $fileRec['content_md5'] = $fileMd5;
-                               $this->dat['files'][$fI['ID']] = $fileRec;
-                               // For soft references, do further processing:
-                               if ($recordRef === '_SOFTREF_') {
-                                       // RTE files?
-                                       if ($RTEoriginal = $this->getRTEoriginalFilename(PathUtility::basename($fI['ID_absFile']))) {
-                                               $RTEoriginal_absPath = PathUtility::dirname($fI['ID_absFile']) . '/' . $RTEoriginal;
-                                               if (@is_file($RTEoriginal_absPath)) {
-                                                       $RTEoriginal_ID = md5($RTEoriginal_absPath);
-                                                       $fileInfo = stat($RTEoriginal_absPath);
-                                                       $fileRec = array();
-                                                       $fileRec['filesize'] = $fileInfo['size'];
-                                                       $fileRec['filename'] = PathUtility::basename($RTEoriginal_absPath);
-                                                       $fileRec['filemtime'] = $fileInfo['mtime'];
-                                                       $fileRec['record_ref'] = '_RTE_COPY_ID:' . $fI['ID'];
-                                                       $this->dat['header']['files'][$fI['ID']]['RTE_ORIG_ID'] = $RTEoriginal_ID;
-                                                       // Setting this data in the header
-                                                       $this->dat['header']['files'][$RTEoriginal_ID] = $fileRec;
-                                                       $fileMd5 = md5_file($RTEoriginal_absPath);
-                                                       if (!$this->saveFilesOutsideExportFile) {
+                               $htmlResourceCaptured = FALSE;
+                               foreach ($prefixedMedias as $k => $v) {
+                                       if ($k % 2) {
+                                               $EXTres_absPath = GeneralUtility::resolveBackPath(PathUtility::dirname($fI['ID_absFile']) . '/' . $v);
+                                               $EXTres_absPath = GeneralUtility::getFileAbsFileName($EXTres_absPath);
+                                               if ($EXTres_absPath && GeneralUtility::isFirstPartOfStr($EXTres_absPath, PATH_site . $this->fileadminFolderName . '/') && @is_file($EXTres_absPath)) {
+                                                       $htmlResourceCaptured = TRUE;
+                                                       $EXTres_ID = md5($EXTres_absPath);
+                                                       $this->dat['header']['files'][$fI['ID']]['EXT_RES_ID'][] = $EXTres_ID;
+                                                       $prefixedMedias[$k] = '{EXT_RES_ID:' . $EXTres_ID . '}';
+                                                       // Add file to memory if it is not set already:
+                                                       if (!isset($this->dat['header']['files'][$EXTres_ID])) {
+                                                               $fileInfo = stat($EXTres_absPath);
+                                                               $fileRec = array();
+                                                               $fileRec['filesize'] = $fileInfo['size'];
+                                                               $fileRec['filename'] = PathUtility::basename($EXTres_absPath);
+                                                               $fileRec['filemtime'] = $fileInfo['mtime'];
+                                                               $fileRec['record_ref'] = '_EXT_PARENT_:' . $fI['ID'];
+                                                               // Media relative to the HTML file.
+                                                               $fileRec['parentRelFileName'] = $v;
+                                                               // Setting this data in the header
+                                                               $this->dat['header']['files'][$EXTres_ID] = $fileRec;
                                                                // ... and finally add the heavy stuff:
-                                                               $fileRec['content'] = GeneralUtility::getUrl($RTEoriginal_absPath);
-                                                       } else {
-                                                               GeneralUtility::upload_copy_move($RTEoriginal_absPath, $this->getTemporaryFilesPathForExport() . $fileMd5);
-                                                       }
-                                                       $fileRec['content_md5'] = $fileMd5;
-                                                       $this->dat['files'][$RTEoriginal_ID] = $fileRec;
-                                               } else {
-                                                       $this->error('RTE original file "' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($RTEoriginal_absPath) . '" was not found!');
-                                               }
-                                       }
-                                       // Files with external media?
-                                       // This is only done with files grabbed by a softreference parser since it is deemed improbable that hard-referenced files should undergo this treatment.
-                                       $html_fI = pathinfo(PathUtility::basename($fI['ID_absFile']));
-                                       if ($this->includeExtFileResources && GeneralUtility::inList($this->extFileResourceExtensions, strtolower($html_fI['extension']))) {
-                                               $uniquePrefix = '###' . md5($GLOBALS['EXEC_TIME']) . '###';
-                                               if (strtolower($html_fI['extension']) === 'css') {
-                                                       $prefixedMedias = explode($uniquePrefix, preg_replace('/(url[[:space:]]*\\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\\))/i', '\\1' . $uniquePrefix . '\\2' . $uniquePrefix . '\\3', $fileRec['content']));
-                                               } else {
-                                                       // html, htm:
-                                                       $htmlParser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\HtmlParser');
-                                                       $prefixedMedias = explode($uniquePrefix, $htmlParser->prefixResourcePath($uniquePrefix, $fileRec['content'], array(), $uniquePrefix));
-                                               }
-                                               $htmlResourceCaptured = FALSE;
-                                               foreach ($prefixedMedias as $k => $v) {
-                                                       if ($k % 2) {
-                                                               $EXTres_absPath = GeneralUtility::resolveBackPath(PathUtility::dirname($fI['ID_absFile']) . '/' . $v);
-                                                               $EXTres_absPath = GeneralUtility::getFileAbsFileName($EXTres_absPath);
-                                                               if ($EXTres_absPath && GeneralUtility::isFirstPartOfStr($EXTres_absPath, PATH_site . $this->fileadminFolderName . '/') && @is_file($EXTres_absPath)) {
-                                                                       $htmlResourceCaptured = TRUE;
-                                                                       $EXTres_ID = md5($EXTres_absPath);
-                                                                       $this->dat['header']['files'][$fI['ID']]['EXT_RES_ID'][] = $EXTres_ID;
-                                                                       $prefixedMedias[$k] = '{EXT_RES_ID:' . $EXTres_ID . '}';
-                                                                       // Add file to memory if it is not set already:
-                                                                       if (!isset($this->dat['header']['files'][$EXTres_ID])) {
-                                                                               $fileInfo = stat($EXTres_absPath);
-                                                                               $fileRec = array();
-                                                                               $fileRec['filesize'] = $fileInfo['size'];
-                                                                               $fileRec['filename'] = PathUtility::basename($EXTres_absPath);
-                                                                               $fileRec['filemtime'] = $fileInfo['mtime'];
-                                                                               $fileRec['record_ref'] = '_EXT_PARENT_:' . $fI['ID'];
-                                                                               // Media relative to the HTML file.
-                                                                               $fileRec['parentRelFileName'] = $v;
-                                                                               // Setting this data in the header
-                                                                               $this->dat['header']['files'][$EXTres_ID] = $fileRec;
-                                                                               // ... and finally add the heavy stuff:
-                                                                               $fileRec['content'] = GeneralUtility::getUrl($EXTres_absPath);
-                                                                               $fileRec['content_md5'] = md5($fileRec['content']);
-                                                                               $this->dat['files'][$EXTres_ID] = $fileRec;
-                                                                       }
-                                                               }
+                                                               $fileRec['content'] = GeneralUtility::getUrl($EXTres_absPath);
+                                                               $fileRec['content_md5'] = md5($fileRec['content']);
+                                                               $this->dat['files'][$EXTres_ID] = $fileRec;
                                                        }
                                                }
-                                               if ($htmlResourceCaptured) {
-                                                       $this->dat['files'][$fI['ID']]['tokenizedContent'] = implode('', $prefixedMedias);
-                                               }
                                        }
                                }
-                       } else {
-                               $this->error($fI['ID_absFile'] . ' was larger (' . GeneralUtility::formatSize(filesize($fI['ID_absFile'])) . ') than the maxFileSize (' . GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.');
+                               if ($htmlResourceCaptured) {
+                                       $this->dat['files'][$fI['ID']]['tokenizedContent'] = implode('', $prefixedMedias);
+                               }
                        }
-               } else {
-                       $this->error($fI['ID_absFile'] . ' was not a file! Skipping.');
                }
        }
 
@@ -1223,7 +1295,8 @@ class ImportExport {
                                                foreach ($elements as $subKey => $el) {
                                                        $lKey = $field . ':' . $spKey . ':' . $subKey;
                                                        $list[$lKey] = array_merge(array('field' => $field, 'spKey' => $spKey), $el);
-                                                       // Add file_ID key to header - slightly "risky" way of doing this because if the calculation changes for the same value in $this->records[...] this will not work anymore!
+                                                       // Add file_ID key to header - slightly "risky" way of doing this because if the calculation
+                                                       // changes for the same value in $this->records[...] this will not work anymore!
                                                        if ($el['subst'] && $el['subst']['relFileName']) {
                                                                $list[$lKey]['file_ID'] = md5(PATH_site . $el['subst']['relFileName']);
                                                        }
@@ -1238,7 +1311,8 @@ class ImportExport {
                                                        foreach ($elements as $subKey => $el) {
                                                                $lKey = $field . ':' . $structurePath . ':' . $spKey . ':' . $subKey;
                                                                $list[$lKey] = array_merge(array('field' => $field, 'spKey' => $spKey, 'structurePath' => $structurePath), $el);
-                                                               // Add file_ID key to header - slightly "risky" way of doing this because if the calculation changes for the same value in $this->records[...] this will not work anymore!
+                                                               // Add file_ID key to header - slightly "risky" way of doing this because if the calculation
+                                                               // changes for the same value in $this->records[...] this will not work anymore!
                                                                if ($el['subst'] && $el['subst']['relFileName']) {
                                                                        $list[$lKey]['file_ID'] = md5(PATH_site . $el['subst']['relFileName']);
                                                                }
@@ -1465,7 +1539,6 @@ class ImportExport {
                $this->storageObjects = $storageRepository->findAll();
        }
 
-
        /**
         * Imports the internal data array to $pid.
         *
@@ -1519,9 +1592,12 @@ class ImportExport {
                                        // check the available storage for Local, writable and online ones
                                        if ($localStorage->getDriverType() === 'Local' && $localStorage->isWritable() && $localStorage->isOnline()) {
                                                // check if there is already a identical storage present (same pathType and basePath)
-                                               $storageRecordConfiguration = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
+                                               $storageRecordConfiguration = ResourceFactory::getInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
                                                $localStorageRecordConfiguration = $localStorage->getConfiguration();
-                                               if ($storageRecordConfiguration['pathType'] == $localStorageRecordConfiguration['pathType'] && $storageRecordConfiguration['basePath'] == $localStorageRecordConfiguration['basePath']) {
+                                               if (
+                                                       $storageRecordConfiguration['pathType'] === $localStorageRecordConfiguration['pathType']
+                                                       && $storageRecordConfiguration['basePath'] === $localStorageRecordConfiguration['basePath']
+                                               ) {
                                                        // same storage is already present
                                                        $useThisStorageUidInsteadOfTheOneInImport = $localStorage->getUid();
                                                        break;
@@ -1557,7 +1633,7 @@ class ImportExport {
 
                $defaultStorageUid = NULL;
                // get default storage
-               $defaultStorage = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getDefaultStorage();
+               $defaultStorage = ResourceFactory::getInstance()->getDefaultStorage();
                if ($defaultStorage !== NULL) {
                        $defaultStorageUid = $defaultStorage->getUid();
                }
@@ -1582,7 +1658,7 @@ class ImportExport {
                // fetch fresh storage records from database
                $storageRecords = $this->fetchStorageRecords();
 
-               $defaultStorage = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getDefaultStorage();
+               $defaultStorage = ResourceFactory::getInstance()->getDefaultStorage();
 
                $sanitizedFolderMappings = array();
 
@@ -1626,9 +1702,9 @@ class ImportExport {
                        // mapping. Only in this case we could be sure, that it's a local, online and writable storage.
                        if ($useStorageFromStorageRecords && isset($storageRecords[$fileRecord['storage']])) {
                                /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
-                               $storage = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($fileRecord['storage'], $storageRecords[$fileRecord['storage']]);
+                               $storage = ResourceFactory::getInstance()->getStorageObject($fileRecord['storage'], $storageRecords[$fileRecord['storage']]);
                        } elseif ($this->isFallbackStorage($fileRecord['storage'])) {
-                               $storage = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject(0);
+                               $storage = ResourceFactory::getInstance()->getStorageObject(0);
                        } elseif ($defaultStorage !== NULL) {
                                $storage = $defaultStorage;
                        } else {
@@ -1669,7 +1745,7 @@ class ImportExport {
                                }
 
                                try {
-                                       /** @var $file \TYPO3\CMS\Core\Resource\File */
+                                       /** @var $newFile \TYPO3\CMS\Core\Resource\File */
                                        $newFile = $storage->addFile($temporaryFile, $importFolder, $fileRecord['name']);
                                } catch (Exception $e) {
                                        $this->error('Error: File could not be added to the storage: "' . $fileRecord['identifier'] . '" with storage uid "' . $fileRecord['storage'] . '"');
@@ -1761,8 +1837,8 @@ class ImportExport {
         * @return bool|array
         */
        protected function fetchStorageRecords() {
-               $whereClause = \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('sys_file_storage');
-               $whereClause .= \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_file_storage');
+               $whereClause = BackendUtility::BEenableFields('sys_file_storage');
+               $whereClause .= BackendUtility::deleteClause('sys_file_storage');
 
                $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
                        '*',
@@ -2008,7 +2084,8 @@ class ImportExport {
 
        /**
         * Adds a single record to the $importData array. Also copies files to tempfolder.
-        * However all File/DB-references and flexform field contents are set to blank for now! That is done with setRelations() later
+        * However all File/DB-references and flexform field contents are set to blank for now!
+        * That is done with setRelations() later
         *
         * @param string $table Table name (from import memory)
         * @param integer $uid Record UID (from import memory)
@@ -2018,86 +2095,89 @@ class ImportExport {
         * @todo Define visibility
         */
        public function addSingle($table, $uid, $pid) {
-               if ($this->import_mode[$table . ':' . $uid] !== 'exclude') {
-                       $record = $this->dat['records'][$table . ':' . $uid]['data'];
-                       if (is_array($record)) {
-                               if ($this->update && $this->doesRecordExist($table, $uid) && $this->import_mode[$table . ':' . $uid] !== 'as_new') {
-                                       $ID = $uid;
-                               } elseif ($table === 'sys_file_metadata' && $record['sys_language_uid'] == '0' && $this->import_mapId['sys_file'][$record['file']]) {
-                                       // on adding sys_file records the belonging sys_file_metadata record was also created
-                                       // if there is one the record need to be overwritten instead of creating a new one.
-                                       $recordInDatabase = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
-                                               'uid',
-                                               'sys_file_metadata',
-                                               'file = ' . $this->import_mapId['sys_file'][$record['file']] . ' AND sys_language_uid = 0 AND pid = 0'
-                                       );
-                                       // if no record could be found, $this->import_mapId['sys_file'][$record['file']] is pointing
-                                       // to a file, that was already there, thus a new metadata record should be created
-                                       if (is_array($recordInDatabase)) {
-                                               $this->import_mapId['sys_file_metadata'][$record['uid']] = $recordInDatabase['uid'];
-                                               $ID = $recordInDatabase['uid'];
-                                       } else {
-                                               $ID = uniqid('NEW');
-                                       }
-
+               if ($this->import_mode[$table . ':' . $uid] === 'exclude') {
+                       return;
+               }
+               $record = $this->dat['records'][$table . ':' . $uid]['data'];
+               if (is_array($record)) {
+                       if ($this->update && $this->doesRecordExist($table, $uid) && $this->import_mode[$table . ':' . $uid] !== 'as_new') {
+                               $ID = $uid;
+                       } elseif ($table === 'sys_file_metadata' && $record['sys_language_uid'] == '0' && $this->import_mapId['sys_file'][$record['file']]) {
+                               // on adding sys_file records the belonging sys_file_metadata record was also created
+                               // if there is one the record need to be overwritten instead of creating a new one.
+                               $recordInDatabase = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
+                                       'uid',
+                                       'sys_file_metadata',
+                                       'file = ' . $this->import_mapId['sys_file'][$record['file']] . ' AND sys_language_uid = 0 AND pid = 0'
+                               );
+                               // if no record could be found, $this->import_mapId['sys_file'][$record['file']] is pointing
+                               // to a file, that was already there, thus a new metadata record should be created
+                               if (is_array($recordInDatabase)) {
+                                       $this->import_mapId['sys_file_metadata'][$record['uid']] = $recordInDatabase['uid'];
+                                       $ID = $recordInDatabase['uid'];
                                } else {
                                        $ID = uniqid('NEW');
                                }
-                               $this->import_newId[$table . ':' . $ID] = array('table' => $table, 'uid' => $uid);
-                               if ($table == 'pages') {
-                                       $this->import_newId_pids[$uid] = $ID;
-                               }
-                               // Set main record data:
-                               $this->import_data[$table][$ID] = $record;
-                               $this->import_data[$table][$ID]['tx_impexp_origuid'] = $this->import_data[$table][$ID]['uid'];
-                               // Reset permission data:
-                               if ($table === 'pages') {
-                                       // Have to reset the user/group IDs so pages are owned by importing user. Otherwise strange things may happen for non-admins!
-                                       unset($this->import_data[$table][$ID]['perms_userid']);
-                                       unset($this->import_data[$table][$ID]['perms_groupid']);
-                               }
-                               // PID and UID:
-                               unset($this->import_data[$table][$ID]['uid']);
-                               // Updates:
-                               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($ID)) {
-                                       unset($this->import_data[$table][$ID]['pid']);
-                               } else {
-                                       // Inserts:
-                                       $this->import_data[$table][$ID]['pid'] = $pid;
-                                       if (($this->import_mode[$table . ':' . $uid] === 'force_uid' && $this->update || $this->force_all_UIDS) && $GLOBALS['BE_USER']->isAdmin()) {
-                                               $this->import_data[$table][$ID]['uid'] = $uid;
-                                               $this->suggestedInsertUids[$table . ':' . $uid] = 'DELETE';
-                                       }
-                               }
-                               // Setting db/file blank:
-                               foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
-                                       switch ((string) $config['type']) {
-                                               case 'db':
 
-                                               case 'file':
-                                                       // Fixed later in ->setRelations() [because we need to know ALL newly created IDs before we can map relations!]
-                                                       // In the meantime we set NO values for relations.
-                                                       //
-                                                       // BUT for field uid_local of table sys_file_reference the relation MUST not be cleared here,
-                                                       // because the value is already the uid of the right imported sys_file record.
-                                                       // @see fixUidLocalInSysFileReferenceRecords()
-                                                       // If it's empty or a uid to another record the FileExtensionFilter will throw an exception or
-                                                       // delete the reference record if the file extension of the related record doesn't match.
-                                                       if ($table !== 'sys_file_reference' && $field !== 'uid_local') {
-                                                               $this->import_data[$table][$ID][$field] = '';
-                                                       }
-                                                       break;
-                                               case 'flex':
-                                                       // Fixed later in setFlexFormRelations()
-                                                       // In the meantime we set NO value for flexforms - this is mainly because file references inside will not be processed properly; In fact references will point to no file or existing files (in which case there will be double-references which is a big problem of course!)
+                       } else {
+                               $ID = uniqid('NEW');
+                       }
+                       $this->import_newId[$table . ':' . $ID] = array('table' => $table, 'uid' => $uid);
+                       if ($table == 'pages') {
+                               $this->import_newId_pids[$uid] = $ID;
+                       }
+                       // Set main record data:
+                       $this->import_data[$table][$ID] = $record;
+                       $this->import_data[$table][$ID]['tx_impexp_origuid'] = $this->import_data[$table][$ID]['uid'];
+                       // Reset permission data:
+                       if ($table === 'pages') {
+                               // Have to reset the user/group IDs so pages are owned by importing user. Otherwise strange things may happen for non-admins!
+                               unset($this->import_data[$table][$ID]['perms_userid']);
+                               unset($this->import_data[$table][$ID]['perms_groupid']);
+                       }
+                       // PID and UID:
+                       unset($this->import_data[$table][$ID]['uid']);
+                       // Updates:
+                       if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($ID)) {
+                               unset($this->import_data[$table][$ID]['pid']);
+                       } else {
+                               // Inserts:
+                               $this->import_data[$table][$ID]['pid'] = $pid;
+                               if (($this->import_mode[$table . ':' . $uid] === 'force_uid' && $this->update || $this->force_all_UIDS) && $GLOBALS['BE_USER']->isAdmin()) {
+                                       $this->import_data[$table][$ID]['uid'] = $uid;
+                                       $this->suggestedInsertUids[$table . ':' . $uid] = 'DELETE';
+                               }
+                       }
+                       // Setting db/file blank:
+                       foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
+                               switch ((string) $config['type']) {
+                                       case 'db':
+
+                                       case 'file':
+                                               // Fixed later in ->setRelations() [because we need to know ALL newly created IDs before we can map relations!]
+                                               // In the meantime we set NO values for relations.
+                                               //
+                                               // BUT for field uid_local of table sys_file_reference the relation MUST not be cleared here,
+                                               // because the value is already the uid of the right imported sys_file record.
+                                               // @see fixUidLocalInSysFileReferenceRecords()
+                                               // If it's empty or a uid to another record the FileExtensionFilter will throw an exception or
+                                               // delete the reference record if the file extension of the related record doesn't match.
+                                               if ($table !== 'sys_file_reference' && $field !== 'uid_local') {
                                                        $this->import_data[$table][$ID][$field] = '';
-                                                       break;
-                                       }
+                                               }
+                                               break;
+                                       case 'flex':
+                                               // Fixed later in setFlexFormRelations()
+                                               // In the meantime we set NO value for flexforms - this is mainly because file references
+                                               // inside will not be processed properly; In fact references will point to no file
+                                               // or existing files (in which case there will be double-references which is a big problem of course!)
+                                               $this->import_data[$table][$ID][$field] = '';
+                                               break;
                                }
-                       } elseif ($table . ':' . $uid != 'pages:0') {
-                               // On root level we don't want this error message.
-                               $this->error('Error: no record was found in data array!', 1);
                        }
+               } elseif ($table . ':' . $uid != 'pages:0') {
+                       // On root level we don't want this error message.
+                       $this->error('Error: no record was found in data array!', 1);
                }
        }
 
@@ -2119,7 +2199,8 @@ class ImportExport {
                                        // Map same ID to same ID....
                                        $this->import_mapId[$table][$old_uid] = $id;
                                } else {
-                                       // if $this->import_mapId contains already the right mapping, skip the error msg. See special handling of sys_file_metadata in addSingle() => nothing to do
+                                       // if $this->import_mapId contains already the right mapping, skip the error msg.
+                                       // See special handling of sys_file_metadata in addSingle() => nothing to do
                                        if (!($table === 'sys_file_metadata' && isset($this->import_mapId[$table][$old_uid]) && $this->import_mapId[$table][$old_uid] == $id)) {
                                                $this->error('Possible error: ' . $table . ':' . $old_uid . ' had no new id assigned to it. This indicates that the record was not added to database during import. Please check changelog!', 1);
                                        }
@@ -2190,10 +2271,11 @@ class ImportExport {
                        if (is_array($this->import_mapId[$table]) && isset($this->import_mapId[$table][$uid])) {
                                $thisNewUid = BackendUtility::wsMapId($table, $this->import_mapId[$table][$uid]);
                                if (is_array($this->dat['records'][$table . ':' . $uid]['rels'])) {
+                                       $thisNewPageUid = 0;
                                        if ($this->legacyImport) {
                                                if ($table != 'pages') {
                                                        $oldPid = $this->dat['records'][$table . ':' . $uid]['data']['pid'];
-                                                       $thisNewPageUid = \TYPO3\CMS\Backend\Utility\BackendUtility::wsMapId($table, $this->import_mapId['pages'][$oldPid]);
+                                                       $thisNewPageUid = BackendUtility::wsMapId($table, $this->import_mapId['pages'][$oldPid]);
                                                } else {
                                                        $thisNewPageUid = $thisNewUid;
                                                }
@@ -2322,7 +2404,8 @@ class ImportExport {
                                }
                                $valArray[] = $value;
                        } elseif ($this->isTableStatic($relDat['table']) || $this->isExcluded($relDat['table'], $relDat['id']) || $relDat['id'] < 0) {
-                               // Checking for less than zero because some select types could contain negative values, eg. fe_groups (-1, -2) and sys_language (-1 = ALL languages). This must be handled on both export and import.
+                               // Checking for less than zero because some select types could contain negative values,
+                               // eg. fe_groups (-1, -2) and sys_language (-1 = ALL languages). This must be handled on both export and import.
                                $valArray[] = $relDat['table'] . '_' . $relDat['id'];
                        } else {
                                $this->error('Lost relation: ' . $relDat['table'] . ':' . $relDat['id'], 1);
@@ -2335,7 +2418,7 @@ class ImportExport {
         * Writes the file from import array to temp dir and returns the filename of it.
         *
         * @param array $fI File information with three keys: "filename" = filename without path, "ID_absFile" = absolute filepath to the file (including the filename), "ID" = md5 hash of "ID_absFile
-        * @return string Absolute filename of the temporary filename of the file. In ->alternativeFileName the original name is set.
+        * @return string|NULL Absolute filename of the temporary filename of the file. In ->alternativeFileName the original name is set.
         * @todo Define visibility
         */
        public function import_addFileNameToBeCopied($fI) {
@@ -2368,6 +2451,7 @@ class ImportExport {
                } else {
                        $this->error('Error: No file found for ID ' . $fI['ID'], 1);
                }
+               return NULL;
        }
 
        /**
@@ -2386,42 +2470,50 @@ class ImportExport {
                        $uid = $dat['uid'];
                        // original UID - NOT the new one!
                        // If the record has been written and received a new id, then proceed:
-                       if (is_array($this->import_mapId[$table]) && isset($this->import_mapId[$table][$uid])) {
-                               $thisNewUid = BackendUtility::wsMapId($table, $this->import_mapId[$table][$uid]);
-                               if (is_array($this->dat['records'][$table . ':' . $uid]['rels'])) {
-                                       // Traverse relation fields of each record
-                                       foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
-                                               switch ((string) $config['type']) {
-                                                       case 'flex':
-                                                               // Get XML content and set as default value (string, non-processed):
-                                                               $updateData[$table][$thisNewUid][$field] = $this->dat['records'][$table . ':' . $uid]['data'][$field];
-                                                               // If there has been registered relations inside the flex form field, run processing on the content:
-                                                               if (count($config['flexFormRels']['db']) || count($config['flexFormRels']['file'])) {
-                                                                       $origRecordRow = BackendUtility::getRecord($table, $thisNewUid, '*');
-                                                                       // This will fetch the new row for the element (which should be updated with any references to data structures etc.)
-                                                                       $conf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
-                                                                       if (is_array($origRecordRow) && is_array($conf) && $conf['type'] === 'flex') {
-                                                                               // Get current data structure and value array:
-                                                                               $dataStructArray = BackendUtility::getFlexFormDS($conf, $origRecordRow, $table, $field);
-                                                                               $currentValueArray = GeneralUtility::xml2array($updateData[$table][$thisNewUid][$field]);
-                                                                               // Do recursive processing of the XML data:
-                                                                               $iteratorObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
-                                                                               $iteratorObj->callBackObj = $this;
-                                                                               $currentValueArray['data'] = $iteratorObj->checkValue_flex_procInData($currentValueArray['data'], array(), array(), $dataStructArray, array($table, $thisNewUid, $field, $config), 'remapListedDBRecords_flexFormCallBack');
-                                                                               // The return value is set as an array which means it will be processed by tcemain for file and DB references!
-                                                                               if (is_array($currentValueArray['data'])) {
-                                                                                       $updateData[$table][$thisNewUid][$field] = $currentValueArray;
-                                                                               }
-                                                                       }
+                       if (!isset($this->import_mapId[$table][$uid])) {
+                               $this->error('Error: this records is NOT created it seems! (' . $table . ':' . $uid . ')', 1);
+                               continue;
+                       }
+
+                       if (!is_array($this->dat['records'][$table . ':' . $uid]['rels'])) {
+                               $this->error('Error: no record was found in data array!', 1);
+                               continue;
+                       }
+                       $thisNewUid = BackendUtility::wsMapId($table, $this->import_mapId[$table][$uid]);
+                       // Traverse relation fields of each record
+                       foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
+                               switch ((string) $config['type']) {
+                                       case 'flex':
+                                               // Get XML content and set as default value (string, non-processed):
+                                               $updateData[$table][$thisNewUid][$field] = $this->dat['records'][$table . ':' . $uid]['data'][$field];
+                                               // If there has been registered relations inside the flex form field, run processing on the content:
+                                               if (count($config['flexFormRels']['db']) || count($config['flexFormRels']['file'])) {
+                                                       $origRecordRow = BackendUtility::getRecord($table, $thisNewUid, '*');
+                                                       // This will fetch the new row for the element (which should be updated with any references to data structures etc.)
+                                                       $conf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
+                                                       if (is_array($origRecordRow) && is_array($conf) && $conf['type'] === 'flex') {
+                                                               // Get current data structure and value array:
+                                                               $dataStructArray = BackendUtility::getFlexFormDS($conf, $origRecordRow, $table, $field);
+                                                               $currentValueArray = GeneralUtility::xml2array($updateData[$table][$thisNewUid][$field]);
+                                                               // Do recursive processing of the XML data:
+                                                               $iteratorObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
+                                                               $iteratorObj->callBackObj = $this;
+                                                               $currentValueArray['data'] = $iteratorObj->checkValue_flex_procInData(
+                                                                       $currentValueArray['data'],
+                                                                       array(),
+                                                                       array(),
+                                                                       $dataStructArray,
+                                                                       array($table, $thisNewUid, $field, $config),
+                                                                       'remapListedDBRecords_flexFormCallBack'
+                                                               );
+                                                               // The return value is set as an array which means it will be processed by tcemain for file and DB references!
+                                                               if (is_array($currentValueArray['data'])) {
+                                                                       $updateData[$table][$thisNewUid][$field] = $currentValueArray;
                                                                }
-                                                               break;
+                                                       }
                                                }
-                                       }
-                               } else {
-                                       $this->error('Error: no record was found in data array!', 1);
+                                               break;
                                }
-                       } else {
-                               $this->error('Error: this records is NOT created it seems! (' . $table . ':' . $uid . ')', 1);
                        }
                }
                if (count($updateData)) {
@@ -2464,6 +2556,7 @@ class ImportExport {
                        $dataValue = implode(',', $valArray);
                }
                if (is_array($config['flexFormRels']['file'][$path])) {
+                       $valArr = array();
                        foreach ($config['flexFormRels']['file'][$path] as $fI) {
                                $valArr[] = $this->import_addFileNameToBeCopied($fI);
                        }
@@ -2491,7 +2584,8 @@ class ImportExport {
                                foreach ($recs as $uid => $thisRec) {
                                        // If there are soft references defined, traverse those:
                                        if (isset($GLOBALS['TCA'][$table]) && is_array($thisRec['softrefs'])) {
-                                               // First traversal is to collect softref configuration and split them up based on fields. This could probably also have been done with the "records" key instead of the header.
+                                               // First traversal is to collect softref configuration and split them up based on fields.
+                                               // This could probably also have been done with the "records" key instead of the header.
                                                $fieldsIndex = array();
                                                foreach ($thisRec['softrefs'] as $softrefDef) {
                                                        // If a substitution token is set:
@@ -2539,14 +2633,14 @@ class ImportExport {
                $tce = $this->getNewTCE();
                $tce->isImporting = TRUE;
                $this->callHook('before_processSoftReferences', array(
-                       'tce' => &$tce,
+                       'tce' => $tce,
                        'data' => &$inData
                ));
                $tce->enableLogging = TRUE;
                $tce->start($inData, array());
                $tce->process_datamap();
                $this->callHook('after_processSoftReferences', array(
-                       'tce' => &$tce
+                       'tce' => $tce
                ));
        }
 
@@ -2665,13 +2759,18 @@ class ImportExport {
                                // RTE:
                                // First, find unique RTE file name:
                                if (@is_dir((PATH_site . $dirPrefix))) {
-                                       // From the "original" RTE filename, produce a new "original" destination filename which is unused. Even if updated, the image should be unique. Currently the problem with this is that it leaves a lot of unused RTE images...
+                                       // From the "original" RTE filename, produce a new "original" destination filename which is unused.
+                                       // Even if updated, the image should be unique. Currently the problem with this is that it leaves a lot of unused RTE images...
                                        $fileProcObj = $this->getFileProcObj();
                                        $origDestName = $fileProcObj->getUniqueName($rteOrigName, PATH_site . $dirPrefix);
                                        // Create copy file name:
                                        $pI = pathinfo($relFileName);
                                        $copyDestName = PathUtility::dirname($origDestName) . '/RTEmagicC_' . substr(PathUtility::basename($origDestName), 10) . '.' . $pI['extension'];
-                                       if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === GeneralUtility::getFileAbsFileName($copyDestName)) {
+                                       if (
+                                               !@is_file($copyDestName) && !@is_file($origDestName)
+                                               && $origDestName === GeneralUtility::getFileAbsFileName($origDestName)
+                                               && $copyDestName === GeneralUtility::getFileAbsFileName($copyDestName)
+                                       ) {
                                                if ($this->dat['header']['files'][$fileHeaderInfo['RTE_ORIG_ID']]) {
                                                        if ($this->legacyImport) {
                                                                $fileName = PathUtility::basename($copyDestName);
@@ -2685,7 +2784,7 @@ class ImportExport {
                                                                $this->writeFileVerify($copyDestName, $cfg['file_ID'], TRUE);
                                                                $this->writeFileVerify($origDestName, $fileHeaderInfo['RTE_ORIG_ID'], TRUE);
                                                                // Return the relative path of the copy file name:
-                                                               return \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($copyDestName);
+                                                               return PathUtility::stripPathSitePrefix($copyDestName);
                                                        }
                                                } else {
                                                        $this->error('ERROR: Could not find original file ID');
@@ -2723,13 +2822,14 @@ class ImportExport {
         * @param string $fileID File ID from import memory
         * @param string $table Table for which the processing occurs
         * @param string $uid UID of record from table
-        * @return string New relative filename, if any
+        * @return string|NULL New relative filename, if any
         * @todo Define visibility
         */
        public function processSoftReferences_saveFile_createRelFile($origDirPrefix, $fileName, $fileID, $table, $uid) {
-               // If the fileID map contains an entry for this fileID then just return the relative filename of that entry; we don't want to write another unique filename for this one!
+               // If the fileID map contains an entry for this fileID then just return the relative filename of that entry;
+               // we don't want to write another unique filename for this one!
                if (isset($this->fileIDMap[$fileID])) {
-                       return \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->fileIDMap[$fileID]);
+                       return PathUtility::stripPathSitePrefix($this->fileIDMap[$fileID]);
                }
                if ($this->legacyImport) {
                        // set dirPrefix to fileadmin because the right target folder is set and checked for permissions later
@@ -2774,7 +2874,7 @@ class ImportExport {
                                                                        $absResourceFileName = GeneralUtility::resolveBackPath(PATH_site . $origDirPrefix . $relResourceFileName);
                                                                        $absResourceFileName = GeneralUtility::getFileAbsFileName($absResourceFileName);
                                                                        if ($absResourceFileName && GeneralUtility::isFirstPartOfStr($absResourceFileName, PATH_site . $this->fileadminFolderName . '/')) {
-                                                                               $destDir = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix(PathUtility::dirname($absResourceFileName) . '/');
+                                                                               $destDir = PathUtility::stripPathSitePrefix(PathUtility::dirname($absResourceFileName) . '/');
                                                                                if ($this->verifyFolderAccess($destDir, TRUE) && $this->checkOrCreateDir($destDir)) {
                                                                                        $this->writeFileVerify($absResourceFileName, $res_fileID);
                                                                                } else {
@@ -2807,10 +2907,11 @@ class ImportExport {
                                                        GeneralUtility::writeFile($newName, $tokenizedContent);
                                                }
                                        }
-                                       return \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($newName);
+                                       return PathUtility::stripPathSitePrefix($newName);
                                }
                        }
                }
+               return NULL;
        }
 
        /**
@@ -2824,45 +2925,45 @@ class ImportExport {
         */
        public function writeFileVerify($fileName, $fileID, $bypassMountCheck = FALSE) {
                $fileProcObj = $this->getFileProcObj();
-               if ($fileProcObj->actionPerms['addFile']) {
-                       // Just for security, check again. Should actually not be necessary.
-                       if ($fileProcObj->checkPathAgainstMounts($fileName) || $bypassMountCheck) {
-                               $fI = GeneralUtility::split_fileref($fileName);
-                               if ($fileProcObj->checkIfAllowed($fI['fileext'], $fI['path'], $fI['file']) || $this->allowPHPScripts && $GLOBALS['BE_USER']->isAdmin()) {
-                                       if (GeneralUtility::getFileAbsFileName($fileName)) {
-                                               if ($this->dat['files'][$fileID]) {
-                                                       GeneralUtility::writeFile($fileName, $this->dat['files'][$fileID]['content']);
-                                                       $this->fileIDMap[$fileID] = $fileName;
-                                                       if (md5(GeneralUtility::getUrl($fileName)) == $this->dat['files'][$fileID]['content_md5']) {
-                                                               return TRUE;
-                                                       } else {
-                                                               $this->error('ERROR: File content "' . $fileName . '" was corrupted');
-                                                       }
-                                               } else {
-                                                       $this->error('ERROR: File ID "' . $fileID . '" could not be found');
-                                               }
-                                       } else {
-                                               $this->error('ERROR: Filename "' . $fileName . '" was not a valid relative file path!');
-                                       }
-                               } else {
-                                       $this->error('ERROR: Filename "' . $fileName . '" failed against extension check or deny-pattern!');
-                               }
-                       } else {
-                               $this->error('ERROR: Filename "' . $fileName . '" was not allowed in destination path!');
-                       }
-               } else {
+               if (!$fileProcObj->actionPerms['addFile']) {
                        $this->error('ERROR: You did not have sufficient permissions to write the file "' . $fileName . '"');
+                       return FALSE;
+               }
+               // Just for security, check again. Should actually not be necessary.
+               if (!$fileProcObj->checkPathAgainstMounts($fileName) && !$bypassMountCheck) {
+                       $this->error('ERROR: Filename "' . $fileName . '" was not allowed in destination path!');
+                       return FALSE;
+               }
+               $fI = GeneralUtility::split_fileref($fileName);
+               if (!$fileProcObj->checkIfAllowed($fI['fileext'], $fI['path'], $fI['file']) && (!$this->allowPHPScripts || !$GLOBALS['BE_USER']->isAdmin())) {
+                       $this->error('ERROR: Filename "' . $fileName . '" failed against extension check or deny-pattern!');
+                       return FALSE;
+               }
+               if (!GeneralUtility::getFileAbsFileName($fileName)) {
+                       $this->error('ERROR: Filename "' . $fileName . '" was not a valid relative file path!');
+                       return FALSE;
+               }
+               if (!$this->dat['files'][$fileID]) {
+                       $this->error('ERROR: File ID "' . $fileID . '" could not be found');
+                       return FALSE;
+               }
+               GeneralUtility::writeFile($fileName, $this->dat['files'][$fileID]['content']);
+               $this->fileIDMap[$fileID] = $fileName;
+               if (md5(GeneralUtility::getUrl($fileName)) == $this->dat['files'][$fileID]['content_md5']) {
+                       return TRUE;
+               } else {
+                       $this->error('ERROR: File content "' . $fileName . '" was corrupted');
+                       return FALSE;
                }
        }
 
-
        /**
         * Writes the file with the is $fileId to the legacy import folder. The file name will used from
         * argument $fileName and the file was successfully created or an identical file was already found,
         * $fileName will held the uid of the new created file record.
         *
-        * @param $fileName The file name for the new file. Value would be changed to the uid of the new created file record.
-        * @param $fileID The id of the file in data array
+        * @param string $fileName The file name for the new file. Value would be changed to the uid of the new created file record.
+        * @param int $fileId The id of the file in data array
         * @return bool
         */
        protected function writeSysFileResourceForLegacyImport(&$fileName, $fileId) {
@@ -3030,6 +3131,7 @@ class ImportExport {
                                }
                        }
                }
+               return FALSE;
        }
 
        /**
@@ -3038,7 +3140,7 @@ class ImportExport {
         *
         * @param string $dirPrefix Path relative to PATH_site
         * @param boolean $noAlternative If set, Do not look for alternative path! Just return FALSE
-        * @return string If a path is available that will be returned, otherwise FALSE.
+        * @return string|bool If a path is available that will be returned, otherwise FALSE.
         * @todo Define visibility
         */
        public function verifyFolderAccess($dirPrefix, $noAlternative = FALSE) {
@@ -3058,11 +3160,12 @@ class ImportExport {
                                if (GeneralUtility::isFirstPartOfStr($dirPrefix, $this->fileadminFolderName . '/')) {
                                        $dirPrefix = substr($dirPrefix, strlen($this->fileadminFolderName . '/'));
                                }
-                               return \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($fileProcObj->mounts[$result]['path'] . $dirPrefix);
+                               return PathUtility::stripPathSitePrefix($fileProcObj->mounts[$result]['path'] . $dirPrefix);
                        }
                } else {
                        return $dirPrefix;
                }
+               return FALSE;
        }
 
        /**************************
@@ -3077,55 +3180,55 @@ class ImportExport {
         * @return boolean TRUE if the operation went well
         * @todo Define visibility
         */
-       public function loadFile($filename, $all = 0) {
-               if (@is_file($filename)) {
-                       $fI = pathinfo($filename);
-                       if (@is_dir($filename . '.files')) {
-                               if (GeneralUtility::isAllowedAbsPath($filename . '.files')) {
-                                       // copy the folder lowlevel to typo3temp, because the files would be deleted after import
-                                       $temporaryFolderName = $this->getTemporaryFolderName();
-                                       GeneralUtility::copyDirectory($filename . '.files', $temporaryFolderName);
-                                       $this->filesPathForImport = $temporaryFolderName;
-                               } else {
-                                       $this->error('External import files for the given import source is currently not supported.');
-                               }
+       public function loadFile($filename, $all = FALSE) {
+               if (!@is_file($filename)) {
+                       $this->error('Filename not found: ' . $filename);
+                       return FALSE;
+               }
+               $fI = pathinfo($filename);
+               if (@is_dir($filename . '.files')) {
+                       if (GeneralUtility::isAllowedAbsPath($filename . '.files')) {
+                               // copy the folder lowlevel to typo3temp, because the files would be deleted after import
+                               $temporaryFolderName = $this->getTemporaryFolderName();
+                               GeneralUtility::copyDirectory($filename . '.files', $temporaryFolderName);
+                               $this->filesPathForImport = $temporaryFolderName;
+                       } else {
+                               $this->error('External import files for the given import source is currently not supported.');
                        }
-                       if (strtolower($fI['extension']) == 'xml') {
-                               // XML:
-                               $xmlContent = GeneralUtility::getUrl($filename);
-                               if (strlen($xmlContent)) {
-                                       $this->dat = GeneralUtility::xml2array($xmlContent, '', TRUE);
-                                       if (is_array($this->dat)) {
-                                               if ($this->dat['_DOCUMENT_TAG'] === 'T3RecordDocument' && is_array($this->dat['header']) && is_array($this->dat['records'])) {
-                                                       $this->loadInit();
-                                                       return TRUE;
-                                               } else {
-                                                       $this->error('XML file did not contain proper XML for TYPO3 Import');
-                                               }
+               }
+               if (strtolower($fI['extension']) == 'xml') {
+                       // XML:
+                       $xmlContent = GeneralUtility::getUrl($filename);
+                       if (strlen($xmlContent)) {
+                               $this->dat = GeneralUtility::xml2array($xmlContent, '', TRUE);
+                               if (is_array($this->dat)) {
+                                       if ($this->dat['_DOCUMENT_TAG'] === 'T3RecordDocument' && is_array($this->dat['header']) && is_array($this->dat['records'])) {
+                                               $this->loadInit();
+                                               return TRUE;
                                        } else {
-                                               $this->error('XML could not be parsed: ' . $this->dat);
+                                               $this->error('XML file did not contain proper XML for TYPO3 Import');
                                        }
                                } else {
-                                       $this->error('Error opening file: ' . $filename);
+                                       $this->error('XML could not be parsed: ' . $this->dat);
                                }
                        } else {
-                               // T3D
-                               if ($fd = fopen($filename, 'rb')) {
-                                       $this->dat['header'] = $this->getNextFilePart($fd, 1, 'header');
-                                       if ($all) {
-                                               $this->dat['records'] = $this->getNextFilePart($fd, 1, 'records');
-                                               $this->dat['files'] = $this->getNextFilePart($fd, 1, 'files');
-                                               $this->dat['files_fal'] = $this->getNextFilePart($fd, 1, 'files_fal');
-                                       }
-                                       $this->loadInit();
-                                       return TRUE;
-                               } else {
-                                       $this->error('Error opening file: ' . $filename);
-                               }
-                               fclose($fd);
+                               $this->error('Error opening file: ' . $filename);
                        }
                } else {
-                       $this->error('Filename not found: ' . $filename);
+                       // T3D
+                       if ($fd = fopen($filename, 'rb')) {
+                               $this->dat['header'] = $this->getNextFilePart($fd, 1, 'header');
+                               if ($all) {
+                                       $this->dat['records'] = $this->getNextFilePart($fd, 1, 'records');
+                                       $this->dat['files'] = $this->getNextFilePart($fd, 1, 'files');
+                                       $this->dat['files_fal'] = $this->getNextFilePart($fd, 1, 'files_fal');
+                               }
+                               $this->loadInit();
+                               return TRUE;
+                       } else {
+                               $this->error('Error opening file: ' . $filename);
+                       }
+                       fclose($fd);
                }
                return FALSE;
        }
@@ -3133,7 +3236,7 @@ class ImportExport {
        /**
         * Returns the next content part form the fileresource (t3d), $fd
         *
-        * @param pointer $fd File pointer
+        * @param int $fd File pointer
         * @param boolean $unserialize If set, the returned content is unserialized into an array, otherwise you get the raw string
         * @param string $name For error messages this indicates the section of the problem.
         * @return string|NULL Data string or NULL in case of an error
@@ -3141,7 +3244,7 @@ class ImportExport {
         * @see loadFile()
         * @todo Define visibility
         */
-       public function getNextFilePart($fd, $unserialize = 0, $name = '') {
+       public function getNextFilePart($fd, $unserialize = FALSE, $name = '') {
                $initStrLen = 32 + 1 + 1 + 1 + 10 + 1;
                // Getting header data
                $initStr = fread($fd, $initStrLen);
@@ -3150,28 +3253,29 @@ class ImportExport {
                        return NULL;
                }
                $initStrDat = explode(':', $initStr);
-               if (strstr($initStrDat[0], 'Warning') == FALSE) {
-                       if ((string)$initStrDat[3] === '') {
-                               $datString = fread($fd, (int)$initStrDat[2]);
-                               fread($fd, 1);
-                               if (md5($datString) === $initStrDat[0]) {
-                                       if ($initStrDat[1]) {
-                                               if ($this->compress) {
-                                                       $datString = gzuncompress($datString);
-                                               } else {
-                                                       $this->error('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.', 1);
-                                               }
-                                       }
+               if (strstr($initStrDat[0], 'Warning')) {
+                       $this->error('File read error: Warning message in file. (' . $initStr . fgets($fd) . ')');
+                       return NULL;
+               }
+               if ((string)$initStrDat[3] !== '') {
+                       $this->error('File read error: InitString had a wrong length. (' . $name . ')');
+                       return NULL;
+               }
+               $datString = fread($fd, (int)$initStrDat[2]);
+               fread($fd, 1);
+               if (md5($datString) === $initStrDat[0]) {
+                       if ($initStrDat[1]) {
+                               if ($this->compress) {
+                                       $datString = gzuncompress($datString);
                                        return $unserialize ? unserialize($datString) : $datString;
                                } else {
-                                       $this->error('MD5 check failed (' . $name . ')');
+                                       $this->error('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.', 1);
                                }
-                       } else {
-                               $this->error('File read error: InitString had a wrong length. (' . $name . ')');
                        }
                } else {
-                       $this->error('File read error: Warning message in file. (' . $initStr . fgets($fd) . ')');
+                       $this->error('MD5 check failed (' . $name . ')');
                }
+               return NULL;
        }
 
        /**
@@ -3195,35 +3299,36 @@ class ImportExport {
         *
         * @param string $filecontent File content string
         * @param integer $pointer File pointer (where to read from)
-        * @param boolean $unserialize If set, the returned content is unserialized into an array, otherwise you get the raw string
+        * @param bool $unserialize If set, the returned content is unserialized into an array, otherwise you get the raw string
         * @param string $name For error messages this indicates the section of the problem.
-        * @return string Data string
+        * @return string|NULL Data string
         * @todo Define visibility
         */
-       public function getNextContentPart($filecontent, &$pointer, $unserialize = 0, $name = '') {
+       public function getNextContentPart($filecontent, &$pointer, $unserialize = FALSE, $name = '') {
                $initStrLen = 32 + 1 + 1 + 1 + 10 + 1;
                // getting header data
                $initStr = substr($filecontent, $pointer, $initStrLen);
                $pointer += $initStrLen;
                $initStrDat = explode(':', $initStr);
-               if ((string)$initStrDat[3] === '') {
-                       $datString = substr($filecontent, $pointer, (int)$initStrDat[2]);
-                       $pointer += (int)$initStrDat[2] + 1;
-                       if (md5($datString) === $initStrDat[0]) {
-                               if ($initStrDat[1]) {
-                                       if ($this->compress) {
-                                               $datString = gzuncompress($datString);
-                                       } else {
-                                               $this->error('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.', 1);
-                                       }
+               if ((string)$initStrDat[3] !== '') {
+                       $this->error('Content read error: InitString had a wrong length. (' . $name . ')');
+                       return NULL;
+               }
+               $datString = substr($filecontent, $pointer, (int)$initStrDat[2]);
+               $pointer += (int)$initStrDat[2] + 1;
+               if (md5($datString) === $initStrDat[0]) {
+                       if ($initStrDat[1]) {
+                               if ($this->compress) {
+                                       $datString = gzuncompress($datString);
+                                       return $unserialize ? unserialize($datString) : $datString;
+                               } else {
+                                       $this->error('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.', 1);
                                }
-                               return $unserialize ? unserialize($datString) : $datString;
-                       } else {
-                               $this->error('MD5 check failed (' . $name . ')');
                        }
                } else {
-                       $this->error('Content read error: InitString had a wrong length. (' . $name . ')');
+                       $this->error('MD5 check failed (' . $name . ')');
                }
+               return NULL;
        }
 
        /**
@@ -3238,7 +3343,10 @@ class ImportExport {
                $this->softrefCfg = (array) $this->dat['header']['softrefCfg'];
                $this->extensionDependencies = (array) $this->dat['header']['extensionDependencies'];
                $this->fixCharsets();
-               if (isset($this->dat['header']['meta']['TYPO3_version']) && \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger($this->dat['header']['meta']['TYPO3_version']) < 6000000){
+               if (
+                       isset($this->dat['header']['meta']['TYPO3_version'])
+                       && \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger($this->dat['header']['meta']['TYPO3_version']) < 6000000
+               ){
                        $this->legacyImport = TRUE;
                        $this->initializeLegacyImportFolder();
                }
@@ -3297,9 +3405,10 @@ class ImportExport {
                }
                // Probably this is done to save memory space?
                unset($this->dat['files']);
+               $out = '';
                // Traverse header:
-               $this->remainHeader = $this->dat['header'];
-               if (is_array($this->remainHeader)) {
+               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']);
@@ -3466,7 +3575,7 @@ class ImportExport {
         * @return void
         * @todo Define visibility
         */
-       public function singleRecordLines($table, $uid, &$lines, $preCode, $checkImportInPidRecord = 0) {
+       public function singleRecordLines($table, $uid, &$lines, $preCode, $checkImportInPidRecord = FALSE) {
                global $LANG;
                // Get record:
                $record = $this->dat['header']['records'][$table][$uid];
@@ -3489,7 +3598,7 @@ class ImportExport {
                } else {
                        // Otherwise, set table icon and title.
                        // Import Validation (triggered by $this->display_import_pid_record) will show messages if import is not possible of various items.
-                       if (is_array($this->display_import_pid_record)) {
+                       if (is_array($this->display_import_pid_record) && !empty($this->display_import_pid_record)) {
                                if ($checkImportInPidRecord) {
                                        if (!$GLOBALS['BE_USER']->doesUserHaveAccess($this->display_import_pid_record, ($table === 'pages' ? 8 : 16))) {
                                                $pInfo['msg'] .= '\'' . $pInfo['ref'] . '\' cannot be INSERTED on this page! ';
@@ -3514,6 +3623,7 @@ class ImportExport {
                                        $pInfo['msg'] .= 'TABLE \'' . $table . '\' will be inserted on ROOT LEVEL! ';
                                }
                                $diffInverse = FALSE;
+                               $recInf = NULL;
                                if ($this->update) {
                                        // In case of update-PREVIEW we swap the diff-sources.
                                        $diffInverse = TRUE;
@@ -3635,45 +3745,46 @@ class ImportExport {
                        $table = $dat['table'];
                        $uid = $dat['id'];
                        $pInfo = array();
+                       $pInfo['ref'] = $table . ':' . $uid;
+                       if (in_array($pInfo['ref'], $recurCheck)) {
+                               $this->error($pInfo['ref'] . ' was recursive...');
+                               continue;
+                       }
                        $Iprepend = '';
                        $staticFixed = FALSE;
-                       $pInfo['ref'] = $table . ':' . $uid;
-                       if (!in_array($pInfo['ref'], $recurCheck)) {
-                               if ($uid > 0) {
-                                       $record = $this->dat['header']['records'][$table][$uid];
-                                       if (!is_array($record)) {
-                                               if ($this->isTableStatic($table) || $this->isExcluded($table, $uid) || $dat['tokenID'] && !$this->includeSoftref($dat['tokenID'])) {
-                                                       $pInfo['title'] = htmlspecialchars('STATIC: ' . $pInfo['ref']);
-                                                       $Iprepend = '_static';
-                                                       $staticFixed = TRUE;
-                                               } else {
-                                                       $doesRE = $this->doesRecordExist($table, $uid);
-                                                       $lostPath = $this->getRecordPath($table === 'pages' ? $doesRE['uid'] : $doesRE['pid']);
-                                                       $pInfo['title'] = htmlspecialchars($pInfo['ref']);
-                                                       $pInfo['title'] = '<span title="' . htmlspecialchars($lostPath) . '">' . $pInfo['title'] . '</span>';
-                                                       $pInfo['msg'] = 'LOST RELATION' . (!$doesRE ? ' (Record not found!)' : ' (Path: ' . $lostPath . ')');
-                                                       $Iprepend = '_lost';
-                                               }
+                       $record = NULL;
+                       if ($uid > 0) {
+                               $record = $this->dat['header']['records'][$table][$uid];
+                               if (!is_array($record)) {
+                                       if ($this->isTableStatic($table) || $this->isExcluded($table, $uid) || $dat['tokenID'] && !$this->includeSoftref($dat['tokenID'])) {
+                                               $pInfo['title'] = htmlspecialchars('STATIC: ' . $pInfo['ref']);
+                                               $Iprepend = '_static';
+                                               $staticFixed = TRUE;
                                        } else {
-                                               $pInfo['title'] = htmlspecialchars($record['title']);
-                                               $pInfo['title'] = '<span title="' . htmlspecialchars($this->getRecordPath(($table === 'pages' ? $record['uid'] : $record['pid']))) . '">' . $pInfo['title'] . '</span>';
+                                               $doesRE = $this->doesRecordExist($table, $uid);
+                                               $lostPath = $this->getRecordPath($table === 'pages' ? $doesRE['uid'] : $doesRE['pid']);
+                                               $pInfo['title'] = htmlspecialchars($pInfo['ref']);
+                                               $pInfo['title'] = '<span title="' . htmlspecialchars($lostPath) . '">' . $pInfo['title'] . '</span>';
+                                               $pInfo['msg'] = 'LOST RELATION' . (!$doesRE ? ' (Record not found!)' : ' (Path: ' . $lostPath . ')');
+                                               $Iprepend = '_lost';
                                        }
                                } else {
-                                       // Negative values in relation fields. This is typically sys_language fields, fe_users fields etc. They are static values. They CAN theoretically be negative pointers to uids in other tables but this is so rarely used that it is not supported
-                                       $pInfo['title'] = htmlspecialchars('FIXED: ' . $pInfo['ref']);
-                                       $staticFixed = TRUE;
-                               }
-                               $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/rel_db' . $Iprepend . '.gif'), 'width="13" height="12"') . ' align="top" title="' . htmlspecialchars($pInfo['ref']) . '" alt="" />';
-                               $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
-                               $pInfo['type'] = 'rel';
-                               if (!$staticFixed || $this->showStaticRelations) {
-                                       $lines[] = $pInfo;
-                                       if (is_array($record) && is_array($record['rels'])) {
-                                               $this->addRelations($record['rels'], $lines, $preCode . '&nbsp;&nbsp;', array_merge($recurCheck, array($pInfo['ref'])), $htmlColorClass);
-                                       }
+                                       $pInfo['title'] = htmlspecialchars($record['title']);
+                                       $pInfo['title'] = '<span title="' . htmlspecialchars($this->getRecordPath(($table === 'pages' ? $record['uid'] : $record['pid']))) . '">' . $pInfo['title'] . '</span>';
                                }
                        } else {
-                               $this->error($pInfo['ref'] . ' was recursive...');
+                               // Negative values in relation fields. This is typically sys_language fields, fe_users fields etc. They are static values. They CAN theoretically be negative pointers to uids in other tables but this is so rarely used that it is not supported
+                               $pInfo['title'] = htmlspecialchars('FIXED: ' . $pInfo['ref']);
+                               $staticFixed = TRUE;
+                       }
+                       $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/rel_db' . $Iprepend . '.gif'), 'width="13" height="12"') . ' align="top" title="' . htmlspecialchars($pInfo['ref']) . '" alt="" />';
+                       $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
+                       $pInfo['type'] = 'rel';
+                       if (!$staticFixed || $this->showStaticRelations) {
+                               $lines[] = $pInfo;
+                               if (is_array($record) && is_array($record['rels'])) {
+                                       $this->addRelations($record['rels'], $lines, $preCode . '&nbsp;&nbsp;', array_merge($recurCheck, array($pInfo['ref'])), $htmlColorClass);
+                               }
                        }
                }
        }
@@ -3742,7 +3853,7 @@ class ImportExport {
                                        $pInfo['msg'] = 'You user profile does not allow you to create files on the server!';
                                }
                        }
-                       $pInfo['showDiffContent'] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
+                       $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
                        $lines[] = $pInfo;
                        unset($this->remainHeader['files'][$ID]);
                        // RTE originals:
@@ -3754,7 +3865,7 @@ class ImportExport {
                                        $pInfo['msg'] = 'MISSING RTE original FILE: ' . $ID;
                                        $this->error('MISSING RTE original FILE: ' . $ID, 1);
                                }
-                               $pInfo['showDiffContent'] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
+                               $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
                                $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-reference-file');
                                $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Original)</em>';
                                $pInfo['ref'] = 'FILE';
@@ -3766,16 +3877,16 @@ class ImportExport {
                        }
                        // External resources:
                        if (is_array($fI['EXT_RES_ID'])) {
-                               foreach ($fI['EXT_RES_ID'] as $ID) {
+                               foreach ($fI['EXT_RES_ID'] as $extID) {
                                        $pInfo = array();
-                                       $fI = $this->dat['header']['files'][$ID];
+                                       $fI = $this->dat['header']['files'][$extID];
                                        if (!is_array($fI)) {
-                                               $pInfo['msg'] = 'MISSING External Resource FILE: ' . $ID;
-                                               $this->error('MISSING External Resource FILE: ' . $ID, 1);
+                                               $pInfo['msg'] = 'MISSING External Resource FILE: ' . $extID;
+                                               $this->error('MISSING External Resource FILE: ' . $extID, 1);
                                        } else {
                                                $pInfo['updatePath'] = $fI['parentRelFileName'];
                                        }
-                                       $pInfo['showDiffContent'] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
+                                       $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$extID]);
                                        $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-insert-reference');
                                        $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Resource)</em>';
                                        $pInfo['ref'] = 'FILE';
@@ -3783,7 +3894,7 @@ class ImportExport {
                                        $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
                                        $pInfo['type'] = 'file';
                                        $lines[] = $pInfo;
-                                       unset($this->remainHeader['files'][$ID]);
+                                       unset($this->remainHeader['files'][$extID]);
                                }
                        }
                }
@@ -3805,6 +3916,7 @@ class ImportExport {
                if (strstr($allowedTableList, '*') || in_array($checkTable, $allowedArray)) {
                        return TRUE;
                }
+               return FALSE;
        }
 
        /**
@@ -3817,7 +3929,11 @@ class ImportExport {
        public function renderControls($r) {
                global $LANG;
                if ($this->mode === 'export') {
-                       return $r['type'] == 'record' ? '<input type="checkbox" name="tx_impexp[exclude][' . $r['ref'] . ']" id="checkExclude' . $r['ref'] . '" value="1" /> <label for="checkExclude' . $r['ref'] . '">' . $LANG->getLL('impexpcore_singlereco_exclude', TRUE) . '</label>' : ($r['type'] == 'softref' ? $this->softrefSelector($r['_softRefInfo']) : '');
+                       if ($r['type'] === 'record') {
+                               return '<input type="checkbox" name="tx_impexp[exclude][' . $r['ref'] . ']" id="checkExclude' . $r['ref'] . '" value="1" /> <label for="checkExclude' . $r['ref'] . '">' . $LANG->getLL('impexpcore_singlereco_exclude', TRUE) . '</label>';
+                       } else {
+                               return  $r['type'] == 'softref' ? $this->softrefSelector($r['_softRefInfo']) : '';
+                       }
                } else {
                        // During import
                        // For softreferences with editable fields:
@@ -3830,6 +3946,7 @@ class ImportExport {
                                }
                        }
                }
+               return '';
        }
 
        /**
@@ -3879,6 +3996,7 @@ class ImportExport {
                        }
                        return $selectorbox . $descriptionField;
                }
+               return '';
        }
 
        /*****************************
@@ -3896,6 +4014,7 @@ class ImportExport {
                if (is_array($GLOBALS['TCA'][$table])) {
                        return $GLOBALS['TCA'][$table]['ctrl']['is_static'] || in_array($table, $this->relStaticTables) || in_array('_ALL', $this->relStaticTables);
                }
+               return FALSE;
        }
 
        /**
@@ -3906,9 +4025,9 @@ class ImportExport {
         * @todo Define visibility
         */
        public function inclRelation($table) {
-               if (is_array($GLOBALS['TCA'][$table])) {
-                       return (in_array($table, $this->relOnlyTables) || in_array('_ALL', $this->relOnlyTables)) && $GLOBALS['BE_USER']->check('tables_select', $table);
-               }
+               return is_array($GLOBALS['TCA'][$table])
+                       && (in_array($table, $this->relOnlyTables) || in_array('_ALL', $this->relOnlyTables))
+                       && $GLOBALS['BE_USER']->check('tables_select', $table);
        }
 
        /**
@@ -3920,7 +4039,7 @@ class ImportExport {
         * @todo Define visibility
         */
        public function isExcluded($table, $uid) {
-               return $this->excludeMap[$table . ':' . $uid] ? TRUE : FALSE;
+               return (bool)$this->excludeMap[$table . ':' . $uid];
        }
 
        /**
@@ -3943,7 +4062,7 @@ class ImportExport {
         */
        public function checkPID($pid) {
                if (!isset($this->checkPID_cache[$pid])) {
-                       $this->checkPID_cache[$pid] = (bool) $GLOBALS['BE_USER']->isInWebMount($pid);
+                       $this->checkPID_cache[$pid] = (bool)$GLOBALS['BE_USER']->isInWebMount($pid);
                }
                return $this->checkPID_cache[$pid];
        }
@@ -4014,7 +4133,8 @@ class ImportExport {
        }
 
        /**
-        * Compares two records, the current database record and the one from the import memory. Will return HTML code to show any differences between them!
+        * Compares two records, the current database record and the one from the import memory.
+        * Will return HTML code to show any differences between them!
         *
         * @param array $databaseRecord Database record, all fields (new values)
         * @param array $importRecord Import memorys record for the same table/uid, all fields (old values)
@@ -4072,7 +4192,7 @@ class ImportExport {
         * Creates the original file name for a copy-RTE image (magic type)
         *
         * @param string $string RTE copy filename, eg. "RTEmagicC_user_pm_icon_01.gif.gif
-        * @return string RTE original filename, eg. "RTEmagicP_user_pm_icon_01.gif". IF the input filename was NOT prefixed RTEmagicC_ as RTE images would be, nothing is returned!
+        * @return string|NULL RTE original filename, eg. "RTEmagicP_user_pm_icon_01.gif". If the input filename was NOT prefixed RTEmagicC_ as RTE images would be, NULL is returned!
         * @todo Define visibility
         */
        public function getRTEoriginalFilename($string) {
@@ -4084,6 +4204,7 @@ class ImportExport {
                        $origFilePath = 'RTEmagicP_' . $filename;
                        return $origFilePath;
                }
+               return NULL;
        }
 
        /**
@@ -4093,7 +4214,7 @@ class ImportExport {
         * @todo Define visibility
         */
        public function getFileProcObj() {
-               if (!is_object($this->fileProcObj)) {
+               if ($this->fileProcObj === NULL) {
                        $this->fileProcObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
                        $this->fileProcObj->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
                        $this->fileProcObj->setActionPermissions();
@@ -4123,7 +4244,7 @@ class ImportExport {
        /**
         * Sets error message in the internal error log
         *
-        * @param string Error message
+        * @param string $msg Error message
         * @return void
         * @todo Define visibility
         */