[BUGFIX] impexp ignore file reference records with missing related files 24/46524/2
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Mon, 8 Feb 2016 12:37:07 +0000 (13:37 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Mon, 8 Feb 2016 12:46:52 +0000 (13:46 +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/46524
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/impexp/Classes/ImportExport.php

index e9e581f..4e4ea4f 100644 (file)
@@ -1640,6 +1640,34 @@ class ImportExport {
 
                // unset the sys_file records to prevent a 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.'
+                               );
+                       }
+               }
        }
 
        /**