Skip to content

Commit 7411ef1

Browse files
committed
fix: Enhance queued export functionality by adding support for root export properties
1 parent 294808c commit 7411ef1

File tree

10 files changed

+185
-43
lines changed

10 files changed

+185
-43
lines changed

.phpunit.cache/test-results

Lines changed: 5 additions & 1 deletion
Large diffs are not rendered by default.

src/Jobs/AppendDataToSheet.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,27 @@ class AppendDataToSheet implements ShouldQueue
3939
*/
4040
public $sheetExport;
4141

42+
/**
43+
* @var object|null
44+
*/
45+
public $export;
46+
4247
/**
4348
* @param object $sheetExport
4449
* @param TemporaryFile $temporaryFile
4550
* @param string $writerType
4651
* @param int $sheetIndex
4752
* @param array $data
53+
* @param object|null $export
4854
*/
49-
public function __construct($sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex, array $data)
55+
public function __construct($sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex, array $data, $export = null)
5056
{
5157
$this->sheetExport = $sheetExport;
5258
$this->data = $data;
5359
$this->temporaryFile = $temporaryFile;
5460
$this->writerType = $writerType;
5561
$this->sheetIndex = $sheetIndex;
62+
$this->export = $export;
5663
}
5764

5865
/**
@@ -80,7 +87,15 @@ public function handle(Writer $writer)
8087

8188
$sheet->appendRows($this->data, $this->sheetExport);
8289

83-
$writer->write($this->sheetExport, $this->temporaryFile, $this->writerType);
90+
$writer->write($this->getRootExport(), $this->temporaryFile, $this->writerType);
8491
});
8592
}
93+
94+
/**
95+
* @return object
96+
*/
97+
protected function getRootExport()
98+
{
99+
return $this->export ?? $this->sheetExport;
100+
}
86101
}

src/Jobs/AppendPaginatedToSheet.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,36 @@ class AppendPaginatedToSheet implements ShouldQueue
4949
*/
5050
public $perPage;
5151

52+
/**
53+
* @var object|null
54+
*/
55+
public $export;
56+
5257
/**
5358
* @param FromQuery $sheetExport
5459
* @param TemporaryFile $temporaryFile
5560
* @param string $writerType
5661
* @param int $sheetIndex
5762
* @param int $page
5863
* @param int $perPage
64+
* @param object|null $export
5965
*/
6066
public function __construct(
6167
FromQuery $sheetExport,
6268
TemporaryFile $temporaryFile,
6369
string $writerType,
6470
int $sheetIndex,
6571
int $page,
66-
int $perPage
72+
int $perPage,
73+
$export = null
6774
) {
6875
$this->sheetExport = $sheetExport;
6976
$this->temporaryFile = $temporaryFile;
7077
$this->writerType = $writerType;
7178
$this->sheetIndex = $sheetIndex;
7279
$this->page = $page;
7380
$this->perPage = $perPage;
81+
$this->export = $export;
7482
}
7583

7684
/**
@@ -98,7 +106,7 @@ public function handle(Writer $writer)
98106

99107
$sheet->appendRows($this->chunk($this->sheetExport->query()), $this->sheetExport);
100108

101-
$writer->write($this->sheetExport, $this->temporaryFile, $this->writerType);
109+
$writer->write($this->getRootExport(), $this->temporaryFile, $this->writerType);
102110
});
103111
}
104112

@@ -114,4 +122,12 @@ protected function chunk($query)
114122
// Fallback
115123
return $query->forPage($this->page, $this->perPage)->get();
116124
}
125+
126+
/**
127+
* @return object
128+
*/
129+
protected function getRootExport()
130+
{
131+
return $this->export ?? $this->sheetExport;
132+
}
117133
}

src/Jobs/AppendQueryToSheet.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,36 @@ class AppendQueryToSheet implements ShouldQueue
4848
*/
4949
public $chunkSize;
5050

