[BUGFIX] Ensure correct field ordering in CSV export 44/50944/3
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:25:59 +0000 (10:25 +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/50944
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>

index 3044c74..5dccd9a 100644 (file)
@@ -2164,7 +2164,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));