From 61823329c89a5090731e9e2c5f4af2457919976c Mon Sep 17 00:00:00 2001 From: Alexander Guth Date: Thu, 18 Aug 2016 21:11:21 +0200 Subject: [PATCH] ImportModel didnt respect encoding In contrast to the preview CSV reader, the actual ``ImportModel`` did not respect any encoding values provided. This leads to bugs with any non utf8-compliant characters. This PR fixes the problem by adding the appropriate encoding filter (copied from the preview reader). --- modules/backend/models/ImportModel.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/backend/models/ImportModel.php b/modules/backend/models/ImportModel.php index 0a7fbfde8..01e457916 100644 --- a/modules/backend/models/ImportModel.php +++ b/modules/backend/models/ImportModel.php @@ -1,5 +1,6 @@ true, 'delimiter' => null, 'enclosure' => null, - 'escape' => null + 'escape' => null, + 'encoding' => null ]; $options = array_merge($defaultOptions, $options); @@ -127,6 +129,18 @@ abstract class ImportModel extends Model $reader->setOffset(1); } + if ( + $options['encoding'] !== null && + $reader->isActiveStreamFilter() + ) { + $reader->appendStreamFilter(sprintf( + '%s%s:%s', + TranscodeFilter::FILTER_NAME, + strtolower($options['encoding']), + 'utf-8' + )); + } + $result = []; $contents = $reader->fetchAll(); foreach ($contents as $row) {