From 1ff6e1913c0b3be3e8c2c489679a61f791c864a9 Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer Date: Tue, 17 Dec 2024 11:51:03 +0100 Subject: [PATCH] refactor: check file extension before writing file --- .../Test/src/ExportImport/ResultsExportExcel.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/components/ILIAS/Test/src/ExportImport/ResultsExportExcel.php b/components/ILIAS/Test/src/ExportImport/ResultsExportExcel.php index 4c462ec4e7d7..b10014b4cca7 100755 --- a/components/ILIAS/Test/src/ExportImport/ResultsExportExcel.php +++ b/components/ILIAS/Test/src/ExportImport/ResultsExportExcel.php @@ -44,16 +44,12 @@ public function __construct( private readonly \ilLanguage $lng, private readonly \ilObjUser $current_user, private readonly \ilObjTest $test_obj, - private string $filename = '', + private readonly string $filename = '', private readonly bool $scoredonly = true, ) { $this->user_date_format = $this->current_user->getDateTimeFormat(); $this->aggregated_data = $test_obj->getAggregatedResultsData(); $this->worksheet = new \ilExcel(); - - if (!str_contains($this->filename, '.xlsx')) { - $this->filename .= '.xlsx'; - } } public function withFilterByActiveId(int $active_id): self @@ -124,6 +120,13 @@ public function withUserPages(): self public function write(): ?string { $path = \ilFileUtils::ilTempnam() . $this->filename; + + $this->worksheet->setFormat(\ilExcel::FORMAT_XML); + $extension = '.' . strtolower(\ilExcel::FORMAT_XML); + if (!str_ends_with($path, $extension)) { + $path .= $extension; + } + $this->worksheet->writeToFile($path); return $path; }