MDL-33818 quiz restore: quiz_attempt.state not restoring old MBZ
authorTim Hunt <T.J.Hunt@open.ac.uk>
Mon, 18 Jun 2012 13:09:06 +0000 (14:09 +0100)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Mon, 18 Jun 2012 13:09:06 +0000 (14:09 +0100)
This field was new in 2.3, so we need to set it when restoring backups
from 2.2 or before, using the same logic as in upgrade.

mod/quiz/backup/moodle2/restore_quiz_stepslib.php

index 036b4e2..58a38d1 100644 (file)
@@ -307,6 +307,15 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
         $data->timefinish = $this->apply_date_offset($data->timefinish);
         $data->timemodified = $this->apply_date_offset($data->timemodified);
 
+        // Deals with up-grading pre-2.3 back-ups to 2.3+.
+        if (!isset($data->state)) {
+            if ($data->timefinish > 0) {
+                $data->state = 'finished';
+            } else {
+                $data->state = 'inprogress';
+            }
+        }
+
         // The data is actually inserted into the database later in inform_new_usage_id.
         $this->currentquizattempt = clone($data);
     }