From faef8e1e6f68b8d4e0e9133c639977b9b56e03a6 Mon Sep 17 00:00:00 2001 From: Sander Date: Wed, 9 Mar 2022 12:48:37 +0100 Subject: [PATCH] Solves issue #47 If an export job stalls and restarts the CSV writer overwrites the file resulting in an export only containing the records from the last (re)start and no header row. By changing the mode to append instead of write every record is appended on a new line. Because of that, the setNewLine has to be reset otherwise there is an empty line between each record in the file. --- src/Jobs/GenerateCSVJob.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Jobs/GenerateCSVJob.php b/src/Jobs/GenerateCSVJob.php index 9cbb9dd..008ff33 100644 --- a/src/Jobs/GenerateCSVJob.php +++ b/src/Jobs/GenerateCSVJob.php @@ -224,10 +224,10 @@ protected function getOutputPath() protected function getCSVWriter() { if (!$this->writer) { - $csvWriter = Writer::createFromPath($this->getOutputPath(), 'w'); + $csvWriter = Writer::createFromPath($this->getOutputPath(), 'a'); $csvWriter->setDelimiter($this->Seperator); - $csvWriter->setNewline("\r\n"); //use windows line endings for compatibility with some csv libraries + $csvWriter->setNewline(""); $csvWriter->setOutputBOM(Writer::BOM_UTF8); if (!Config::inst()->get(GridFieldExportButton::class, 'xls_export_disabled')) {