mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
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).
This commit is contained in:
parent
2d3d9f1bc7
commit
61823329c8
@ -1,5 +1,6 @@
|
||||
<?php namespace Backend\Models;
|
||||
|
||||
use Backend\Behaviors\ImportExportController\TranscodeFilter;
|
||||
use Str;
|
||||
use Lang;
|
||||
use Model;
|
||||
@ -96,7 +97,8 @@ abstract class ImportModel extends Model
|
||||
'firstRowTitles' => 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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user