Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
61
vendor/maatwebsite/excel/src/Jobs/AfterImportJob.php
vendored
Normal file
61
vendor/maatwebsite/excel/src/Jobs/AfterImportJob.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\ImportFailed;
|
||||
use Maatwebsite\Excel\HasEventBus;
|
||||
use Maatwebsite\Excel\Reader;
|
||||
use Throwable;
|
||||
|
||||
class AfterImportJob implements ShouldQueue
|
||||
{
|
||||
use Queueable, HasEventBus;
|
||||
|
||||
/**
|
||||
* @var WithEvents
|
||||
*/
|
||||
private $import;
|
||||
|
||||
/**
|
||||
* @var Reader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* @param object $import
|
||||
* @param Reader $reader
|
||||
*/
|
||||
public function __construct($import, Reader $reader)
|
||||
{
|
||||
$this->import = $import;
|
||||
$this->reader = $reader;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if ($this->import instanceof ShouldQueue && $this->import instanceof WithEvents) {
|
||||
$this->reader->clearListeners();
|
||||
$this->reader->registerListeners($this->import->registerEvents());
|
||||
}
|
||||
|
||||
$this->reader->afterImport($this->import);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Throwable $e
|
||||
*/
|
||||
public function failed(Throwable $e)
|
||||
{
|
||||
if ($this->import instanceof WithEvents) {
|
||||
$this->registerListeners($this->import->registerEvents());
|
||||
$this->raise(new ImportFailed($e));
|
||||
|
||||
if (method_exists($this->import, 'failed')) {
|
||||
$this->import->failed($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
86
vendor/maatwebsite/excel/src/Jobs/AppendDataToSheet.php
vendored
Normal file
86
vendor/maatwebsite/excel/src/Jobs/AppendDataToSheet.php
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Maatwebsite\Excel\Files\TemporaryFile;
|
||||
use Maatwebsite\Excel\Jobs\Middleware\LocalizeJob;
|
||||
use Maatwebsite\Excel\Writer;
|
||||
|
||||
class AppendDataToSheet implements ShouldQueue
|
||||
{
|
||||
use Queueable, Dispatchable, ProxyFailures, InteractsWithQueue;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $data = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $temporaryFile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $writerType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $sheetIndex;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
public $sheetExport;
|
||||
|
||||
/**
|
||||
* @param object $sheetExport
|
||||
* @param TemporaryFile $temporaryFile
|
||||
* @param string $writerType
|
||||
* @param int $sheetIndex
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct($sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex, array $data)
|
||||
{
|
||||
$this->sheetExport = $sheetExport;
|
||||
$this->data = $data;
|
||||
$this->temporaryFile = $temporaryFile;
|
||||
$this->writerType = $writerType;
|
||||
$this->sheetIndex = $sheetIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should be dispatched through.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function middleware()
|
||||
{
|
||||
return (method_exists($this->sheetExport, 'middleware')) ? $this->sheetExport->middleware() : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Writer $writer
|
||||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
|
||||
*/
|
||||
public function handle(Writer $writer)
|
||||
{
|
||||
(new LocalizeJob($this->sheetExport))->handle($this, function () use ($writer) {
|
||||
$writer = $writer->reopen($this->temporaryFile, $this->writerType);
|
||||
|
||||
$sheet = $writer->getSheetByIndex($this->sheetIndex);
|
||||
|
||||
$sheet->appendRows($this->data, $this->sheetExport);
|
||||
|
||||
$writer->write($this->sheetExport, $this->temporaryFile, $this->writerType);
|
||||
});
|
||||
}
|
||||
}
|
||||
102
vendor/maatwebsite/excel/src/Jobs/AppendQueryToSheet.php
vendored
Normal file
102
vendor/maatwebsite/excel/src/Jobs/AppendQueryToSheet.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Files\TemporaryFile;
|
||||
use Maatwebsite\Excel\Jobs\Middleware\LocalizeJob;
|
||||
use Maatwebsite\Excel\Writer;
|
||||
|
||||
class AppendQueryToSheet implements ShouldQueue
|
||||
{
|
||||
use Queueable, Dispatchable, ProxyFailures, InteractsWithQueue;
|
||||
|
||||
/**
|
||||
* @var TemporaryFile
|
||||
*/
|
||||
public $temporaryFile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $writerType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $sheetIndex;
|
||||
|
||||
/**
|
||||
* @var FromQuery
|
||||
*/
|
||||
public $sheetExport;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $page;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $chunkSize;
|
||||
|
||||
/**
|
||||
* @param FromQuery $sheetExport
|
||||
* @param TemporaryFile $temporaryFile
|
||||
* @param string $writerType
|
||||
* @param int $sheetIndex
|
||||
* @param int $page
|
||||
* @param int $chunkSize
|
||||
*/
|
||||
public function __construct(
|
||||
FromQuery $sheetExport,
|
||||
TemporaryFile $temporaryFile,
|
||||
string $writerType,
|
||||
int $sheetIndex,
|
||||
int $page,
|
||||
int $chunkSize
|
||||
) {
|
||||
$this->sheetExport = $sheetExport;
|
||||
$this->temporaryFile = $temporaryFile;
|
||||
$this->writerType = $writerType;
|
||||
$this->sheetIndex = $sheetIndex;
|
||||
$this->page = $page;
|
||||
$this->chunkSize = $chunkSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should be dispatched through.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function middleware()
|
||||
{
|
||||
return (method_exists($this->sheetExport, 'middleware')) ? $this->sheetExport->middleware() : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Writer $writer
|
||||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
|
||||
*/
|
||||
public function handle(Writer $writer)
|
||||
{
|
||||
(new LocalizeJob($this->sheetExport))->handle($this, function () use ($writer) {
|
||||
$writer = $writer->reopen($this->temporaryFile, $this->writerType);
|
||||
|
||||
$sheet = $writer->getSheetByIndex($this->sheetIndex);
|
||||
|
||||
$query = $this->sheetExport->query()->forPage($this->page, $this->chunkSize);
|
||||
|
||||
$sheet->appendRows($query->get(), $this->sheetExport);
|
||||
|
||||
$writer->write($this->sheetExport, $this->temporaryFile, $this->writerType);
|
||||
});
|
||||
}
|
||||
}
|
||||
81
vendor/maatwebsite/excel/src/Jobs/AppendViewToSheet.php
vendored
Normal file
81
vendor/maatwebsite/excel/src/Jobs/AppendViewToSheet.php
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Files\TemporaryFile;
|
||||
use Maatwebsite\Excel\Jobs\Middleware\LocalizeJob;
|
||||
use Maatwebsite\Excel\Writer;
|
||||
|
||||
class AppendViewToSheet implements ShouldQueue
|
||||
{
|
||||
use Queueable, Dispatchable, InteractsWithQueue;
|
||||
|
||||
/**
|
||||
* @var TemporaryFile
|
||||
*/
|
||||
public $temporaryFile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $writerType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $sheetIndex;
|
||||
|
||||
/**
|
||||
* @var FromView
|
||||
*/
|
||||
public $sheetExport;
|
||||
|
||||
/**
|
||||
* @param FromView $sheetExport
|
||||
* @param TemporaryFile $temporaryFile
|
||||
* @param string $writerType
|
||||
* @param int $sheetIndex
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(FromView $sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex)
|
||||
{
|
||||
$this->sheetExport = $sheetExport;
|
||||
$this->temporaryFile = $temporaryFile;
|
||||
$this->writerType = $writerType;
|
||||
$this->sheetIndex = $sheetIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should be dispatched through.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function middleware()
|
||||
{
|
||||
return (method_exists($this->sheetExport, 'middleware')) ? $this->sheetExport->middleware() : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Writer $writer
|
||||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
|
||||
*/
|
||||
public function handle(Writer $writer)
|
||||
{
|
||||
(new LocalizeJob($this->sheetExport))->handle($this, function () use ($writer) {
|
||||
$writer = $writer->reopen($this->temporaryFile, $this->writerType);
|
||||
|
||||
$sheet = $writer->getSheetByIndex($this->sheetIndex);
|
||||
|
||||
$sheet->fromView($this->sheetExport, $this->sheetIndex);
|
||||
|
||||
$writer->write($this->sheetExport, $this->temporaryFile, $this->writerType);
|
||||
});
|
||||
}
|
||||
}
|
||||
76
vendor/maatwebsite/excel/src/Jobs/CloseSheet.php
vendored
Normal file
76
vendor/maatwebsite/excel/src/Jobs/CloseSheet.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Files\TemporaryFile;
|
||||
use Maatwebsite\Excel\Writer;
|
||||
|
||||
class CloseSheet implements ShouldQueue
|
||||
{
|
||||
use Queueable, ProxyFailures;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
private $sheetExport;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $temporaryFile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $writerType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $sheetIndex;
|
||||
|
||||
/**
|
||||
* @param object $sheetExport
|
||||
* @param TemporaryFile $temporaryFile
|
||||
* @param string $writerType
|
||||
* @param int $sheetIndex
|
||||
*/
|
||||
public function __construct($sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex)
|
||||
{
|
||||
$this->sheetExport = $sheetExport;
|
||||
$this->temporaryFile = $temporaryFile;
|
||||
$this->writerType = $writerType;
|
||||
$this->sheetIndex = $sheetIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Writer $writer
|
||||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
|
||||
*/
|
||||
public function handle(Writer $writer)
|
||||
{
|
||||
$writer = $writer->reopen(
|
||||
$this->temporaryFile,
|
||||
$this->writerType
|
||||
);
|
||||
|
||||
$sheet = $writer->getSheetByIndex($this->sheetIndex);
|
||||
|
||||
if ($this->sheetExport instanceof WithEvents) {
|
||||
$sheet->registerListeners($this->sheetExport->registerEvents());
|
||||
}
|
||||
|
||||
$sheet->close($this->sheetExport);
|
||||
|
||||
$writer->write(
|
||||
$this->sheetExport,
|
||||
$this->temporaryFile,
|
||||
$this->writerType
|
||||
);
|
||||
}
|
||||
}
|
||||
26
vendor/maatwebsite/excel/src/Jobs/ExtendedQueueable.php
vendored
Normal file
26
vendor/maatwebsite/excel/src/Jobs/ExtendedQueueable.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
|
||||
trait ExtendedQueueable
|
||||
{
|
||||
use Queueable {
|
||||
chain as originalChain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $chain
|
||||
* @return $this
|
||||
*/
|
||||
public function chain($chain)
|
||||
{
|
||||
collect($chain)->each(function ($job) {
|
||||
$serialized = method_exists($this, 'serializeJob') ? $this->serializeJob($job) : serialize($job);
|
||||
$this->chained[] = $serialized;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
49
vendor/maatwebsite/excel/src/Jobs/Middleware/LocalizeJob.php
vendored
Normal file
49
vendor/maatwebsite/excel/src/Jobs/Middleware/LocalizeJob.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Translation\HasLocalePreference;
|
||||
use Illuminate\Support\Traits\Localizable;
|
||||
|
||||
class LocalizeJob
|
||||
{
|
||||
use Localizable;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
private $localizable;
|
||||
|
||||
/**
|
||||
* LocalizeJob constructor.
|
||||
*
|
||||
* @param object $localizable
|
||||
*/
|
||||
public function __construct($localizable)
|
||||
{
|
||||
$this->localizable = $localizable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the job.
|
||||
*
|
||||
* @param mixed $job
|
||||
* @param Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($job, Closure $next)
|
||||
{
|
||||
$locale = value(function () {
|
||||
if ($this->localizable instanceof HasLocalePreference) {
|
||||
return $this->localizable->preferredLocale();
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
return $this->withLocale($locale, function () use ($next, $job) {
|
||||
return $next($job);
|
||||
});
|
||||
}
|
||||
}
|
||||
18
vendor/maatwebsite/excel/src/Jobs/ProxyFailures.php
vendored
Normal file
18
vendor/maatwebsite/excel/src/Jobs/ProxyFailures.php
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Throwable;
|
||||
|
||||
trait ProxyFailures
|
||||
{
|
||||
/**
|
||||
* @param Throwable $e
|
||||
*/
|
||||
public function failed(Throwable $e)
|
||||
{
|
||||
if (method_exists($this->sheetExport, 'failed')) {
|
||||
$this->sheetExport->failed($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
89
vendor/maatwebsite/excel/src/Jobs/QueueExport.php
vendored
Normal file
89
vendor/maatwebsite/excel/src/Jobs/QueueExport.php
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
use Maatwebsite\Excel\Files\TemporaryFile;
|
||||
use Maatwebsite\Excel\Jobs\Middleware\LocalizeJob;
|
||||
use Maatwebsite\Excel\Writer;
|
||||
use Throwable;
|
||||
|
||||
class QueueExport implements ShouldQueue
|
||||
{
|
||||
use ExtendedQueueable, Dispatchable;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
public $export;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $writerType;
|
||||
|
||||
/**
|
||||
* @var TemporaryFile
|
||||
*/
|
||||
private $temporaryFile;
|
||||
|
||||
/**
|
||||
* @param object $export
|
||||
* @param TemporaryFile $temporaryFile
|
||||
* @param string $writerType
|
||||
*/
|
||||
public function __construct($export, TemporaryFile $temporaryFile, string $writerType)
|
||||
{
|
||||
$this->export = $export;
|
||||
$this->writerType = $writerType;
|
||||
$this->temporaryFile = $temporaryFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should be dispatched through.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function middleware()
|
||||
{
|
||||
return (method_exists($this->export, 'middleware')) ? $this->export->middleware() : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Writer $writer
|
||||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
*/
|
||||
public function handle(Writer $writer)
|
||||
{
|
||||
(new LocalizeJob($this->export))->handle($this, function () use ($writer) {
|
||||
$writer->open($this->export);
|
||||
|
||||
$sheetExports = [$this->export];
|
||||
if ($this->export instanceof WithMultipleSheets) {
|
||||
$sheetExports = $this->export->sheets();
|
||||
}
|
||||
|
||||
// Pre-create the worksheets
|
||||
foreach ($sheetExports as $sheetIndex => $sheetExport) {
|
||||
$sheet = $writer->addNewSheet($sheetIndex);
|
||||
$sheet->open($sheetExport);
|
||||
}
|
||||
|
||||
// Write to temp file with empty sheets.
|
||||
$writer->write($sheetExport, $this->temporaryFile, $this->writerType);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Throwable $e
|
||||
*/
|
||||
public function failed(Throwable $e)
|
||||
{
|
||||
if (method_exists($this->export, 'failed')) {
|
||||
$this->export->failed($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
vendor/maatwebsite/excel/src/Jobs/QueueImport.php
vendored
Normal file
37
vendor/maatwebsite/excel/src/Jobs/QueueImport.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class QueueImport implements ShouldQueue
|
||||
{
|
||||
use ExtendedQueueable, Dispatchable;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $tries;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $timeout;
|
||||
|
||||
/**
|
||||
* @param ShouldQueue $import
|
||||
*/
|
||||
public function __construct(ShouldQueue $import = null)
|
||||
{
|
||||
if ($import) {
|
||||
$this->timeout = $import->timeout ?? null;
|
||||
$this->tries = $import->tries ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
209
vendor/maatwebsite/excel/src/Jobs/ReadChunk.php
vendored
Normal file
209
vendor/maatwebsite/excel/src/Jobs/ReadChunk.php
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\ImportFailed;
|
||||
use Maatwebsite\Excel\Files\RemoteTemporaryFile;
|
||||
use Maatwebsite\Excel\Files\TemporaryFile;
|
||||
use Maatwebsite\Excel\Filters\ChunkReadFilter;
|
||||
use Maatwebsite\Excel\HasEventBus;
|
||||
use Maatwebsite\Excel\Imports\HeadingRowExtractor;
|
||||
use Maatwebsite\Excel\Sheet;
|
||||
use Maatwebsite\Excel\Transactions\TransactionHandler;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\IReader;
|
||||
use Throwable;
|
||||
|
||||
class ReadChunk implements ShouldQueue
|
||||
{
|
||||
use Queueable, HasEventBus, InteractsWithQueue;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $timeout;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $tries;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $maxExceptions;
|
||||
|
||||
/**
|
||||
* @var WithChunkReading
|
||||
*/
|
||||
private $import;
|
||||
|
||||
/**
|
||||
* @var IReader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* @var TemporaryFile
|
||||
*/
|
||||
private $temporaryFile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sheetName;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
private $sheetImport;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $startRow;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $chunkSize;
|
||||
|
||||
/**
|
||||
* @param WithChunkReading $import
|
||||
* @param IReader $reader
|
||||
* @param TemporaryFile $temporaryFile
|
||||
* @param string $sheetName
|
||||
* @param object $sheetImport
|
||||
* @param int $startRow
|
||||
* @param int $chunkSize
|
||||
*/
|
||||
public function __construct(WithChunkReading $import, IReader $reader, TemporaryFile $temporaryFile, string $sheetName, $sheetImport, int $startRow, int $chunkSize)
|
||||
{
|
||||
$this->import = $import;
|
||||
$this->reader = $reader;
|
||||
$this->temporaryFile = $temporaryFile;
|
||||
$this->sheetName = $sheetName;
|
||||
$this->sheetImport = $sheetImport;
|
||||
$this->startRow = $startRow;
|
||||
$this->chunkSize = $chunkSize;
|
||||
$this->timeout = $import->timeout ?? null;
|
||||
$this->tries = $import->tries ?? null;
|
||||
$this->maxExceptions = $import->maxExceptions ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should be dispatched through.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function middleware()
|
||||
{
|
||||
return (method_exists($this->import, 'middleware')) ? $this->import->middleware() : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the time at which the job should timeout.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function retryUntil()
|
||||
{
|
||||
return (method_exists($this->import, 'retryUntil')) ? $this->import->retryUntil() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionHandler $transaction
|
||||
*
|
||||
* @throws \Maatwebsite\Excel\Exceptions\SheetNotFoundException
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
|
||||
*/
|
||||
public function handle(TransactionHandler $transaction)
|
||||
{
|
||||
if (method_exists($this->import, 'setChunkOffset')) {
|
||||
$this->import->setChunkOffset($this->startRow);
|
||||
}
|
||||
|
||||
if ($this->sheetImport instanceof WithCustomValueBinder) {
|
||||
Cell::setValueBinder($this->sheetImport);
|
||||
}
|
||||
|
||||
$headingRow = HeadingRowExtractor::headingRow($this->sheetImport);
|
||||
|
||||
$filter = new ChunkReadFilter(
|
||||
$headingRow,
|
||||
$this->startRow,
|
||||
$this->chunkSize,
|
||||
$this->sheetName
|
||||
);
|
||||
|
||||
$this->reader->setReadFilter($filter);
|
||||
$this->reader->setReadDataOnly(config('excel.imports.read_only', true));
|
||||
$this->reader->setReadEmptyCells(!config('excel.imports.ignore_empty', false));
|
||||
|
||||
$spreadsheet = $this->reader->load(
|
||||
$this->temporaryFile->sync()->getLocalPath()
|
||||
);
|
||||
|
||||
$sheet = Sheet::byName(
|
||||
$spreadsheet,
|
||||
$this->sheetName
|
||||
);
|
||||
|
||||
if ($sheet->getHighestRow() < $this->startRow) {
|
||||
$sheet->disconnect();
|
||||
|
||||
$this->cleanUpTempFile();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$transaction(function () use ($sheet) {
|
||||
$sheet->import(
|
||||
$this->sheetImport,
|
||||
$this->startRow
|
||||
);
|
||||
|
||||
$sheet->disconnect();
|
||||
|
||||
$this->cleanUpTempFile();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Throwable $e
|
||||
*/
|
||||
public function failed(Throwable $e)
|
||||
{
|
||||
if ($this->temporaryFile instanceof RemoteTemporaryFile) {
|
||||
$this->temporaryFile->deleteLocalCopy();
|
||||
}
|
||||
|
||||
if ($this->import instanceof WithEvents) {
|
||||
$this->registerListeners($this->import->registerEvents());
|
||||
$this->raise(new ImportFailed($e));
|
||||
|
||||
if (method_exists($this->import, 'failed')) {
|
||||
$this->import->failed($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function cleanUpTempFile()
|
||||
{
|
||||
if (!config('excel.temporary_files.force_resync_remote')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$this->temporaryFile instanceof RemoteTemporaryFile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->temporaryFile->deleteLocalCopy();
|
||||
}
|
||||
}
|
||||
59
vendor/maatwebsite/excel/src/Jobs/StoreQueuedExport.php
vendored
Normal file
59
vendor/maatwebsite/excel/src/Jobs/StoreQueuedExport.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Maatwebsite\Excel\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Maatwebsite\Excel\Files\Filesystem;
|
||||
use Maatwebsite\Excel\Files\TemporaryFile;
|
||||
|
||||
class StoreQueuedExport implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $filePath;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $disk;
|
||||
|
||||
/**
|
||||
* @var TemporaryFile
|
||||
*/
|
||||
private $temporaryFile;
|
||||
/**
|
||||
* @var array|string
|
||||
*/
|
||||
private $diskOptions;
|
||||
|
||||
/**
|
||||
* @param TemporaryFile $temporaryFile
|
||||
* @param string $filePath
|
||||
* @param string|null $disk
|
||||
* @param array|string $diskOptions
|
||||
*/
|
||||
public function __construct(TemporaryFile $temporaryFile, string $filePath, string $disk = null, $diskOptions = [])
|
||||
{
|
||||
$this->disk = $disk;
|
||||
$this->filePath = $filePath;
|
||||
$this->temporaryFile = $temporaryFile;
|
||||
$this->diskOptions = $diskOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Filesystem $filesystem
|
||||
*/
|
||||
public function handle(Filesystem $filesystem)
|
||||
{
|
||||
$filesystem->disk($this->disk, $this->diskOptions)->copy(
|
||||
$this->temporaryFile,
|
||||
$this->filePath
|
||||
);
|
||||
|
||||
$this->temporaryFile->delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user