}
$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);
}
if (!defined('RESTORE_SILENTLY')) {
echo '</li>';
}
-
+
// Restore links in questions.
require_once("$CFG->dirroot/question/restorelib.php");
if (!defined('RESTORE_SILENTLY')) {
//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);
}
}
//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']['#']);
$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++) {