From afee7280c42a865a144656acdcd4ee9f8cac44e5 Mon Sep 17 00:00:00 2001 From: Christian Hartmann Date: Mon, 9 Mar 2026 23:48:28 +0100 Subject: [PATCH] fix(export): Handle exceptions when reading file content and ignore whitespace-only files Signed-off-by: Christian Hartmann --- lib/Service/SubmissionService.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index a64999585..5cff29713 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -312,9 +312,19 @@ function (array $carry, Answer $answer) use ($questionPerQuestionId) { * @param array|non-empty-list> $data */ private function exportData(array $header, array $data, string $fileFormat, ?File $file = null): string { - if ($file && $file->getContent()) { + $content = null; + if ($file) { + try { + $content = $file->getContent(); + } catch (\Exception $e) { + $this->logger->warning('Failed to read existing linked file content: {msg}', ['msg' => $e->getMessage()]); + } + } + + // Ignore whitespace-only files (e.g. S3 single-space placeholder). + if ($content !== null && trim($content) !== '') { $existentFile = $this->tempManager->getTemporaryFile($fileFormat); - file_put_contents($existentFile, $file->getContent()); + file_put_contents($existentFile, $content); $spreadsheet = IOFactory::load($existentFile); } else { $spreadsheet = new Spreadsheet();