MDL-15095 towards restore lib dml conversion

This commit is contained in:
skodak 2008-06-03 23:35:50 +00:00
parent 9db7dab2ca
commit cd655b33f9
16 changed files with 207 additions and 238 deletions

View file

@ -3268,7 +3268,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Now search if that group exists (by name and description field) in //Now search if that group exists (by name and description field) in
//restore->course_id course //restore->course_id course
//Going to compare LOB columns so, use the cross-db sql_compare_text() in both sides. //Going to compare LOB columns so, use the cross-db $DB->sql_compare_text() in both sides.
$description_clause = ''; $description_clause = '';
$params = array('courseid'=>$restore->course_id, 'grname'=>$gro->name); $params = array('courseid'=>$restore->course_id, 'grname'=>$gro->name);
if (!empty($gro->description)) { /// Only for groups having a description if (!empty($gro->description)) { /// Only for groups having a description

View file

@ -328,12 +328,10 @@
//working in the backup/restore process. It's called from restore_decode_content_links() //working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process //function in restore process
function assignment_decode_content_links_caller($restore) { function assignment_decode_content_links_caller($restore) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
if ($assignments = get_records_sql ("SELECT a.id, a.description if ($assignments = $DB->get_records('assignment', array('course'=>$restore->course_id), '', "id,description")) {
FROM {$CFG->prefix}assignment a
WHERE a.course = $restore->course_id")) {
//Iterate over each assignment->description //Iterate over each assignment->description
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($assignments as $assignment) { foreach ($assignments as $assignment) {
@ -343,8 +341,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$assignment->description = addslashes($result); $assignment->description = $result;
$status = update_record("assignment",$assignment); $status = $DB->update_record("assignment",$assignment);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@ -369,20 +367,18 @@
//This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
//some texts in the module //some texts in the module
function assignment_restore_wiki2markdown ($restore) { function assignment_restore_wiki2markdown ($restore) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
//Convert assignment->description //Convert assignment->description
if ($records = get_records_sql ("SELECT a.id, a.description, a.format if ($records = $DB->get_records_sql ("SELECT a.id, a.description, a.format
FROM {$CFG->prefix}assignment a, FROM {assignment} a, {backup_ids} b
{$CFG->prefix}backup_ids b WHERE a.course = ? AND
WHERE a.course = $restore->course_id AND
a.format = ".FORMAT_WIKI. " AND a.format = ".FORMAT_WIKI. " AND
b.backup_code = $restore->backup_unique_code AND b.backup_code = ? AND
b.table_name = 'assignment' AND b.table_name = 'assignment' AND
b.new_id = a.id")) { b.new_id = a.id", array($restore->course_id, $restore->backup_unique_code))) {
foreach ($records as $record) { foreach ($records as $record) {
//Rebuild wiki links //Rebuild wiki links
$record->description = restore_decode_wiki_content($record->description, $restore); $record->description = restore_decode_wiki_content($record->description, $restore);
@ -390,7 +386,7 @@
$wtm = new WikiToMarkdown(); $wtm = new WikiToMarkdown();
$record->description = $wtm->convert($record->description, $restore->course_id); $record->description = $wtm->convert($record->description, $restore->course_id);
$record->format = FORMAT_MARKDOWN; $record->format = FORMAT_MARKDOWN;
$status = update_record('assignment', addslashes_object($record)); $status = $DB->update_record('assignment', $record);
//Do some output //Do some output
$i++; $i++;
if (($i+1) % 1 == 0) { if (($i+1) % 1 == 0) {

View file

@ -206,12 +206,10 @@
//working in the backup/restore process. It's called from restore_decode_content_links() //working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process //function in restore process
function chat_decode_content_links_caller($restore) { function chat_decode_content_links_caller($restore) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
if ($chats = get_records_sql ("SELECT c.id, c.intro if ($chats = $DB->get_records('chat', array('course'=>$restore->course_id), '', "id,intro")) {
FROM {$CFG->prefix}chat c
WHERE c.course = $restore->course_id")) {
//Iterate over each chat->intro //Iterate over each chat->intro
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($chats as $chat) { foreach ($chats as $chat) {
@ -221,8 +219,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$chat->intro = addslashes($result); $chat->intro = $result;
$status = update_record("chat",$chat); $status = $DB->update_record("chat",$chat);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';

View file

@ -144,8 +144,7 @@
} }
function choice_options_restore_mods($choiceid,$info,$restore) { function choice_options_restore_mods($choiceid,$info,$restore) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
@ -169,7 +168,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
$option->timemodified = backup_todb($opt_info['#']['TIMEMODIFIED']['0']['#']); $option->timemodified = backup_todb($opt_info['#']['TIMEMODIFIED']['0']['#']);
//The structure is equal to the db, so insert the choice_options //The structure is equal to the db, so insert the choice_options
$newid = insert_record ("choice_options",$option); $newid = $DB->insert_record ("choice_options",$option);
//Do some output //Do some output
if (($i+1) % 50 == 0) { if (($i+1) % 50 == 0) {
@ -196,8 +195,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
//This function restores the choice_answers //This function restores the choice_answers
function choice_answers_restore_mods($choiceid,$info,$restore) { function choice_answers_restore_mods($choiceid,$info,$restore) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
@ -239,7 +237,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
} }
//The structure is equal to the db, so insert the choice_answers //The structure is equal to the db, so insert the choice_answers
$newid = insert_record ("choice_answers",$answer); $newid = $DB->insert_record ("choice_answers",$answer);
//Do some output //Do some output
if (($i+1) % 50 == 0) { if (($i+1) % 50 == 0) {
@ -336,9 +334,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
global $CFG; global $CFG;
$status = true; $status = true;
if ($choices = get_records_sql ("SELECT c.id, c.text if ($choices = $DB->get_records('chat', array('course'=>$restore->course_id), '', "id,text")) {
FROM {$CFG->prefix}choice c
WHERE c.course = $restore->course_id")) {
//Iterate over each choice->text //Iterate over each choice->text
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($choices as $choice) { foreach ($choices as $choice) {
@ -348,8 +344,8 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$choice->text = addslashes($result); $choice->text = $result;
$status = update_record("choice",$choice); $status = $DB->update_record("choice",$choice);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@ -375,20 +371,18 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
//This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
//some texts in the module //some texts in the module
function choice_restore_wiki2markdown ($restore) { function choice_restore_wiki2markdown ($restore) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
//Convert choice->text //Convert choice->text
if ($records = get_records_sql ("SELECT c.id, c.text, c.format if ($records = $DB->get_records_sql("SELECT c.id, c.text, c.format
FROM {$CFG->prefix}choice c, FROM {choice} c, {backup_ids} b
{$CFG->prefix}backup_ids b WHERE c.course = ? AND
WHERE c.course = $restore->course_id AND c.format = ".FORMAT_WIKI. " AND
c.format = ".FORMAT_WIKI. " AND b.backup_code = ? AND
b.backup_code = $restore->backup_unique_code AND b.table_name = 'choice' AND
b.table_name = 'choice' AND b.new_id = c.id", array($restore->course_id, $restore->backup_unique_code))) {
b.new_id = c.id")) {
foreach ($records as $record) { foreach ($records as $record) {
//Rebuild wiki links //Rebuild wiki links
$record->text = restore_decode_wiki_content($record->text, $restore); $record->text = restore_decode_wiki_content($record->text, $restore);
@ -396,7 +390,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
$wtm = new WikiToMarkdown(); $wtm = new WikiToMarkdown();
$record->text = $wtm->convert($record->text, $restore->course_id); $record->text = $wtm->convert($record->text, $restore->course_id);
$record->format = FORMAT_MARKDOWN; $record->format = FORMAT_MARKDOWN;
$status = update_record('choice', addslashes_object($record)); $status = $DB->update_record('choice', $record);
//Do some output //Do some output
$i++; $i++;
if (($i+1) % 1 == 0) { if (($i+1) % 1 == 0) {

View file

@ -555,17 +555,17 @@ function data_decode_content_links ($content,$restore) {
* @return boolean status of the execution * @return boolean status of the execution
*/ */
function data_decode_content_links_caller($restore) { function data_decode_content_links_caller($restore) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
/// Process every DATA (intro, all HTML templates) in the course /// Process every DATA (intro, all HTML templates) in the course
/// Supported fields for main table: /// Supported fields for main table:
$supportedfields = array('intro','singletemplate','listtemplate', $supportedfields = array('intro','singletemplate','listtemplate',
'listtemplateheader','addtemplate','rsstemplate','rsstitletemplate'); 'listtemplateheader','addtemplate','rsstemplate','rsstitletemplate');
if ($datas = get_records_sql ("SELECT d.id, ".implode(',',$supportedfields)." if ($datas = $DB->get_records_sql ("SELECT d.id, ".implode(',',$supportedfields)."
FROM {$CFG->prefix}data d FROM {data} d
WHERE d.course = $restore->course_id")) { WHERE d.course = ?", array($restore->course_id))) {
/// Iterate over each data /// Iterate over each data
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($datas as $data) { foreach ($datas as $data) {
@ -573,7 +573,7 @@ function data_decode_content_links_caller($restore) {
$i++; $i++;
/// Make a new copy of the data object with nothing in, to use if /// Make a new copy of the data object with nothing in, to use if
/// changes are necessary (allows us to do update_record without /// changes are necessary (allows us to do $DB->update_record without
/// worrying about every single field being included and needing /// worrying about every single field being included and needing
/// slashes). /// slashes).
$newdata = new stdClass; $newdata = new stdClass;
@ -584,7 +584,7 @@ function data_decode_content_links_caller($restore) {
foreach($supportedfields as $field) { foreach($supportedfields as $field) {
$result = restore_decode_content_links_worker($data->{$field},$restore); $result = restore_decode_content_links_worker($data->{$field},$restore);
if ($result != $data->{$field}) { if ($result != $data->{$field}) {
$newdata->{$field} = addslashes($result); $newdata->{$field} = $result;
$changed = true; $changed = true;
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
@ -596,7 +596,7 @@ function data_decode_content_links_caller($restore) {
/// Update record if any field changed /// Update record if any field changed
if($changed) { if($changed) {
$status = update_record("data",$newdata); $status = $DB->update_record("data",$newdata);
} }
/// Do some output /// Do some output
@ -613,13 +613,13 @@ function data_decode_content_links_caller($restore) {
} }
/// Process every COMMENT (content) in the course /// Process every COMMENT (content) in the course
if ($comments = get_records_sql ("SELECT dc.id, dc.content if ($comments = $DB->get_records_sql ("SELECT dc.id, dc.content
FROM {$CFG->prefix}data d, FROM {data} d,
{$CFG->prefix}data_records dr, {data_records} dr,
{$CFG->prefix}data_comments dc {data_comments} dc
WHERE d.course = $restore->course_id WHERE d.course = ?
AND dr.dataid = d.id AND dr.dataid = d.id
AND dc.recordid = dr.id")) { AND dc.recordid = dr.id", array($restore->course_id))) {
/// Iterate over each data_comments->content /// Iterate over each data_comments->content
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($comments as $comment) { foreach ($comments as $comment) {
@ -629,8 +629,8 @@ function data_decode_content_links_caller($restore) {
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
/// Update record /// Update record
$comment->content = addslashes($result); $comment->content = $result;
$status = update_record("data_comments",$comment); $status = $DB->update_record("data_comments",$comment);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@ -651,13 +651,13 @@ function data_decode_content_links_caller($restore) {
} }
/// Process every CONTENT (content, content1, content2, content3, content4) in the course /// Process every CONTENT (content, content1, content2, content3, content4) in the course
if ($contents = get_records_sql ("SELECT dc.id, dc.content, dc.content1, dc.content2, dc.content3, dc.content4 if ($contents = $DB->get_records_sql("SELECT dc.id, dc.content, dc.content1, dc.content2, dc.content3, dc.content4
FROM {$CFG->prefix}data d, FROM {data} d,
{$CFG->prefix}data_records dr, {data_records} dr,
{$CFG->prefix}data_content dc {data_content} dc
WHERE d.course = $restore->course_id WHERE d.course = ?
AND dr.dataid = d.id AND dr.dataid = d.id
AND dc.recordid = dr.id")) { AND dc.recordid = dr.id", array($restore->course_id))) {
/// Iterate over each data_content->content, content1, content2, content3 and content4 /// Iterate over each data_content->content, content1, content2, content3 and content4
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($contents as $cnt) { foreach ($contents as $cnt) {
@ -683,22 +683,22 @@ function data_decode_content_links_caller($restore) {
unset($cnt->content4); unset($cnt->content4);
/// Conditionally set the fields /// Conditionally set the fields
if ($result != $content) { if ($result != $content) {
$cnt->content = addslashes($result); $cnt->content = $result;
} }
if ($result1 != $content1) { if ($result1 != $content1) {
$cnt->content1 = addslashes($result1); $cnt->content1 = $result1;
} }
if ($result2 != $content2) { if ($result2 != $content2) {
$cnt->content2 = addslashes($result2); $cnt->content2 = $result2;
} }
if ($result3 != $content3) { if ($result3 != $content3) {
$cnt->content3 = addslashes($result3); $cnt->content3 = $result3;
} }
if ($result4 != $content4) { if ($result4 != $content4) {
$cnt->content4 = addslashes($result4); $cnt->content4 = $result4;
} }
/// Update record with the changed fields /// Update record with the changed fields
$status = update_record("data_content",$cnt); $status = $DB->update_record("data_content",$cnt);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';

View file

@ -703,6 +703,7 @@
//This function returns a log record with all the necessay transformations //This function returns a log record with all the necessay transformations
//done. It's used by restore_log_module() to restore modules log. //done. It's used by restore_log_module() to restore modules log.
function forum_restore_logs($restore,$log) { function forum_restore_logs($restore,$log) {
global $DB;
$status = false; $status = false;
@ -871,7 +872,7 @@
$pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info); $pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info);
if ($pos) { if ($pos) {
//Get the post record from database //Get the post record from database
$dbpos = get_record("forum_posts","id","$pos->new_id"); $dbpos = $DB->get_record("forum_posts", array("id"=>$pos->new_id));
if ($dbpos) { if ($dbpos) {
$log->url = "discuss.php?d=".$dbpos->discussion."&parent=".$pos->new_id; $log->url = "discuss.php?d=".$dbpos->discussion."&parent=".$pos->new_id;
$log->info = $pos->new_id; $log->info = $pos->new_id;
@ -886,7 +887,7 @@
$pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info); $pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info);
if ($pos) { if ($pos) {
//Get the post record from database //Get the post record from database
$dbpos = get_record("forum_posts","id","$pos->new_id"); $dbpos = $DB->get_record("forum_posts", array("id"=>$pos->new_id));
if ($dbpos) { if ($dbpos) {
$log->url = "discuss.php?d=".$dbpos->discussion; $log->url = "discuss.php?d=".$dbpos->discussion;
$log->info = $pos->new_id; $log->info = $pos->new_id;
@ -901,7 +902,7 @@
$pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info); $pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info);
if ($pos) { if ($pos) {
//Get the post record from database //Get the post record from database
$dbpos = get_record("forum_posts","id","$pos->new_id"); $dbpos = $DB->get_record("forum_posts", array("id"=>$pos->new_id));
if ($dbpos) { if ($dbpos) {
$log->url = "discuss.php?d=".$dbpos->discussion."&parent=".$pos->new_id; $log->url = "discuss.php?d=".$dbpos->discussion."&parent=".$pos->new_id;
$log->info = $pos->new_id; $log->info = $pos->new_id;
@ -1122,15 +1123,15 @@
//working in the backup/restore process. It's called from restore_decode_content_links() //working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process //function in restore process
function forum_decode_content_links_caller($restore) { function forum_decode_content_links_caller($restore) {
global $CFG, $DB; global $CFG, $DB, $DB;
$status = true; $status = true;
//Process every POST (message) in the course //Process every POST (message) in the course
if ($posts = get_records_sql ("SELECT p.id, p.message if ($posts = $DB->get_records_sql("SELECT p.id, p.message
FROM {$CFG->prefix}forum_posts p, FROM {forum_posts} p,
{$CFG->prefix}forum_discussions d {forum_discussions} d
WHERE d.course = $restore->course_id AND WHERE d.course = ? AND
p.discussion = d.id")) { p.discussion = d.id", array($restore->course_id))) {
//Iterate over each post->message //Iterate over each post->message
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($posts as $post) { foreach ($posts as $post) {
@ -1162,9 +1163,7 @@
} }
//Process every FORUM (intro) in the course //Process every FORUM (intro) in the course
if ($forums = get_records_sql ("SELECT f.id, f.intro if ($forums = $DB->get_records('forum', array('course'=>$restore->course_id), '', "id,intro")) {
FROM {$CFG->prefix}forum f
WHERE f.course = $restore->course_id")) {
//Iterate over each forum->intro //Iterate over each forum->intro
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($forums as $forum) { foreach ($forums as $forum) {
@ -1174,8 +1173,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$forum->intro = addslashes($result); $forum->intro = $result;
$status = update_record("forum",$forum); $status = $DB->update_record("forum",$forum);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';

View file

@ -591,15 +591,15 @@
//working in the backup/restore process. It's called from restore_decode_content_links() //working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process //function in restore process
function glossary_decode_content_links_caller($restore) { function glossary_decode_content_links_caller($restore) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
//Process every glossary ENTRY in the course //Process every glossary ENTRY in the course
if ($entries = get_records_sql ("SELECT e.id, e.definition if ($entries = $DB->get_records_sql("SELECT e.id, e.definition
FROM {$CFG->prefix}glossary_entries e, FROM {glossary_entries} e,
{$CFG->prefix}glossary g {glossary} g
WHERE g.course = $restore->course_id AND WHERE g.course = ? AND
e.glossaryid = g.id")) { e.glossaryid = g.id", array($restore->course_id))) {
//Iterate over each post->message //Iterate over each post->message
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($entries as $entry) { foreach ($entries as $entry) {
@ -609,8 +609,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$entry->definition = addslashes($result); $entry->definition = $result;
$status = update_record("glossary_entries",$entry); $status = $DB->update_record("glossary_entries",$entry);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@ -631,9 +631,7 @@
} }
//Process every glossary (intro) in the course //Process every glossary (intro) in the course
if ($glossarys = get_records_sql ("SELECT g.id, g.intro if ($glossarys = $DB->get_records('glossary', array('course'=>$restore->course_id), '', "id,intro")) {
FROM {$CFG->prefix}glossary g
WHERE g.course = $restore->course_id")) {
//Iterate over each glossary->intro //Iterate over each glossary->intro
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($glossarys as $glossary) { foreach ($glossarys as $glossary) {
@ -643,8 +641,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$glossary->intro = addslashes($result); $glossary->intro = $result;
$status = update_record("glossary",$glossary); $status = $DB->update_record("glossary",$glossary);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@ -670,24 +668,23 @@
//This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
//some texts in the module //some texts in the module
function glossary_restore_wiki2markdown ($restore) { function glossary_restore_wiki2markdown ($restore) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
//Convert glossary_comments->entrycomment //Convert glossary_comments->entrycomment
if ($records = get_records_sql ("SELECT c.id, c.entrycomment, c.format if ($records = $DB->get_records_sql("SELECT c.id, c.entrycomment, c.format
FROM {$CFG->prefix}glossary_comments c, FROM {glossary_comments} c,
{$CFG->prefix}glossary_entries e, {glossary_entries} e,
{$CFG->prefix}glossary g, {glossary} g,
{$CFG->prefix}backup_ids b {backup_ids} b
WHERE e.id = c.entryid AND WHERE e.id = c.entryid AND
g.id = e.glossaryid AND g.id = e.glossaryid AND
g.course = $restore->course_id AND g.course = ? AND
c.format = ".FORMAT_WIKI. " AND c.format = ".FORMAT_WIKI. " AND
b.backup_code = $restore->backup_unique_code AND b.backup_code = ? AND
b.table_name = 'glossary_comments' AND b.table_name = 'glossary_comments' AND
b.new_id = c.id")) { b.new_id = c.id", array($restore->course_id, $restore->backup_unique_code))) {
foreach ($records as $record) { foreach ($records as $record) {
//Rebuild wiki links //Rebuild wiki links
$record->entrycomment = restore_decode_wiki_content($record->entrycomment, $restore); $record->entrycomment = restore_decode_wiki_content($record->entrycomment, $restore);
@ -695,7 +692,7 @@
$wtm = new WikiToMarkdown(); $wtm = new WikiToMarkdown();
$record->entrycomment = $wtm->convert($record->entrycomment, $restore->course_id); $record->entrycomment = $wtm->convert($record->entrycomment, $restore->course_id);
$record->format = FORMAT_MARKDOWN; $record->format = FORMAT_MARKDOWN;
$status = update_record('glossary_comments', addslashes_object($record)); $status = $DB->update_record('glossary_comments', $record);
//Do some output //Do some output
$i++; $i++;
if (($i+1) % 1 == 0) { if (($i+1) % 1 == 0) {
@ -712,16 +709,16 @@
} }
//Convert glossary_entries->definition //Convert glossary_entries->definition
if ($records = get_records_sql ("SELECT e.id, e.definition, e.format if ($records = $DB->get_records_sql("SELECT e.id, e.definition, e.format
FROM {$CFG->prefix}glossary_entries e, FROM {glossary_entries} e,
{$CFG->prefix}glossary g, {glossary} g,
{$CFG->prefix}backup_ids b {backup_ids} b
WHERE g.id = e.glossaryid AND WHERE g.id = e.glossaryid AND
g.course = $restore->course_id AND g.course = ? AND
e.format = ".FORMAT_WIKI. " AND e.format = ".FORMAT_WIKI. " AND
b.backup_code = $restore->backup_unique_code AND b.backup_code = ? AND
b.table_name = 'glossary_entries' AND b.table_name = 'glossary_entries' AND
b.new_id = e.id")) { b.new_id = e.id", array($restore->course_id, $restore->backup_unique_code))) {
foreach ($records as $record) { foreach ($records as $record) {
//Rebuild wiki links //Rebuild wiki links
$record->definition = restore_decode_wiki_content($record->definition, $restore); $record->definition = restore_decode_wiki_content($record->definition, $restore);
@ -729,7 +726,7 @@
$wtm = new WikiToMarkdown(); $wtm = new WikiToMarkdown();
$record->definition = $wtm->convert($record->definition, $restore->course_id); $record->definition = $wtm->convert($record->definition, $restore->course_id);
$record->format = FORMAT_MARKDOWN; $record->format = FORMAT_MARKDOWN;
$status = update_record('glossary_entries', addslashes_object($record)); $status = $DB->update_record('glossary_entries', $record);
//Do some output //Do some output
$i++; $i++;
if (($i+1) % 1 == 0) { if (($i+1) % 1 == 0) {

View file

@ -212,6 +212,7 @@ function hotpot_restore_responses(&$restore, $status, &$xml, &$record) {
); );
} }
function hotpot_restore_details(&$restore, $status, &$xml, &$record) { function hotpot_restore_details(&$restore, $status, &$xml, &$record) {
global $DB;
// $xml is an XML tree for an attempt record // $xml is an XML tree for an attempt record
// $record is the newly added attempt record // $record is the newly added attempt record
if (empty($record->details)) { if (empty($record->details)) {
@ -220,7 +221,7 @@ function hotpot_restore_details(&$restore, $status, &$xml, &$record) {
$details = new stdClass(); $details = new stdClass();
$details->attempt = $record->id; $details->attempt = $record->id;
$details->details = $record->details; $details->details = $record->details;
if (insert_record('hotpot_details', $details)) { if ($DB->insert_record('hotpot_details', $details)) {
$status = true; $status = true;
} else { } else {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {

View file

@ -63,12 +63,10 @@
} }
function label_decode_content_links_caller($restore) { function label_decode_content_links_caller($restore) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
if ($labels = get_records_sql ("SELECT l.id, l.content if ($labels = $DB->get_records('label', array('course'=>$restore->course_id), '', "id,content")) {
FROM {$CFG->prefix}label l
WHERE l.course = $restore->course_id")) {
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($labels as $label) { foreach ($labels as $label) {
//Increment counter //Increment counter
@ -78,8 +76,8 @@
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$label->content = addslashes($result); $label->content = $result;
$status = update_record("label", $label); $status = $DB->update_record("label", $label);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';

View file

@ -274,7 +274,7 @@
// pre moodle 1.5. Matching questions need two answer fields designated // pre moodle 1.5. Matching questions need two answer fields designated
// for correct and wrong responses before the rest of the answer fields. // for correct and wrong responses before the rest of the answer fields.
if ($restore->backup_version <= 2004083124) { // Backup version for 1.4.5+ if ($restore->backup_version <= 2004083124) { // Backup version for 1.4.5+
if ($ismatching = get_record('lesson_pages', 'id', $pageid)) { // get the page we just inserted if ($ismatching = $DB->get_record('lesson_pages', array('id'=>$pageid))) { // get the page we just inserted
if ($ismatching->qtype == 5) { // check to make sure it is a matching question if ($ismatching->qtype == 5) { // check to make sure it is a matching question
$time = time(); // this may need to be changed $time = time(); // this may need to be changed
// make our 2 response answers // make our 2 response answers
@ -763,15 +763,15 @@
//working in the backup/restore process. It's called from restore_decode_content_links() //working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process //function in restore process
function lesson_decode_content_links_caller($restore) { function lesson_decode_content_links_caller($restore) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
//Process every lesson PAGE in the course //Process every lesson PAGE in the course
if ($pages = get_records_sql ("SELECT p.id, p.contents if ($pages = $DB->get_records_sql("SELECT p.id, p.contents
FROM {$CFG->prefix}lesson_pages p, FROM {lesson_pages} p,
{$CFG->prefix}lesson l {lesson} l
WHERE l.course = $restore->course_id AND WHERE l.course = ? AND
p.lessonid = l.id")) { p.lessonid = l.id", array($restore->course_id))) {
//Iterate over each page->message //Iterate over each page->message
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($pages as $page) { foreach ($pages as $page) {
@ -781,8 +781,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$page->contents = addslashes($result); $page->contents = $result;
$status = update_record("lesson_pages",$page); $status = $DB->update_record("lesson_pages",$page);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@ -803,10 +803,10 @@
} }
// Remap activity links // Remap activity links
if ($lessons = get_records_select('lesson', "activitylink != 0 AND course = $restore->course_id", '', 'id, activitylink')) { if ($lessons = $DB->get_records_select('lesson', "activitylink <> 0 AND course = ?", array($restore->course_id), '', 'id, activitylink')) {
foreach ($lessons as $lesson) { foreach ($lessons as $lesson) {
if ($newcmid = backup_getid($restore->backup_unique_code, 'course_modules', $lesson->activitylink)) { if ($newcmid = backup_getid($restore->backup_unique_code, 'course_modules', $lesson->activitylink)) {
$status = $status and set_field('lesson', 'activitylink', $newcmid->new_id, 'id', $lesson->id); $status = $status and $DB->set_field('lesson', 'activitylink', $newcmid->new_id, array('id'=>$lesson->id));
} }
} }
} }

View file

@ -554,12 +554,10 @@
//working in the backup/restore process. It's called from restore_decode_content_links() //working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process //function in restore process
function quiz_decode_content_links_caller($restore) { function quiz_decode_content_links_caller($restore) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
if ($quizs = get_records_sql ("SELECT q.id, q.intro if ($quizs = $DB->get_records('quiz', array('course'=>$restore->course_id), '', "id,intro")) {
FROM {$CFG->prefix}quiz q
WHERE q.course = $restore->course_id")) {
//Iterate over each quiz->intro //Iterate over each quiz->intro
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($quizs as $quiz) { foreach ($quizs as $quiz) {
@ -569,8 +567,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$quiz->intro = addslashes($result); $quiz->intro = $result;
$status = update_record("quiz",$quiz); $status = $DB->update_record("quiz",$quiz);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@ -596,19 +594,18 @@
//This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
//some texts in the module //some texts in the module
function quiz_restore_wiki2markdown ($restore) { function quiz_restore_wiki2markdown ($restore) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
//Convert question->questiontext //Convert question->questiontext
if ($records = get_records_sql ("SELECT q.id, q.questiontext, q.questiontextformat if ($records = $DB->get_records_sql("SELECT q.id, q.questiontext, q.questiontextformat
FROM {$CFG->prefix}question q, FROM {question} q,
{$CFG->prefix}backup_ids b {backup_ids} b
WHERE b.backup_code = $restore->backup_unique_code AND WHERE b.backup_code = ? AND
b.table_name = 'question' AND b.table_name = 'question' AND
q.id = b.new_id AND q.id = b.new_id AND
q.questiontextformat = ".FORMAT_WIKI)) { q.questiontextformat = ".FORMAT_WIKI, array($restore->backup_unique_code))) {
$i = 0; $i = 0;
foreach ($records as $record) { foreach ($records as $record) {
//Rebuild wiki links //Rebuild wiki links
@ -617,7 +614,7 @@
$wtm = new WikiToMarkdown(); $wtm = new WikiToMarkdown();
$record->questiontext = $wtm->convert($record->questiontext, $restore->course_id); $record->questiontext = $wtm->convert($record->questiontext, $restore->course_id);
$record->questiontextformat = FORMAT_MARKDOWN; $record->questiontextformat = FORMAT_MARKDOWN;
$status = update_record('question', addslashes_object($record)); $status = $DB->update_record('question', $record);
//Do some output //Do some output
$i++; $i++;
if (($i+1) % 1 == 0) { if (($i+1) % 1 == 0) {

View file

@ -200,12 +200,10 @@
//working in the backup/restore process. It's called from restore_decode_content_links() //working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process //function in restore process
function resource_decode_content_links_caller($restore) { function resource_decode_content_links_caller($restore) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
if ($resources = get_records_sql ("SELECT r.id, r.alltext, r.summary, r.reference if ($resources = $DB->get_records('resource', array('course'=>$restore->course_id), '', "id, alltext, summary, reference")) {
FROM {$CFG->prefix}resource r
WHERE r.course = $restore->course_id")) {
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($resources as $resource) { foreach ($resources as $resource) {
@ -220,10 +218,10 @@
if ($result1 != $content1 || $result2 != $content2 || $result3 != $content3) { if ($result1 != $content1 || $result2 != $content2 || $result3 != $content3) {
//Update record //Update record
$resource->alltext = addslashes($result1); $resource->alltext = $result1;
$resource->summary = addslashes($result2); $resource->summary = $result2;
$resource->reference = addslashes($result3); $resource->reference = $result3;
$status = update_record("resource",$resource); $status = $DB->update_record("resource",$resource);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content1).'<br />changed to<br />'.s($result1).'<hr /><br />'; echo '<br /><hr />'.s($content1).'<br />changed to<br />'.s($result1).'<hr /><br />';
@ -250,20 +248,19 @@
//This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
//some texts in the module //some texts in the module
function resource_restore_wiki2markdown ($restore) { function resource_restore_wiki2markdown ($restore) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
//Convert resource->alltext //Convert resource->alltext
if ($records = get_records_sql ("SELECT r.id, r.alltext, r.options if ($records = $DB->get_records_sql("SELECT r.id, r.alltext, r.options
FROM {$CFG->prefix}resource r, FROM {resource} r,
{$CFG->prefix}backup_ids b {backup_ids} b
WHERE r.course = $restore->course_id AND WHERE r.course = ? AND
options = ".FORMAT_WIKI. " AND options = ".FORMAT_WIKI. " AND
b.backup_code = $restore->backup_unique_code AND b.backup_code = ? AND
b.table_name = 'resource' AND b.table_name = 'resource' AND
b.new_id = r.id")) { b.new_id = r.id", array($restore->course_id, $restore->backup_unique_code))) {
foreach ($records as $record) { foreach ($records as $record) {
//Rebuild wiki links //Rebuild wiki links
$record->alltext = restore_decode_wiki_content($record->alltext, $restore); $record->alltext = restore_decode_wiki_content($record->alltext, $restore);
@ -271,7 +268,7 @@
$wtm = new WikiToMarkdown(); $wtm = new WikiToMarkdown();
$record->alltext = $wtm->convert($record->alltext, $restore->course_id); $record->alltext = $wtm->convert($record->alltext, $restore->course_id);
$record->options = FORMAT_MARKDOWN; $record->options = FORMAT_MARKDOWN;
$status = update_record('resource', addslashes_object($record)); $status = $DB->update_record('resource', $record);
//Do some output //Do some output
$i++; $i++;
if (($i+1) % 1 == 0) { if (($i+1) % 1 == 0) {

View file

@ -808,9 +808,7 @@
global $CFG; global $CFG;
$status = true; $status = true;
if ($scorms = get_records_sql ("SELECT s.id, s.summary if ($scorms = $DB->get_records('scorm', array('course'=>$restore->course_id), '', "id,summary")) {
FROM {$CFG->prefix}scorm s
WHERE s.course = $restore->course_id")) {
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($scorms as $scorm) { foreach ($scorms as $scorm) {
@ -821,11 +819,11 @@
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$scorm->summary = addslashes($result); $scorm->summary = $result;
$status = update_record("scorm",$scorm); $status = $DB->update_record("scorm",$scorm);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.htmlentities($content).'<br />changed to<br />'.htmlentities($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
} }
} }
} }

View file

@ -266,12 +266,10 @@
//working in the backup/restore process. It's called from restore_decode_content_links() //working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process //function in restore process
function survey_decode_content_links_caller($restore) { function survey_decode_content_links_caller($restore) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
if ($surveys = get_records_sql ("SELECT s.id, s.intro if ($surveys = $DB->get_records('survey', array('course'=>$restore->course_id), '', "id,intro")) {
FROM {$CFG->prefix}survey s
WHERE s.course = $restore->course_id")) {
//Iterate over each survey->intro //Iterate over each survey->intro
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($surveys as $survey) { foreach ($surveys as $survey) {
@ -281,8 +279,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$survey->intro = addslashes($result); $survey->intro = $result;
$status = update_record("survey",$survey); $status = $DB->update_record("survey",$survey);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';

View file

@ -339,15 +339,14 @@
//working in the backup/restore process. It's called from restore_decode_content_links() //working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process //function in restore process
function wiki_decode_content_links_caller($restore) { function wiki_decode_content_links_caller($restore) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
//Process every wiki PAGE in the course //Process every wiki PAGE in the course
if ($pages = get_records_sql ("SELECT p.id, p.content if ($pages = $DB->get_records_sql("SELECT p.id, p.content
FROM {$CFG->prefix}wiki_pages p, FROM {wiki_pages} p, {wiki} w
{$CFG->prefix}wiki w WHERE w.course = ? AND
WHERE w.course = $restore->course_id AND p.wiki = w.id", array($restore->course_id))) {
p.wiki = w.id")) {
//Iterate over each post->message //Iterate over each post->message
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($pages as $page) { foreach ($pages as $page) {
@ -357,8 +356,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$page->content = addslashes($result); $page->content = $result;
$status = update_record("wiki_pages",$page); $status = $DB->update_record("wiki_pages",$page);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@ -379,9 +378,7 @@
} }
//Process every wiki (summary) in the course //Process every wiki (summary) in the course
if ($wikis = get_records_sql ("SELECT w.id, w.summary if ($wikis = $DB->get_records('wiki', array('course'=>$restore->course_id), '', "id,summary")) {
FROM {$CFG->prefix}wiki w
WHERE w.course = $restore->course_id")) {
//Iterate over each wiki->summary //Iterate over each wiki->summary
$i = 0; //Counter to send some output to the browser to avoid timeouts $i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($wikis as $wiki) { foreach ($wikis as $wiki) {
@ -391,8 +388,8 @@
$result = restore_decode_content_links_worker($content,$restore); $result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) { if ($result != $content) {
//Update record //Update record
$wiki->summary = addslashes($result); $wiki->summary = $result;
$status = update_record("wiki",$wiki); $status = $DB->update_record("wiki",$wiki);
if (debugging()) { if (debugging()) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />'; echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';

View file

@ -94,6 +94,8 @@
* @return object best context instance for this category to be in * @return object best context instance for this category to be in
*/ */
function restore_question_get_best_category_context($restore, $contextinfo) { function restore_question_get_best_category_context($restore, $contextinfo) {
global $DB;
switch ($contextinfo['LEVEL'][0]['#']) { switch ($contextinfo['LEVEL'][0]['#']) {
case 'module': case 'module':
if (!$instanceinfo = backup_getid($restore->backup_unique_code, 'course_modules', $contextinfo['INSTANCE'][0]['#'])){ if (!$instanceinfo = backup_getid($restore->backup_unique_code, 'course_modules', $contextinfo['INSTANCE'][0]['#'])){
@ -109,9 +111,9 @@
//search COURSECATEGORYLEVEL steps up the course cat tree or //search COURSECATEGORYLEVEL steps up the course cat tree or
//to the top of the tree if steps are exhausted. //to the top of the tree if steps are exhausted.
$catno = $contextinfo['COURSECATEGORYLEVEL'][0]['#']; $catno = $contextinfo['COURSECATEGORYLEVEL'][0]['#'];
$catid = get_field('course', 'category', 'id', $restore->course_id); $catid = $DB->get_field('course', 'category', array('id'=>$restore->course_id));
while ($catno > 1){ while ($catno > 1){
$nextcatid = get_field('course_categories', 'parent', 'id', $catid); $nextcatid = $DB->get_field('course_categories', 'parent', array('id'=>$catid));
if ($nextcatid == 0){ if ($nextcatid == 0){
break; break;
} }
@ -192,7 +194,7 @@
} }
$question_cat->contextid = $tocontext->id; $question_cat->contextid = $tocontext->id;
if (!$fcat = $DB->get_record('question_categories', array('contextid'=>$question_cat->contextid, 'stamp'=>$question_cat->stamp))) { if (!$fcat = $DB->get_record('question_categories', array('contextid'=>$question_cat->contextid, 'stamp'=>$question_cat->stamp))) {
$question_cat->id = insert_record ("question_categories", $question_cat); $question_cat->id = $DB->insert_record ("question_categories", $question_cat);
} else { } else {
$question_cat = $fcat; $question_cat = $fcat;
} }
@ -231,17 +233,17 @@
} }
function restore_recode_category_parents($restore){ function restore_recode_category_parents($restore){
global $CFG; global $CFG, $DB;
$status = true; $status = true;
//Now we have to recode the parent field of each restored category //Now we have to recode the parent field of each restored category
$categories = get_records_sql("SELECT old_id, new_id $categories = $DB->get_records_sql("SELECT old_id, new_id
FROM {$CFG->prefix}backup_ids FROM {backup_ids}
WHERE backup_code = $restore->backup_unique_code AND WHERE backup_code = ? AND
table_name = 'question_categories'"); table_name = 'question_categories'", array($restore->backup_unique_code));
if ($categories) { if ($categories) {
//recode all parents to point at their old parent cats no matter what context the parent is now in //recode all parents to point at their old parent cats no matter what context the parent is now in
foreach ($categories as $category) { foreach ($categories as $category) {
$restoredcategory = get_record('question_categories','id',$category->new_id); $restoredcategory = $DB->get_record('question_categories', array('id'=>$category->new_id));
if ($restoredcategory && $restoredcategory->parent != 0) { if ($restoredcategory && $restoredcategory->parent != 0) {
$updateobj = new object(); $updateobj = new object();
$updateobj->id = $restoredcategory->id; $updateobj->id = $restoredcategory->id;
@ -251,7 +253,7 @@
} else { } else {
$updateobj->parent = 0; $updateobj->parent = 0;
} }
$status = $status && update_record('question_categories', $updateobj); $status = $status && $DB->update_record('question_categories', $updateobj);
} }
} }
//now we have recoded all parents, check through all parents and set parent to be //now we have recoded all parents, check through all parents and set parent to be
@ -259,11 +261,11 @@
//or else set parent to 0 (top level category). //or else set parent to 0 (top level category).
$toupdate = array(); $toupdate = array();
foreach ($categories as $category) { foreach ($categories as $category) {
$restoredcategory = get_record('question_categories','id',$category->new_id); $restoredcategory = $DB->get_record('question_categories', array('id'=>$category->new_id));
if ($restoredcategory && $restoredcategory->parent != 0) { if ($restoredcategory && $restoredcategory->parent != 0) {
$nextparentid = $restoredcategory->parent; $nextparentid = $restoredcategory->parent;
do { do {
if (!$parent = get_record('question_categories', 'id', $nextparentid)){ if (!$parent = $DB->get_record('question_categories', array('id'=>$nextparentid))) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo 'Could not find parent for question category '. $category->id.' recoding as top category item.<br />'; echo 'Could not find parent for question category '. $category->id.' recoding as top category item.<br />';
} }
@ -289,7 +291,7 @@
$updateobj = new object(); $updateobj = new object();
$updateobj->id = $id; $updateobj->id = $id;
$updateobj->parent = $parent; $updateobj->parent = $parent;
$status = $status && update_record('question_categories', $updateobj); $status = $status && $DB->update_record('question_categories', $updateobj);
} }
} }
return $status; return $status;
@ -376,7 +378,7 @@
} }
$question->category = $course_question_cat->id; $question->category = $course_question_cat->id;
//does question already exist in course cat //does question already exist in course cat
$existingquestion = get_record ("question", "category", $question->category, "stamp", $question->stamp, "version", $question->version); $existingquestion = $DB->get_record("question", array("category"=>$question->category, "stamp"=>$question->stamp, "version"=>$question->version));
} else { } else {
//permissions ok, restore to best cat //permissions ok, restore to best cat
$question->category = $best_question_cat->id; $question->category = $best_question_cat->id;
@ -919,7 +921,7 @@
* @return boolean whether the operation succeeded. * @return boolean whether the operation succeeded.
*/ */
function question_decode_content_links_caller($restore) { function question_decode_content_links_caller($restore) {
global $CFG, $QTYPES; global $CFG, $QTYPES, $DB;
$status = true; $status = true;
$i = 1; //Counter to send some output to the browser to avoid timeouts $i = 1; //Counter to send some output to the browser to avoid timeouts
@ -935,7 +937,7 @@
$coursemodulecontexts = array(); $coursemodulecontexts = array();
$context = get_context_instance(CONTEXT_COURSE, $restore->course_id); $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
$coursemodulecontexts[] = $context->id; $coursemodulecontexts[] = $context->id;
$cms = get_records('course_modules', 'course', $restore->course_id, '', 'id'); $cms = $DB->get_records('course_modules', array('course'=>$restore->course_id), '', 'id');
if ($cms){ if ($cms){
foreach ($cms as $cm){ foreach ($cms as $cm){
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
@ -944,19 +946,18 @@
} }
$coursemodulecontextslist = join($coursemodulecontexts, ','); $coursemodulecontextslist = join($coursemodulecontexts, ',');
// Decode links in questions. // Decode links in questions.
if ($questions = get_records_sql('SELECT q.id, q.qtype, q.questiontext, q.generalfeedback '. if ($questions = $DB->get_records_sql('SELECT q.id, q.qtype, q.questiontext, q.generalfeedback
'FROM ' . $CFG->prefix . 'question q, '. FROM {question} q, {question_categories} qc
$CFG->prefix . 'question_categories qc '. WHERE q.category = qc.id
'WHERE q.category = qc.id '. AND qc.contextid IN (' .$coursemodulecontextslist.')')) {
'AND qc.contextid IN (' .$coursemodulecontextslist.')')) {
foreach ($questions as $question) { foreach ($questions as $question) {
$questiontext = restore_decode_content_links_worker($question->questiontext, $restore); $questiontext = restore_decode_content_links_worker($question->questiontext, $restore);
$generalfeedback = restore_decode_content_links_worker($question->generalfeedback, $restore); $generalfeedback = restore_decode_content_links_worker($question->generalfeedback, $restore);
if ($questiontext != $question->questiontext || $generalfeedback != $question->generalfeedback) { if ($questiontext != $question->questiontext || $generalfeedback != $question->generalfeedback) {
$question->questiontext = addslashes($questiontext); $question->questiontext = $questiontext;
$question->generalfeedback = addslashes($generalfeedback); $question->generalfeedback = $generalfeedback;
if (!update_record('question', $question)) { if (!$DB->update_record('question', $question)) {
$status = false; $status = false;
} }
} }
@ -981,13 +982,11 @@
} }
// Decode links in answers. // Decode links in answers.
if ($answers = get_records_sql('SELECT qa.id, qa.answer, qa.feedback, q.qtype if ($answers = $DB->get_records_sql('SELECT qa.id, qa.answer, qa.feedback, q.qtype
FROM ' . $CFG->prefix . 'question_answers qa, FROM {question_answers} qa, {question} q, {question_categories} qc
' . $CFG->prefix . 'question q, WHERE qa.question = q.id
' . $CFG->prefix . 'question_categories qc AND q.category = qc.id
WHERE qa.question = q.id AND qc.contextid IN ('.$coursemodulecontextslist.')')) {
AND q.category = qc.id '.
'AND qc.contextid IN ('.$coursemodulecontextslist.')')) {
foreach ($answers as $answer) { foreach ($answers as $answer) {
$feedback = restore_decode_content_links_worker($answer->feedback, $restore); $feedback = restore_decode_content_links_worker($answer->feedback, $restore);
@ -998,9 +997,9 @@
} }
if ($feedback != $answer->feedback || $answertext != $answer->answer) { if ($feedback != $answer->feedback || $answertext != $answer->answer) {
unset($answer->qtype); unset($answer->qtype);
$answer->feedback = addslashes($feedback); $answer->feedback = $feedback;
$answer->answer = addslashes($answertext); $answer->answer = $answertext;
if (!update_record('question_answers', $answer)) { if (!$DB->update_record('question_answers', $answer)) {
$status = false; $status = false;
} }
} }