Skip to content

Commit dfd5178

Browse files
authored
Merge pull request #3214 from nextcloud/fix/s3_export
fix(export): Handle exceptions when reading file content and ignore whitespace-only files
2 parents 59080d8 + 0b03c8c commit dfd5178

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

lib/Service/SubmissionService.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,19 @@ function (array $carry, Answer $answer) use ($questionPerQuestionId, $gridRowsPe
380380
* @param list<non-empty-list<array{columns?: list<mixed|string>, label?: string, url?: string}|mixed|null|string>> $data
381381
*/
382382
private function exportData(array $header, array $data, string $fileFormat, ?File $file = null): string {
383-
if ($file && $file->getContent()) {
383+
$content = null;
384+
if ($file) {
385+
try {
386+
$content = $file->getContent();
387+
} catch (\Exception $e) {
388+
$this->logger->warning('Failed to read existing linked file content: {msg}', ['msg' => $e->getMessage()]);
389+
}
390+
}
391+
392+
// Ignore whitespace-only files (e.g. S3 single-space placeholder).
393+
if ($content !== null && trim($content) !== '') {
384394
$existentFile = $this->tempManager->getTemporaryFile($fileFormat);
385-
file_put_contents($existentFile, $file->getContent());
395+
file_put_contents($existentFile, $content);
386396
$spreadsheet = IOFactory::load($existentFile);
387397
} else {
388398
$spreadsheet = new Spreadsheet();

0 commit comments

Comments
 (0)