MDL-26229 backup & restore - fix quiz & lesson conflicts
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Sat, 12 Feb 2011 02:03:26 +0000 (03:03 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Sat, 12 Feb 2011 02:03:26 +0000 (03:03 +0100)
mod/lesson/backup/moodle2/backup_lesson_stepslib.php
mod/lesson/backup/moodle2/restore_lesson_stepslib.php
mod/quiz/backup/moodle2/backup_quiz_stepslib.php
mod/quiz/backup/moodle2/restore_quiz_stepslib.php

index 0b90f42..c55bffe 100644 (file)
@@ -76,8 +76,11 @@ class backup_lesson_activity_structure_step extends backup_activity_structure_st
             'minquestions','maxpages','timed','maxtime','retake','activitylink',
             'mediafile','mediaheight','mediawidth','mediaclose','slideshow',
             'width','height','bgcolor','displayleft','displayleftif','progressbar',
-            'highscores','maxhighscores','available','deadline','timemodified'
+            'showhighscores','maxhighscores','available','deadline','timemodified'
         ));
+        // Tell the lesson element about the showhighscores elements mapping to the highscores
+        // database field.
+        $lesson->set_source_alias('highscores', 'showhighscores');
 
         // The lesson_pages table
         // Grouped within a `pages` element, important to note that page is relational
index 90d0cb6..d1f34dd 100644 (file)
@@ -62,6 +62,13 @@ class restore_lesson_activity_structure_step extends restore_activity_structure_
         $data->deadline = $this->apply_date_offset($data->deadline);
         $data->timemodified = $this->apply_date_offset($data->timemodified);
 
+        // lesson->highscores can come both in data->highscores and
+        // data->showhighscores, handle both. MDL-26229
+        if (isset($data->showhighscores)) {
+            $data->highscores = $data->showhighscores;
+            unset($data->showhighscores);
+        }
+
         // insert the lesson record
         $newitemid = $DB->insert_record('lesson', $data);
         // immediately after inserting "activity" record, call this
index 7a05c5a..655cb5f 100644 (file)
@@ -39,7 +39,7 @@ class backup_quiz_activity_structure_step extends backup_questions_activity_stru
         // Define each element separated
         $quiz = new backup_nested_element('quiz', array('id'), array(
             'name', 'intro', 'introformat', 'timeopen',
-            'timeclose', 'optionflags', 'penaltyscheme', 'attempts',
+            'timeclose', 'optionflags', 'penaltyscheme', 'attempts_number',
             'attemptonlast', 'grademethod', 'decimalpoints', 'questiondecimalpoints',
             'review', 'questionsperpage', 'shufflequestions', 'shuffleanswers',
             'questions', 'sumgrades', 'grade', 'timecreated',
@@ -119,6 +119,7 @@ class backup_quiz_activity_structure_step extends backup_questions_activity_stru
         }
 
         // Define source alias
+        $quiz->set_source_alias('attempts', 'attempts_number');
         $grade->set_source_alias('grade', 'gradeval');
         $attempt->set_source_alias('attempt', 'attemptnum');
 
index 30f8baa..7222241 100644 (file)
@@ -67,6 +67,13 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
 
         $data->questions = $this->questions_recode_layout($data->questions);
 
+        // quiz->attempts can come both in data->attempts and
+        // data->attempts_number, handle both. MDL-26229
+        if (isset($data->attempts_number)) {
+            $data->attempts = $data->attempts_number;
+            unset($data->attempts_number);
+        }
+
         // insert the quiz record
         $newitemid = $DB->insert_record('quiz', $data);
         // immediately after inserting "activity" record, call this