From: tjhunt Date: Thu, 13 Dec 2007 18:48:30 +0000 (+0000) Subject: MDL-12575 - Backup and restore problems with the new question bank. Merged from MOODL... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=27cabbe626bbe63d2ce55ab5ccec72ee21be7048;p=moodle.git MDL-12575 - Backup and restore problems with the new question bank. Merged from MOODLE_19_STABLE. --- diff --git a/backup/restorelib.php b/backup/restorelib.php index 9b21084117..e8407d5c7f 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -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 '

Updating config for block ', $instance->id, '.

'; $instance->configdata = base64_encode(serialize($config)); $status = $status && update_record('block_instance', $instance); } @@ -132,7 +131,7 @@ echo '

Updating config for block ', $instance->id, '.

'; if (!defined('RESTORE_SILENTLY')) { echo ''; } - + // Restore links in questions. require_once("$CFG->dirroot/question/restorelib.php"); if (!defined('RESTORE_SILENTLY')) { diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index f4d03eb8ce..adf32597f2 100644 --- a/mod/quiz/backuplib.php +++ b/mod/quiz/backuplib.php @@ -103,7 +103,7 @@ //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, @@ -139,7 +139,8 @@ // 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 @@ -151,7 +152,7 @@ $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); } } diff --git a/question/restorelib.php b/question/restorelib.php index aaf15a8815..48426518f5 100644 --- a/question/restorelib.php +++ b/question/restorelib.php @@ -106,7 +106,7 @@ //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){ @@ -235,7 +235,7 @@ //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); @@ -253,7 +253,7 @@ $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)){ @@ -262,7 +262,7 @@ } 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)){ @@ -862,7 +862,7 @@ $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']['#']); diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php index 0cfd258649..d0c2d20f51 100644 --- a/question/type/numerical/questiontype.php +++ b/question/type/numerical/questiontype.php @@ -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++) {