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;
|
<?php namespace Backend\Models;
|
||||||
|
|
||||||
|
use Backend\Behaviors\ImportExportController\TranscodeFilter;
|
||||||
use Str;
|
use Str;
|
||||||
use Lang;
|
use Lang;
|
||||||
use Model;
|
use Model;
|
||||||
@ -96,7 +97,8 @@ abstract class ImportModel extends Model
|
|||||||
'firstRowTitles' => true,
|
'firstRowTitles' => true,
|
||||||
'delimiter' => null,
|
'delimiter' => null,
|
||||||
'enclosure' => null,
|
'enclosure' => null,
|
||||||
'escape' => null
|
'escape' => null,
|
||||||
|
'encoding' => null
|
||||||
];
|
];
|
||||||
|
|
||||||
$options = array_merge($defaultOptions, $options);
|
$options = array_merge($defaultOptions, $options);
|
||||||
@ -127,6 +129,18 @@ abstract class ImportModel extends Model
|
|||||||
$reader->setOffset(1);
|
$reader->setOffset(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
$options['encoding'] !== null &&
|
||||||
|
$reader->isActiveStreamFilter()
|
||||||
|
) {
|
||||||
|
$reader->appendStreamFilter(sprintf(
|
||||||
|
'%s%s:%s',
|
||||||
|
TranscodeFilter::FILTER_NAME,
|
||||||
|
strtolower($options['encoding']),
|
||||||
|
'utf-8'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
$contents = $reader->fetchAll();
|
$contents = $reader->fetchAll();
|
||||||
foreach ($contents as $row) {
|
foreach ($contents as $row) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user