From 5bc3c63e471165121c8171b9ecc110faf9b8b627 Mon Sep 17 00:00:00 2001 From: Alexander Killing Date: Tue, 10 Oct 2023 17:28:01 +0200 Subject: [PATCH] temporary fix for exc migration --- .../Assignment/class.ilExAssignment.php | 22 +++++++++++++++++++ .../class.ilExAssignmentEditorGUI.php | 8 ++++--- ...ss.ilExerciseInstructionFilesMigration.php | 6 ++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Modules/Exercise/Assignment/class.ilExAssignment.php b/Modules/Exercise/Assignment/class.ilExAssignment.php index 3bcf405f64c6..bf566d2d7d5f 100644 --- a/Modules/Exercise/Assignment/class.ilExAssignment.php +++ b/Modules/Exercise/Assignment/class.ilExAssignment.php @@ -722,11 +722,33 @@ protected function initFromDB(array $a_set): void $this->setRelativeDeadline((int) $a_set["relative_deadline"]); $this->setRelDeadlineLastSubmission((int) $a_set["rel_deadline_last_subm"]); $rcid = $a_set["if_rcid"] ?? null; + if ($rcid === "") { // get new id, if we have an empty string here, see migration and #38167 + $rcid = $this->createInstructionFilesIrssId()->serialize(); + } if ($rcid !== null) { $this->instruction_file_rcid = $this->irss->collection()->id($rcid); } } + /** + * @return ResourceCollectionIdentification + * @throws Exception + */ + protected function createInstructionFilesIrssId(): ResourceCollectionIdentification + { + $rcid = $this->irss->collection()->id(); + $this->db->update( + "exc_assignment", + [ + "if_rcid" => ["text", $rcid->serialize()] + ], + [ // where + "id" => ["integer", $this->getId()] + ] + ); + return $rcid; + } + /** * @throws ilDateTimeException */ diff --git a/Modules/Exercise/Assignment/class.ilExAssignmentEditorGUI.php b/Modules/Exercise/Assignment/class.ilExAssignmentEditorGUI.php index 11f82925df4b..f737d392b918 100644 --- a/Modules/Exercise/Assignment/class.ilExAssignmentEditorGUI.php +++ b/Modules/Exercise/Assignment/class.ilExAssignmentEditorGUI.php @@ -911,9 +911,11 @@ protected function importFormToAssignment( } // Create Collection ID - $rcid = $this->irss->collection()->id(); - $a_ass->setInstructionFileRCID($rcid); - $a_ass->update(); + if ($is_create) { + $rcid = $this->irss->collection()->id(); + $a_ass->setInstructionFileRCID($rcid); + $a_ass->update(); + } // id needed for file handling if ($is_create) { diff --git a/Modules/Exercise/classes/Setup/class.ilExerciseInstructionFilesMigration.php b/Modules/Exercise/classes/Setup/class.ilExerciseInstructionFilesMigration.php index 70780991fb77..7557177fead9 100644 --- a/Modules/Exercise/classes/Setup/class.ilExerciseInstructionFilesMigration.php +++ b/Modules/Exercise/classes/Setup/class.ilExerciseInstructionFilesMigration.php @@ -59,7 +59,7 @@ public function step(Environment $environment): void { $db = $this->helper->getDatabase(); $r = $this->helper->getDatabase()->query( - "SELECT id, exc_id, owner FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE if_rcid IS NULL OR if_rcid = '' LIMIT 1;" + "SELECT id, exc_id, owner FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE if_rcid IS NULL LIMIT 1;" ); $d = $this->helper->getDatabase()->fetchObject($r); $exec_id = (int)$d->exc_id; @@ -73,7 +73,7 @@ public function step(Environment $environment): void $this->helper->getDatabase()->update( 'exc_assignment', [ - 'if_rcid' => ['text', $collection_id] + 'if_rcid' => ['text', (string) $collection_id] ], [ 'id' => ['integer', $assignment_id], @@ -85,7 +85,7 @@ public function step(Environment $environment): void public function getRemainingAmountOfSteps(): int { $r = $this->helper->getDatabase()->query( - "SELECT count(id) AS amount FROM exc_assignment WHERE if_rcid IS NULL OR if_rcid = ''" + "SELECT count(id) AS amount FROM exc_assignment WHERE if_rcid IS NULL " ); $d = $this->helper->getDatabase()->fetchObject($r);