[BUGFIX] impexp ignore file reference records with missing related files 23/46523/2
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Fri, 15 Jan 2016 14:35:33 +0000 (15:35 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Mon, 8 Feb 2016 12:34:42 +0000 (13:34 +0100)
It could happen, that an export contains sys_file_reference records
with relations to sys_files records, that was missing in the exporting
instance. This causes exceptions on importing the sys_file_reference
records, because the related sys_file record is checked on saving of
the sys_file_reference record.
To prevent this this sys_file_reference are ignored on import.

Resolves: #58693
Releases: master, 7.6, 6.2
Change-Id: I68afed93502553b0d55eb858bdb6da5641d1e5f0
Reviewed-on: https://review.typo3.org/46523
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/impexp/Classes/Import.php

index 4daa67e..d1f0855 100644 (file)
@@ -516,6 +516,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.'
+                );
+            }
+        }
     }
 
     /**