Skip to content

Commit 85a6f7a

Browse files
authored
Merge pull request #3223 from nextcloud/backport/3214/stable5.2
[stable5.2] fix(export): Handle exceptions when reading file content and ignore whitespace-only files
2 parents be2cb24 + afee728 commit 85a6f7a

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
@@ -312,9 +312,19 @@ function (array $carry, Answer $answer) use ($questionPerQuestionId) {
312312
* @param array<int, array<int, string>|non-empty-list<array{label: string, url: string}>> $data
313313
*/
314314
private function exportData(array $header, array $data, string $fileFormat, ?File $file = null): string {
315-
if ($file && $file->getContent()) {
315+
$content = null;
316+
if ($file) {
317+
try {
318+
$content = $file->getContent();
319+
} catch (\Exception $e) {
320+
$this->logger->warning('Failed to read existing linked file content: {msg}', ['msg' => $e->getMessage()]);
321+
}
322+
}
323+
324+
// Ignore whitespace-only files (e.g. S3 single-space placeholder).
325+
if ($content !== null && trim($content) !== '') {
316326
$existentFile = $this->tempManager->getTemporaryFile($fileFormat);
317-
file_put_contents($existentFile, $file->getContent());
327+
file_put_contents($existentFile, $content);
318328
$spreadsheet = IOFactory::load($existentFile);
319329
} else {
320330
$spreadsheet = new Spreadsheet();

0 commit comments

Comments
 (0)