Skip to content

Commit

Permalink
Solves issue silverstripe#47 If an export job stalls and restarts the…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
SanderHamaka committed Mar 9, 2022
1 parent 0c97234 commit faef8e1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Jobs/GenerateCSVJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit faef8e1

Please sign in to comment.