function restore_create_questions($restore, $xml_file) { global $CFG, $db; $status = true; //Check it exists if (!file_exists($xml_file)) { $status = false; } //Get info from xml if ($status) { //info will contain the old_id of every category //in backup_ids->info will be the real info (serialized) $info = restore_read_xml_questions($restore, $xml_file); } //Now, if we have anything in info, we have to restore that //categories/questions if ($info) { if ($info !== true) { $status = $status && restore_question_categories($info, $restore); } } else { $status = false; } return $status; }
function restore_create_questions($restore, $xml_file) { global $CFG, $db; $status = true; //Check it exists if (!file_exists($xml_file)) { $status = false; } //Get info from xml if ($status) { //info will contain the old_id of every category //in backup_ids->info will be the real info (serialized) $info = restore_read_xml_questions($restore, $xml_file); } //Now, if we have anything in info, we have to restore that //categories/questions if ($info) { if ($info !== true) { //Iterate over each category foreach ($info as $category) { //Skip empty categories (some backups can contain them) if (!empty($category->id)) { $status = restore_question_categories($category, $restore); } } //Now we have to recode the parent field of each restored category $categories = get_records_sql("SELECT old_id, new_id \n FROM {$CFG->prefix}backup_ids\n WHERE backup_code = {$restore->backup_unique_code} AND\n table_name = 'question_categories'"); if ($categories) { foreach ($categories as $category) { $restoredcategory = get_record('question_categories', 'id', $category->new_id); $restoredcategory = addslashes_object($restoredcategory); if ($restoredcategory->parent != 0) { $idcat = backup_getid($restore->backup_unique_code, 'question_categories', $restoredcategory->parent); if ($idcat->new_id) { $restoredcategory->parent = $idcat->new_id; } else { $restoredcategory->parent = 0; } update_record('question_categories', $restoredcategory); } } } } } else { $status = false; } return $status; }