Merge pull request #2145 from denisdulici/master

Added limit to import
This commit is contained in:
Denis Duliçi 2021-06-27 03:28:59 +03:00 committed by GitHub
commit ef23e27846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 6 deletions

View File

@ -15,11 +15,12 @@ use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
use Maatwebsite\Excel\Concerns\ToModel; use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithChunkReading; use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Concerns\WithHeadingRow; use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithLimit;
use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithValidation; use Maatwebsite\Excel\Concerns\WithValidation;
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate; use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
abstract class Import implements HasLocalePreference, ShouldQueue, SkipsEmptyRows, WithChunkReading, WithHeadingRow, WithMapping, WithValidation, ToModel abstract class Import implements HasLocalePreference, ShouldQueue, SkipsEmptyRows, WithChunkReading, WithHeadingRow, WithLimit, WithMapping, WithValidation, ToModel
{ {
use Importable, ImportHelper; use Importable, ImportHelper;
@ -69,7 +70,12 @@ abstract class Import implements HasLocalePreference, ShouldQueue, SkipsEmptyRow
public function chunkSize(): int public function chunkSize(): int
{ {
return 100; return config('excel.imports.chunk_size');
}
public function limit(): int
{
return config('excel.imports.row_limit');
} }
public function isNotValid($row) public function isNotValid($row)

View File

@ -24,7 +24,7 @@ class Import extends FormRequest
public function rules() public function rules()
{ {
return [ return [
'import' => 'required|file|extension:xls,xlsx', 'import' => 'required|file|extension:' . config('excel.imports.extensions'),
]; ];
} }
} }

View File

@ -13,7 +13,7 @@ return [
| Here you can specify how big the chunk should be. | Here you can specify how big the chunk should be.
| |
*/ */
'chunk_size' => 100, 'chunk_size' => env('EXCEL_EXPORTS_CHUNK_SIZE', 100),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -42,6 +42,12 @@ return [
'imports' => [ 'imports' => [
'chunk_size' => env('EXCEL_IMPORTS_CHUNK_SIZE', 100),
'row_limit' => env('EXCEL_IMPORTS_ROW_LIMIT', 1000),
'extensions' => env('EXCEL_IMPORTS_EXTENSIONS', 'xls,xlsx'),
'read_only' => true, 'read_only' => true,
'heading_row' => [ 'heading_row' => [

View File

@ -4,6 +4,7 @@ return [
'import' => 'Import', 'import' => 'Import',
'title' => 'Import :type', 'title' => 'Import :type',
'message' => 'Allowed file types: XLS, XLSX. Please, <a target="_blank" href=":link"><strong>download</strong></a> the sample file.', 'limitations' => 'Allowed file types: :extensions<br>Allowed max rows: :row_limit',
'sample_file' => 'You can <a target="_blank" href=":download_link"><strong>download</strong></a> the sample file and fill it with your data.',
]; ];

View File

@ -8,9 +8,14 @@
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">
<div class="col-md-12">
<div class="alert alert-warning alert-important">
{!! trans('import.limitations', ['extensions' => strtoupper(config('excel.imports.extensions')), 'row_limit' => config('excel.imports.row_limit')]) !!}
</div>
</div>
<div class="col-md-12"> <div class="col-md-12">
<div class="alert alert-info alert-important"> <div class="alert alert-info alert-important">
{!! trans('import.message', ['link' => $sample_file]) !!} {!! trans('import.sample_file', ['download_link' => $sample_file]) !!}
</div> </div>
</div> </div>