Merge pull request #2324 from alxy/patch-13

ImportModel didnt respect encoding
This commit is contained in:
Samuel Georges 2016-08-19 07:30:16 +10:00 committed by GitHub
commit 7373cf2bfb
1 changed files with 15 additions and 1 deletions

View File

@ -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) {