Fix for CSV import

This commit is contained in:
Hillel Coren 2018-04-18 10:00:38 +03:00
parent 9ad6cae695
commit 12bd18f38b
3 changed files with 306 additions and 233 deletions

View File

@ -35,6 +35,9 @@ use Session;
use stdClass; use stdClass;
use Utils; use Utils;
use Carbon; use Carbon;
use League\Csv\Reader;
use League\Csv\Statement;
/** /**
* Class ImportService. * Class ImportService.
@ -653,8 +656,11 @@ class ImportService
private function getCsvData($fileName) private function getCsvData($fileName)
{ {
$this->checkForFile($fileName); $this->checkForFile($fileName);
$file = file_get_contents($fileName);
$data = array_map("str_getcsv", preg_split('/\r*\n+|\r+/', $file)); $csv = Reader::createFromPath($fileName, 'r');
//$csv->setHeaderOffset(0); //set the CSV header offset
$stmt = new Statement();
$data = iterator_to_array($stmt->process($csv));
if (count($data) > 0) { if (count($data) > 0) {
$headers = $data[0]; $headers = $data[0];

View File

@ -46,6 +46,7 @@
"laravel/socialite": "~3.0", "laravel/socialite": "~3.0",
"laravel/tinker": "^1.0", "laravel/tinker": "^1.0",
"laravelcollective/html": "5.4.*", "laravelcollective/html": "5.4.*",
"league/csv": "^9.1",
"league/flysystem-aws-s3-v3": "~1.0", "league/flysystem-aws-s3-v3": "~1.0",
"league/flysystem-rackspace": "~1.0", "league/flysystem-rackspace": "~1.0",
"league/fractal": "0.13.*", "league/fractal": "0.13.*",

528
composer.lock generated

File diff suppressed because it is too large Load Diff