51+
/**
52+
* @var object|null
53+
*/
54+
public $export;
55+
5156
/**
5257
* @param FromQuery $sheetExport
5358
* @param TemporaryFile $temporaryFile
5459
* @param string $writerType
5560
* @param int $sheetIndex
5661
* @param int $page
5762
* @param int $chunkSize
63+
* @param object|null $export
5864
*/
5965
public function __construct(
6066
FromQuery $sheetExport,
6167
TemporaryFile $temporaryFile,
6268
string $writerType,
6369
int $sheetIndex,
6470
int $page,
65-
int $chunkSize
71+
int $chunkSize,
72+
$export = null
6673
) {
6774
$this->sheetExport = $sheetExport;
6875
$this->temporaryFile = $temporaryFile;
6976
$this->writerType = $writerType;
7077
$this->sheetIndex = $sheetIndex;
7178
$this->page = $page;
7279
$this->chunkSize = $chunkSize;
80+
$this->export = $export;
7381
}
7482

7583
/**
@@ -103,10 +111,18 @@ public function handle(Writer $writer)
103111

104112
$sheet->appendRows($query->get(), $this->sheetExport);
105113

106-
$writer->write($this->sheetExport, $this->temporaryFile, $this->writerType);
114+
$writer->write($this->getRootExport(), $this->temporaryFile, $this->writerType);
107115

108116
$this->raise(new AfterChunk($sheet, $this->sheetExport, ($this->page - 1) * $this->chunkSize));
109117
$this->clearListeners();
110118
});
111119
}
120+
121+
/**
122+
* @return object
123+
*/
124+
protected function getRootExport()
125+
{
126+
return $this->export ?? $this->sheetExport;
127+
}
112128
}

src/Jobs/AppendViewToSheet.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,25 @@ class AppendViewToSheet implements ShouldQueue
3535
*/
3636
public $sheetExport;
3737

38+
/**
39+
* @var object|null
40+
*/
41+
public $export;
42+
3843
/**
3944
* @param FromView $sheetExport
4045
* @param TemporaryFile $temporaryFile
4146
* @param string $writerType
4247
* @param int $sheetIndex
43-
* @param array $data
48+
* @param object|null $export
4449
*/
45-
public function __construct(FromView $sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex)
50+
public function __construct(FromView $sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex, $export = null)
4651
{
4752
$this->sheetExport = $sheetExport;
4853
$this->temporaryFile = $temporaryFile;
4954
$this->writerType = $writerType;
5055
$this->sheetIndex = $sheetIndex;
56+
$this->export = $export;
5157
}
5258

5359
/**
@@ -75,7 +81,15 @@ public function handle(Writer $writer)
7581

7682
$sheet->fromView($this->sheetExport, $this->sheetIndex);
7783

78-
$writer->write($this->sheetExport, $this->temporaryFile, $this->writerType);
84+
$writer->write($this->getRootExport(), $this->temporaryFile, $this->writerType);
7985
});
8086
}
87+
88+
/**
89+
* @return object
90+
*/
91+
protected function getRootExport()
92+
{
93+
return $this->export ?? $this->sheetExport;
94+
}
8195
}

src/Jobs/CloseSheet.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class CloseSheet implements ShouldQueue
1717
*/
1818
private $sheetExport;
1919

20+
/**
21+
* @var object|null
22+
*/
23+
private $export;
24+
2025
/**
2126
* @var string
2227
*/
@@ -37,13 +42,15 @@ class CloseSheet implements ShouldQueue
3742
* @param TemporaryFile $temporaryFile
3843
* @param string $writerType
3944
* @param int $sheetIndex
45+
* @param object|null $export
4046
*/
41-
public function __construct($sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex)
47+
public function __construct($sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex, $export = null)
4248
{
4349
$this->sheetExport = $sheetExport;
4450
$this->temporaryFile = $temporaryFile;
4551
$this->writerType = $writerType;
4652
$this->sheetIndex = $sheetIndex;
53+
$this->export = $export;
4754
}
4855

4956
/**
@@ -68,9 +75,17 @@ public function handle(Writer $writer)
6875
$sheet->close($this->sheetExport);
6976

7077
$writer->write(
71-
$this->sheetExport,
78+
$this->getRootExport(),
7279
$this->temporaryFile,
7380
$this->writerType
7481
);
7582
}
83+
84+
/**
85+
* @return object
86+
*/
87+
private function getRootExport()
88+
{
89+
return $this->export ?? $this->sheetExport;
90+
}
7691
}

src/Jobs/QueueExport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function handle(Writer $writer)
7979
}
8080

8181
// Write to temp file with empty sheets.
82-
$writer->write($sheetExport, $this->temporaryFile, $this->writerType);
82+
$writer->write($this->export, $this->temporaryFile, $this->writerType);
8383
});
8484
}
8585

0 commit comments

Comments
 (0)