mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-02-03 16:09:36 +00:00
Do not use ob_* functions in XSLX exporter, as this affects global state and can lead to sideffects
This commit is contained in:
parent
0c7aa5e92a
commit
d57107ed3e
1 changed files with 10 additions and 5 deletions
|
|
@ -137,7 +137,7 @@ class EntityExporter
|
||||||
*
|
*
|
||||||
* @param AbstractNamedDBElement[] $entities The entities to export
|
* @param AbstractNamedDBElement[] $entities The entities to export
|
||||||
* @param array $options The export options
|
* @param array $options The export options
|
||||||
*
|
*
|
||||||
* @return string The Excel file content as binary string
|
* @return string The Excel file content as binary string
|
||||||
*/
|
*/
|
||||||
protected function exportToExcel(array $entities, array $options): string
|
protected function exportToExcel(array $entities, array $options): string
|
||||||
|
|
@ -187,10 +187,15 @@ class EntityExporter
|
||||||
//Save to memory stream
|
//Save to memory stream
|
||||||
$writer = $options['format'] === 'xlsx' ? new Xlsx($spreadsheet) : new Xls($spreadsheet);
|
$writer = $options['format'] === 'xlsx' ? new Xlsx($spreadsheet) : new Xls($spreadsheet);
|
||||||
|
|
||||||
ob_start();
|
$memFile = fopen("php://temp", 'r+b');
|
||||||
$writer->save('php://output');
|
$writer->save($memFile);
|
||||||
$content = ob_get_contents();
|
rewind($memFile);
|
||||||
ob_end_clean();
|
$content = stream_get_contents($memFile);
|
||||||
|
fclose($memFile);
|
||||||
|
|
||||||
|
if ($content === false) {
|
||||||
|
throw new \RuntimeException('Failed to read Excel content from memory stream.');
|
||||||
|
}
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue