From 915530ac963a03c507a8f13dfbf8300ff303d289 Mon Sep 17 00:00:00 2001 From: Stephan Kergomard Date: Mon, 16 Dec 2024 16:14:10 +0100 Subject: [PATCH] Test: Ensure Results Don't Contain Negative Values See: https://mantis.ilias.de/view.php?id=43199 --- .../Setup/class.ilTest9DBUpdateSteps.php | 6 ++++++ Modules/Test/classes/class.ilObjTest.php | 17 +++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Modules/Test/classes/Setup/class.ilTest9DBUpdateSteps.php b/Modules/Test/classes/Setup/class.ilTest9DBUpdateSteps.php index 11c809963b65..0ef1332055a1 100644 --- a/Modules/Test/classes/Setup/class.ilTest9DBUpdateSteps.php +++ b/Modules/Test/classes/Setup/class.ilTest9DBUpdateSteps.php @@ -354,4 +354,10 @@ public function step_20(): void { $this->db->modifyTableColumn('ass_log', 'logtext', ['type' => \ilDBConstants::T_CLOB]); } + + public function step_21(): void + { + $this->db->manipulate('UPDATE tst_pass_result SET points = 0 WHERE points < 0'); + $this->db->manipulate('UPDATE tst_result_cache SET reached_points = 0 WHERE reached_points < 0'); + } } diff --git a/Modules/Test/classes/class.ilObjTest.php b/Modules/Test/classes/class.ilObjTest.php index c41ad793e163..fc9dd1f281fe 100755 --- a/Modules/Test/classes/class.ilObjTest.php +++ b/Modules/Test/classes/class.ilObjTest.php @@ -8109,6 +8109,10 @@ public function updateTestResultCache(int $active_id, ilAssQuestionProcessLocker [$active_id] ); + if ($reached < 0.0) { + $reached = 0.0; + } + $mark_short_name = $mark->getShortName(); if ($mark_short_name === '') { $mark_short_name = ' '; @@ -8205,7 +8209,8 @@ public function updateTestPassResults( $row = $this->db->fetchAssoc($result); - if ($row['reachedpoints'] === null) { + if ($row['reachedpoints'] === null + || $row['reachedpoints'] < 0.0) { $row['reachedpoints'] = 0.0; } if ($row['hint_count'] === null) { @@ -8225,7 +8230,7 @@ public function updateTestPassResults( 'pass' => ['integer', $pass] ], [ - 'points' => ['float', $row['reachedpoints'] ?: 0], + 'points' => ['float', $row['reachedpoints']], 'maxpoints' => ['float', $data['points']], 'questioncount' => ['integer', $data['count']], 'answeredquestions' => ['integer', $row['answeredquestions']], @@ -8251,10 +8256,10 @@ public function updateTestPassResults( return [ 'active_fi' => $active_id, 'pass' => $pass, - 'points' => $row["reachedpoints"] ?? 0.0, - 'maxpoints' => $data["points"], - 'questioncount' => $data["count"], - 'answeredquestions' => $row["answeredquestions"], + 'points' => $row['reachedpoints'], + 'maxpoints' => $data['points'], + 'questioncount' => $data['count'], + 'answeredquestions' => $row['answeredquestions'], 'workingtime' => $time, 'tstamp' => time(), 'hint_count' => $row['hint_count'],