]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12575 - Backup and restore problems with the new question bank. Merged from MOODL...
authortjhunt <tjhunt>
Thu, 13 Dec 2007 18:48:30 +0000 (18:48 +0000)
committertjhunt <tjhunt>
Thu, 13 Dec 2007 18:48:30 +0000 (18:48 +0000)
backup/restorelib.php
mod/quiz/backuplib.php
question/restorelib.php
question/type/numerical/questiontype.php

index 9b210841175a192a7b38476cf10852b2e5ce4f66..e8407d5c7f2f95a7ee1416aa2533948c366a7fae 100644 (file)
@@ -123,7 +123,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
                 }
                 $config = unserialize(base64_decode($instance->configdata));
                 if ($blocks[$instance->blockid]->blockobject->restore_decode_absolute_links_in_config($config)) {
-echo '<p>Updating config for block ', $instance->id, '.</p>';
                     $instance->configdata = base64_encode(serialize($config));
                     $status = $status && update_record('block_instance', $instance);
                 }
@@ -132,7 +131,7 @@ echo '<p>Updating config for block ', $instance->id, '.</p>';
         if (!defined('RESTORE_SILENTLY')) {
             echo '</li>';
         }
-        
+
         // Restore links in questions.
         require_once("$CFG->dirroot/question/restorelib.php");
         if (!defined('RESTORE_SILENTLY')) {
index f4d03eb8cefe886ac0d4bf655fd3cbdfc38079fb..adf32597f28eac116cf5fd579027e8e5491a2ad4 100644 (file)
             //put the ids of the used questions from all these categories into the db.
             $status = $status && execute_sql("INSERT INTO {$CFG->prefix}backup_ids
                                        (backup_code, table_name, old_id, info)
-                                       SELECT '$backup_unique_code', 'question', q.id, ''
+                                       SELECT DISTINCT $backup_unique_code, 'question', q.id, ''
                                        FROM {$CFG->prefix}question q,
                                        $from
                                        {$CFG->prefix}question_categories qc,
             // those subcategories also need to be backed up. (The categories themselves
             // and their parents will already have been included.)
             $categorieswithrandom = get_records_sql("
-                    SELECT question.category AS id, SUM(question.questiontext) as questiontext
+                    SELECT question.category AS id, SUM(" .
+                            sql_cast_char2int('questiontext', true) . ") AS numqsusingsubcategories
                     FROM {$CFG->prefix}quiz_question_instances qqi,
                          $from
                          {$CFG->prefix}question question
             $randomselectedquestions = array();
             if ($categorieswithrandom) {
                 foreach ($categorieswithrandom as $category) {
-                    if ($category->questiontext){
+                    if ($category->numqsusingsubcategories > 0) {
                         $status = $status && quiz_backup_add_sub_categories($categories, $randomselectedquestions, $category->id);
                     }
                 }
index aaf15a8815c4c2b2ee5f3f87cbdcbab40325fd24..48426518f5f325a38560496dedcac07aac440c72 100644 (file)
                 //search COURSECATEGORYLEVEL steps up the course cat tree or
                 //to the top of the tree if steps are exhausted.
                 $catno = $contextinfo['COURSECATEGORYLEVEL'][0]['#'];
-                $catid = get_field('course', 'parent', 'id', $restore->course_id);
+                $catid = get_field('course', 'category', 'id', $restore->course_id);
                 while ($catno > 1){
                     $nextcatid = get_field('course_categories', 'parent', 'id', $catid);
                     if ($nextcatid == 0){
             //recode all parents to point at their old parent cats no matter what context the parent is now in
             foreach ($categories as $category) {
                 $restoredcategory = get_record('question_categories','id',$category->new_id);
-                if ($restoredcategory->parent != 0) {
+                if ($restoredcategory && $restoredcategory->parent != 0) {
                     $updateobj = new object();
                     $updateobj->id = $restoredcategory->id;
                     $idcat = backup_getid($restore->backup_unique_code,'question_categories',$restoredcategory->parent);
             $toupdate = array();
             foreach ($categories as $category) {
                 $restoredcategory = get_record('question_categories','id',$category->new_id);
-                if ($restoredcategory->parent != 0) {
+                if ($restoredcategory && $restoredcategory->parent != 0) {
                     $nextparentid = $restoredcategory->parent;
                     do {
                         if (!$parent = get_record('question_categories', 'id', $nextparentid)){
                             }
                             break;//record fetch failed finish loop
                         } else {
-                            $nextparentid = $nextparent->parent;
+                            $nextparentid = $parent->parent;
                         }
                     } while (($nextparentid != 0) && ($parent->contextid != $restoredcategory->contextid));
                     if (!$parent || ($parent->id != $restoredcategory->parent)){
             $session->newgraded = backup_todb($res_info['#']['NEWGRADED']['0']['#']);
             $session->sumpenalty = backup_todb($res_info['#']['SUMPENALTY']['0']['#']);
 
-            if ($res_info['#']['MANUALCOMMENT']['0']['#']) {
+            if (isset($res_info['#']['MANUALCOMMENT']['0']['#'])) {
                 $session->manualcomment = backup_todb($res_info['#']['MANUALCOMMENT']['0']['#']);
             } else { // pre 1.7 backups
                 $session->manualcomment = backup_todb($res_info['#']['COMMENT']['0']['#']);
index 0cfd258649e4113088c0e45585b65278da35dd25..d0c2d20f510cdd4671514f8a2c2a77a15183fb39 100644 (file)
@@ -437,7 +437,11 @@ class question_numerical_qtype extends question_shortanswer_qtype {
         $status = true;
 
         //Get the numerical array
-        $numericals = $info['#']['NUMERICAL'];
+        if (isset($info['#']['NUMERICAL'])) {
+            $numericals = $info['#']['NUMERICAL'];
+        } else {
+            $numericals = array();
+        }
 
         //Iterate over numericals
         for($i = 0; $i < sizeof($numericals); $i++) {