[BUGFIX] Ensure correct field ordering in CSV export 87/51087/2
authorNicole Cordes <typo3@cordes.co>
Mon, 12 Dec 2016 22:01:14 +0000 (23:01 +0100)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Sun, 1 Jan 2017 09:27:35 +0000 (10:27 +0100)
Due to patch https://review.typo3.org/48998/ the whole database record
is fetched from the database instead of only the visible fields. This
screws up the CSV export as this on relies of the field sorting of the
database row. This patch ensures a correct sorting of the row fields
before they are added to the CSV export.

Resolves: #78908
Releases: master, 7.6
Change-Id: I64f0213695c0cd13fecaa96343a5b1d9af1582f4
Reviewed-on: https://review.typo3.org/51087
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index 56458ca..426c433 100644 (file)
@@ -2140,7 +2140,10 @@ class DatabaseRecordList extends AbstractDatabaseRecordList
     protected function addToCSV(array $row = [])
     {
         $rowReducedByControlFields = self::removeControlFieldsFromFieldRow($row);
-        $rowReducedToSelectedColumns = array_intersect_key($rowReducedByControlFields, array_flip($this->fieldArray));
+        // Get an field array without control fields but in the expected order
+        $fieldArray = array_intersect_key(array_flip($this->fieldArray), $rowReducedByControlFields);
+        // Overwrite fieldArray to keep the order with an array of needed fields
+        $rowReducedToSelectedColumns = array_replace($fieldArray, array_intersect_key($rowReducedByControlFields, $fieldArray));
         $this->setCsvRow($rowReducedToSelectedColumns);
     }