Skip to content

Commit

Permalink
Fix for CSV import
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Apr 18, 2018
1 parent 9ad6cae commit 12bd18f
Show file tree
Hide file tree
Showing 3 changed files with 306 additions and 233 deletions.
10 changes: 8 additions & 2 deletions app/Services/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
use stdClass;
use Utils;
use Carbon;
use League\Csv\Reader;
use League\Csv\Statement;


/**
* Class ImportService.
Expand Down Expand Up @@ -653,8 +656,11 @@ public function mapFile($entityType, $filename, $columns, $map)
private function getCsvData($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) {
$headers = $data[0];
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"laravel/socialite": "~3.0",
"laravel/tinker": "^1.0",
"laravelcollective/html": "5.4.*",
"league/csv": "^9.1",
"league/flysystem-aws-s3-v3": "~1.0",
"league/flysystem-rackspace": "~1.0",
"league/fractal": "0.13.*",
Expand Down
Loading

0 comments on commit 12bd18f

Please sign in to comment.