[BUGFIX] impexp ignore file reference records with missing related files
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / Import.php
index 48b18a8..f5b9753 100644 (file)
@@ -515,6 +515,34 @@ class Import extends ImportExport
 
         // unset the sys_file records to prevent an import in writeRecords_records
         unset($this->dat['header']['records']['sys_file']);
+        // remove all sys_file_reference records that point to file records which are unknown
+        // in the system to prevent exceptions
+        $this->removeSysFileReferenceRecordsFromImportDataWithRelationToMissingFile();
+    }
+
+    /**
+     * Removes all sys_file_reference records from the import data array that are pointing to sys_file records which
+     * are missing not in the import data to prevent exceptions on checking the related file started by the Datahandler.
+     *
+     * @return void
+     */
+    protected function removeSysFileReferenceRecordsFromImportDataWithRelationToMissingFile()
+    {
+        if (!isset($this->dat['header']['records']['sys_file_reference'])) {
+            return;
+        }
+
+        foreach ($this->dat['header']['records']['sys_file_reference'] as $sysFileReferenceUid => $_) {
+            $fileReferenceRecord = $this->dat['records']['sys_file_reference:' . $sysFileReferenceUid]['data'];
+            if (!in_array($fileReferenceRecord['uid_local'], $this->import_mapId['sys_file'])) {
+                unset($this->dat['header']['records']['sys_file_reference'][$sysFileReferenceUid]);
+                unset($this->dat['records']['sys_file_reference:' . $sysFileReferenceUid]);
+                $this->error('Error: sys_file_reference record ' . (int)$sysFileReferenceUid
+                             . ' with relation to sys_file record ' . (int)$fileReferenceRecord['uid_local']
+                             . ', which is not part of the import data, was not imported.'
+                );
+            }
+        }
     }
 
     /**