Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1 #1656

Merged
merged 3 commits into from
May 9, 2018
Merged

2.1 #1656

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/Maatwebsite/Excel/Readers/ChunkedReadJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,23 @@ class ChunkedReadJob implements ShouldQueue
* @var bool
*/
private $shouldQueue;

/**
* @var string|null
*/
private $encoding;

/**
* ChunkedReadJob constructor.
*
* @param $file
* @param null $sheets
* @param int $startRow
* @param $startIndex
* @param $chunkSize
* @param callable $callback
* @param bool $shouldQueue
* @param $file
* @param null $sheets
* @param int $startRow
* @param $startIndex
* @param $chunkSize
* @param callable $callback
* @param bool $shouldQueue
* @param string|null $encoding
*/
public function __construct(
$file,
Expand All @@ -64,7 +70,8 @@ public function __construct(
$startIndex,
$chunkSize,
callable $callback,
$shouldQueue = true
$shouldQueue = true,
$encoding = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the docblock as well please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course. I have updated the docblock.

) {
$this->startRow = $startRow;
$this->chunkSize = $chunkSize;
Expand All @@ -74,6 +81,7 @@ public function __construct(
$this->callback = $shouldQueue ? (new Serializer)->serialize($callback) : $callback;
$this->sheets = $sheets;
$this->shouldQueue = $shouldQueue;
$this->encoding = $encoding;
}

/***
Expand All @@ -89,6 +97,11 @@ public function handle()
$reader->reader->setLoadSheetsOnly($this->sheets);
$reader->reader->setReadFilter($filter);
$reader->reader->setReadDataOnly(true);

// Set encoding
if (! is_null($this->encoding)) {
$reader->reader->setInputEncoding($this->encoding);
}

// Set the rows for the chunking
$filter->setRows($this->startRow, $this->chunkSize);
Expand Down
9 changes: 8 additions & 1 deletion src/Maatwebsite/Excel/Readers/LaravelExcelReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,21 @@ public function chunk($size = 10, callable $callback, $shouldQueue = true)
$startIndex = ($startRow == 0 || !$this->hasHeading()) ? $startRow : $startRow - 1;
$chunkSize = ($startRow == 0 && $this->hasHeading()) ? $size + 1 : $size;

$encoding = null;

if ($this->format == 'CSV') {
$encoding = $this->reader->getInputEncoding($encoding);
}

$job = new ChunkedReadJob(
$this->file,
$this->reader->getLoadSheetsOnly(),
$startRow,
$startIndex,
$chunkSize,
$callback,
$shouldQueue
$shouldQueue,
$encoding
);

if ($shouldQueue) {
Expand Down