77use Illuminate \Support \Str ;
88use Webmozart \Assert \Assert ;
99use Maatwebsite \Excel \Concerns \ToModel ;
10- use Maatwebsite \Excel \Events \AfterImport ;
11- use Maatwebsite \Excel \Concerns \Importable ;
12- use Maatwebsite \Excel \Concerns \WithEvents ;
13- use Illuminate \Contracts \Queue \ShouldQueue ;
14- use Illuminate \Foundation \Bus \PendingDispatch ;
15- use Maatwebsite \Excel \Concerns \WithHeadingRow ;
16- use FromHome \ModelUpload \Models \ModelUploadFile ;
17- use Maatwebsite \Excel \Concerns \WithBatchInserts ;
18- use Maatwebsite \Excel \Concerns \WithChunkReading ;
1910use FromHome \ModelUpload \Models \ModelUploadRecord ;
20- use Maatwebsite \Excel \Concerns \SkipsUnknownSheets ;
21- use Maatwebsite \Excel \Concerns \WithMultipleSheets ;
22- use Maatwebsite \Excel \Concerns \WithCustomStartCell ;
23- use FromHome \ModelUpload \Jobs \ProcessModelRecordJob ;
2411
25- final class ModelRecordImport implements ShouldQueue, SkipsUnknownSheets, ToModel, WithBatchInserts, WithChunkReading, WithCustomStartCell, WithEvents, WithHeadingRow, WithMultipleSheets
12+ final class ModelRecordImport extends AbstractModelRecordImport implements ToModel
2613{
27- use Importable;
28-
29- private ?ModelUploadFile $ uploadFile = null ;
30-
31- private array $ meta = [];
32-
33- public static function new (): self
34- {
35- return new self ();
36- }
37-
38- public function forFile (ModelUploadFile $ uploadFile ): self
39- {
40- $ this ->uploadFile = $ uploadFile ;
41-
42- return $ this ;
43- }
44-
45- public function withMeta (array $ meta ): self
46- {
47- $ this ->meta = $ meta ;
48-
49- return $ this ;
50- }
51-
52- public function process (): PendingDispatch
53- {
54- Assert::notNull ($ this ->uploadFile );
55-
56- return $ this ->queue (
57- $ this ->uploadFile ->getAttribute ('file_path ' ),
58- $ this ->uploadFile ->getAttribute ('storage_disk ' ),
59- );
60- }
61-
6214 public function model (array $ row ): ModelUploadRecord
6315 {
6416 Assert::notNull ($ this ->uploadFile );
@@ -70,41 +22,4 @@ public function model(array $row): ModelUploadRecord
7022 'meta ' => $ this ->meta ,
7123 ]);
7224 }
73-
74- public function batchSize (): int
75- {
76- return 500 ;
77- }
78-
79- public function chunkSize (): int
80- {
81- return 500 ;
82- }
83-
84- public function registerEvents (): array
85- {
86- return [
87- AfterImport::class => function (): void {
88- Assert::notNull ($ this ->uploadFile );
89-
90- dispatch (new ProcessModelRecordJob ($ this ->uploadFile ));
91- },
92- ];
93- }
94-
95- public function sheets (): array
96- {
97- return [
98- 'DATA ' => $ this ,
99- ];
100- }
101-
102- public function onUnknownSheet ($ sheetName ): void
103- {
104- }
105-
106- public function startCell (): string
107- {
108- return ModelUpload::importStartCell ();
109- }
11025}
0 commit comments