diff --git a/backup/lib.php b/backup/lib.php
index fac9292c9cf..aba4ad23ea2 100644
--- a/backup/lib.php
+++ b/backup/lib.php
@@ -534,14 +534,11 @@
//This function is used to add slashes (and decode from UTF-8 if needed)
//It's used intensivelly when restoring modules and saving them in db
- function backup_todb ($data, $addslashes=true) {
+ function backup_todb ($data) {
// MDL-10770
if ($data === '$@NULL@$') {
return null;
} else {
- if ($addslashes) {
- $data = addslashes($data);
- }
return restore_decode_absolute_links($data);
}
}
diff --git a/backup/restorelib.php b/backup/restorelib.php
index ffa44717126..d09b305848e 100644
--- a/backup/restorelib.php
+++ b/backup/restorelib.php
@@ -85,7 +85,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//from backup format to destination site/course in order to mantain inter-activities
//working in the backup/restore process
function restore_decode_content_links($restore) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -117,7 +117,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
echo '
'.get_string ('from').' '.get_string('blocks');
}
- if ($blocks = get_records('block', 'visible', 1)) {
+ if ($blocks = $DB->get_records('block', array('visible'=>1))) {
foreach ($blocks as $block) {
if ($blockobject = block_instance($block->name)) {
$blockobject->decode_content_links_caller($restore);
@@ -150,6 +150,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//its task is to ask all modules (maybe other linkable objects) to restore
//links to them.
function restore_decode_content_links_worker($content,$restore) {
+ global $DB;
+
foreach($restore->mods as $name => $info) {
$function_name = $name."_decode_content_links";
if (function_exists($function_name)) {
@@ -161,7 +163,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
static $blockobjects = null;
if (!isset($blockobjects)) {
$blockobjects = array();
- if ($blocks = get_records('block', 'visible', 1)) {
+ if ($blocks = $DB->get_records('block', array('visible'=>1))) {
foreach ($blocks as $block) {
if ($blockobject = block_instance($block->name)) {
$blockobjects[] = $blockobject;
@@ -211,7 +213,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//return it with every link to modules " modulename:moduleid"
//converted if possible. See the space before modulename!!
function restore_decode_wiki_content($content,$restore) {
-
global $CFG;
$result = $content;
@@ -603,8 +604,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function create a new course record.
//When finished, course_header contains the id of the new course
function restore_create_new_course($restore,&$course_header) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -625,8 +625,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$currentfullname = $fullname.$suffixfull;
// Limit the size of shortname - database column accepts <= 100 chars
$currentshortname = substr($shortname, 0, 100 - strlen($suffixshort)).$suffixshort;
- $coursefull = get_record("course","fullname",addslashes($currentfullname));
- $courseshort = get_record("course","shortname",addslashes($currentshortname));
+ $coursefull = $DB->get_record("course", array("fullname"=>$currentfullname));
+ $courseshort = $DB->get_record("course", array("shortname"=>$currentshortname));
$counter++;
} while ($coursefull || $courseshort);
@@ -636,36 +636,36 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// first try to get it from restore
if ($restore->restore_restorecatto) {
- $category = get_record('course_categories', 'id', $restore->restore_restorecatto);
+ $category = $DB->get_record('course_categories', array('id'=>$restore->restore_restorecatto));
}
// else we try to get it from the xml file
//Now calculate the category
if (!$category) {
- $category = get_record("course_categories","id",$course_header->category->id,
- "name",addslashes($course_header->category->name));
+ $category = $DB->get_record("course_categories",array("id"=>$course_header->category->id,
+ "name"=>$course_header->category->name));
}
//If no exists, try by name only
if (!$category) {
- $category = get_record("course_categories","name",addslashes($course_header->category->name));
+ $category = $DB->get_record("course_categories", array("name"=>$course_header->category->name));
}
//If no exists, get category id 1
if (!$category) {
- $category = get_record("course_categories","id","1");
+ $category = $DB->get_record("course_categories", array("id"=>"1"));
}
//If category 1 doesn'exists, lets create the course category (get it from backup file)
if (!$category) {
$ins_category = new object();
- $ins_category->name = addslashes($course_header->category->name);
+ $ins_category->name = $course_header->category->name;
$ins_category->parent = 0;
$ins_category->sortorder = 0;
$ins_category->coursecount = 0;
$ins_category->visible = 0; //To avoid interferences with the rest of the site
$ins_category->timemodified = time();
- $newid = insert_record("course_categories",$ins_category);
+ $newid = $DB->insert_record("course_categories",$ins_category);
$category->id = $newid;
$category->name = $course_header->category->name;
}
@@ -683,64 +683,64 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Create the course_object
if ($status) {
$course = new object();
- $course->category = addslashes($course_header->category->id);
- $course->password = addslashes($course_header->course_password);
- $course->fullname = addslashes($course_header->course_fullname);
- $course->shortname = addslashes($course_header->course_shortname);
- $course->idnumber = addslashes($course_header->course_idnumber);
+ $course->category = $course_header->category->id;
+ $course->password = $course_header->course_password;
+ $course->fullname = $course_header->course_fullname;
+ $course->shortname = $course_header->course_shortname;
+ $course->idnumber = $course_header->course_idnumber;
$course->idnumber = ''; //addslashes($course_header->course_idnumber); // we don't want this at all.
$course->summary = backup_todb($course_header->course_summary);
- $course->format = addslashes($course_header->course_format);
- $course->showgrades = addslashes($course_header->course_showgrades);
- $course->newsitems = addslashes($course_header->course_newsitems);
- $course->teacher = addslashes($course_header->course_teacher);
- $course->teachers = addslashes($course_header->course_teachers);
- $course->student = addslashes($course_header->course_student);
- $course->students = addslashes($course_header->course_students);
- $course->guest = addslashes($course_header->course_guest);
- $course->startdate = addslashes($course_header->course_startdate);
+ $course->format = $course_header->course_format;
+ $course->showgrades = $course_header->course_showgrades;
+ $course->newsitems = $course_header->course_newsitems;
+ $course->teacher = $course_header->course_teacher;
+ $course->teachers = $course_header->course_teachers;
+ $course->student = $course_header->course_student;
+ $course->students = $course_header->course_students;
+ $course->guest = $course_header->course_guest;
+ $course->startdate = $course_header->course_startdate;
$course->startdate += $restore->course_startdateoffset;
- $course->numsections = addslashes($course_header->course_numsections);
+ $course->numsections = $course_header->course_numsections;
//$course->showrecent = addslashes($course_header->course_showrecent); INFO: This is out in 1.3
- $course->maxbytes = addslashes($course_header->course_maxbytes);
- $course->showreports = addslashes($course_header->course_showreports);
+ $course->maxbytes = $course_header->course_maxbytes;
+ $course->showreports = $course_header->course_showreports;
if (isset($course_header->course_groupmode)) {
- $course->groupmode = addslashes($course_header->course_groupmode);
+ $course->groupmode = $course_header->course_groupmode;
}
if (isset($course_header->course_groupmodeforce)) {
- $course->groupmodeforce = addslashes($course_header->course_groupmodeforce);
+ $course->groupmodeforce = $course_header->course_groupmodeforce;
}
if (isset($course_header->course_defaultgroupingid)) {
//keep the original now - convert after groupings restored
- $course->defaultgroupingid = addslashes($course_header->course_defaultgroupingid);
+ $course->defaultgroupingid = $course_header->course_defaultgroupingid;
}
- $course->lang = addslashes($course_header->course_lang);
- $course->theme = addslashes($course_header->course_theme);
- $course->cost = addslashes($course_header->course_cost);
- $course->currency = isset($course_header->course_currency)?addslashes($course_header->course_currency):'';
- $course->marker = addslashes($course_header->course_marker);
- $course->visible = addslashes($course_header->course_visible);
- $course->hiddensections = addslashes($course_header->course_hiddensections);
- $course->timecreated = addslashes($course_header->course_timecreated);
- $course->timemodified = addslashes($course_header->course_timemodified);
- $course->metacourse = addslashes($course_header->course_metacourse);
- $course->expirynotify = isset($course_header->course_expirynotify) ? addslashes($course_header->course_expirynotify):0;
- $course->notifystudents = isset($course_header->course_notifystudents) ? addslashes($course_header->course_notifystudents) : 0;
- $course->expirythreshold = isset($course_header->course_expirythreshold) ? addslashes($course_header->course_expirythreshold) : 0;
- $course->enrollable = isset($course_header->course_enrollable) ? addslashes($course_header->course_enrollable) : 1;
- $course->enrolstartdate = isset($course_header->course_enrolstartdate) ? addslashes($course_header->course_enrolstartdate) : 0;
+ $course->lang = $course_header->course_lang;
+ $course->theme = $course_header->course_theme;
+ $course->cost = $course_header->course_cost;
+ $course->currency = isset($course_header->course_currency)?$course_header->course_currency:'';
+ $course->marker = $course_header->course_marker;
+ $course->visible = $course_header->course_visible;
+ $course->hiddensections = $course_header->course_hiddensections;
+ $course->timecreated = $course_header->course_timecreated;
+ $course->timemodified = $course_header->course_timemodified;
+ $course->metacourse = $course_header->course_metacourse;
+ $course->expirynotify = isset($course_header->course_expirynotify) ? $course_header->course_expirynotify:0;
+ $course->notifystudents = isset($course_header->course_notifystudents) ? $course_header->course_notifystudents : 0;
+ $course->expirythreshold = isset($course_header->course_expirythreshold) ? $course_header->course_expirythreshold : 0;
+ $course->enrollable = isset($course_header->course_enrollable) ? $course_header->course_enrollable : 1;
+ $course->enrolstartdate = isset($course_header->course_enrolstartdate) ? $course_header->course_enrolstartdate : 0;
if ($course->enrolstartdate) { //Roll course dates
$course->enrolstartdate += $restore->course_startdateoffset;
}
- $course->enrolenddate = isset($course_header->course_enrolenddate) ? addslashes($course_header->course_enrolenddate) : 0;
+ $course->enrolenddate = isset($course_header->course_enrolenddate) ? $course_header->course_enrolenddate : 0;
if ($course->enrolenddate) { //Roll course dates
$course->enrolenddate += $restore->course_startdateoffset;
}
- $course->enrolperiod = addslashes($course_header->course_enrolperiod);
+ $course->enrolperiod = $course_header->course_enrolperiod;
//Calculate sortorder field
- $sortmax = get_record_sql('SELECT MAX(sortorder) AS max
- FROM ' . $CFG->prefix . 'course
- WHERE category=' . $course->category);
+ $sortmax = $DB->get_record_sql('SELECT MAX(sortorder) AS max
+ FROM {course}
+ WHERE category=?', array($course->category));
if (!empty($sortmax->max)) {
$course->sortorder = $sortmax->max + 1;
unset($sortmax);
@@ -765,7 +765,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
//Now insert the record
- $newid = insert_record("course",$course);
+ $newid = $DB->insert_record("course",$course);
if ($newid) {
//save old and new course id
backup_putid ($restore->backup_unique_code,"course",$course_header->course_id,$newid);
@@ -785,10 +785,10 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//It calls selectively to restore_create_block_instances() for 1.5
//and above backups. Upwards compatible with old blocks.
function restore_create_blocks($restore, $backup_block_format, $blockinfo, $xml_file) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
- delete_records('block_instance', 'pageid', $restore->course_id, 'pagetype', PAGE_COURSE_VIEW);
+ $DB->delete_records('block_instance', array('pageid'=>$restore->course_id, 'pagetype'=>PAGE_COURSE_VIEW));
if (empty($backup_block_format)) { // This is a backup from Moodle < 1.5
if (empty($blockinfo)) {
// Looks like it's from Moodle < 1.3. Let's give the course default blocks...
@@ -796,7 +796,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
blocks_repopulate_page($newpage);
} else if (!empty($CFG->showblocksonmodpages)) {
// We just have a blockinfo field, this is a legacy 1.4 or 1.3 backup
- $blockrecords = get_records_select('block', '', '', 'name, id');
+ $blockrecords = $DB->get_records('block', null, '', 'name, id');
$temp_blocks_l = array();
$temp_blocks_r = array();
@list($temp_blocks_l, $temp_blocks_r) = explode(':', $blockinfo);
@@ -821,7 +821,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$blockinstance->pagetype = PAGE_COURSE_VIEW;
$blockinstance->position = $blockposition;
$blockinstance->weight = $blockweight;
- if(!$status = insert_record('block_instance', $blockinstance)) {
+ if(!$status = $DB->insert_record('block_instance', $blockinstance)) {
$status = false;
}
++$blockweight;
@@ -839,7 +839,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the block_instances from xml when restoring in a
//new course
function restore_create_block_instances($restore,$xml_file) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
@@ -901,7 +901,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$pageinstances[$instance->pagetype][$instance->pageid][] = $instance;
}
- $blocks = get_records_select('block', 'visible = 1', '', 'name, id, multiple');
+ $blocks = $DB->get_records('block', array('visible'=>1), '', 'name, id, multiple');
// For each type of page we have restored
foreach($pageinstances as $thistypeinstances) {
@@ -940,14 +940,14 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$instance->blockid = $blocks[$instance->name]->id;
// This will only be set if we come from 1.7 and above backups
- // Also, must do this before insert (insert_record unsets id)
+ // Also, must do this before insert ($DB->insert_record unsets id)
if (!empty($instance->id)) {
$oldid = $instance->id;
} else {
$oldid = 0;
}
- if ($instance->id = insert_record('block_instance', $instance)) {
+ if ($instance->id = $DB->insert_record('block_instance', $instance)) {
// Create block instance
if (!$blockobj = block_instance($instance->name, $instance)) {
$status = false;
@@ -996,8 +996,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//when restoring in a new course or simply checks sections and create records
//in backup_ids when restoring in a existing course
function restore_create_sections(&$restore, $xml_file) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
@@ -1026,16 +1025,16 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$newid = 0;
if ($restore->restoreto == 2) {
//Save it to db (only if restoring to new course)
- $newid = insert_record("course_sections",$section);
+ $newid = $DB->insert_record("course_sections",$section);
} else {
//Get section id when restoring in existing course
- $rec = get_record("course_sections","course",$restore->course_id,
- "section",$section->section);
+ $rec = $DB->get_record("course_sections", array("course"=>$restore->course_id,
+ "section"=>$section->section));
//If that section doesn't exist, get section 0 (every mod will be
//asigned there
if(!$rec) {
- $rec = get_record("course_sections","course",$restore->course_id,
- "section","0");
+ $rec = $DB->get_record("course_sections", array("course"=>$restore->course_id,
+ "section"=>"0"));
}
//New check. If section 0 doesn't exist, insert it here !!
//Teorically this never should happen but, in practice, some users
@@ -1046,7 +1045,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$zero_sec->section = 0;
$zero_sec->summary = "";
$zero_sec->sequence = "";
- $newid = insert_record("course_sections",$zero_sec);
+ $newid = $DB->insert_record("course_sections",$zero_sec);
$rec->id = $newid;
$rec->sequence = "";
}
@@ -1090,7 +1089,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
&& !empty($restore->mods[$mod->type]->instances[$mod->instance]->restore))) {
//Get the module id from modules
- $module = get_record("modules","name",$mod->type);
+ $module = $DB->get_record("modules", array("name"=>$mod->type));
if ($module) {
$course_module = new object();
$course_module->course = $restore->course_id;
@@ -1118,7 +1117,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
}
- $newidmod = insert_record("course_modules", addslashes_recursive($course_module));
+ $newidmod = $DB->insert_record("course_modules", $course_module);
if ($newidmod) {
//save old and new module id
//In the info field, we save the original instance of the module
@@ -1152,7 +1151,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$update_rec = new object();
$update_rec->id = $newid;
$update_rec->sequence = $sequence;
- $status = update_record("course_sections",$update_rec);
+ $status = $DB->update_record("course_sections",$update_rec);
}
}
}
@@ -1164,7 +1163,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Called to set up any course-format specific data that may be in the file
function restore_set_format_data($restore,$xml_file) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
@@ -1178,7 +1177,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Process format data if there is any
if (isset($info->format_data)) {
- if(!$format=get_field('course','format','id',$restore->course_id)) {
+ if(!$format=$DB->get_field('course','format', array('id'=>$restore->course_id))) {
return false;
}
// If there was any data then it must have a restore method
@@ -1201,8 +1200,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the metacourse data from xml, notifying
//about each incidence
function restore_create_metacourse($restore,$xml_file) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
@@ -1226,19 +1224,19 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//(by id in the same server or by idnumber and shortname in other server)
if ($restore->original_wwwroot == $CFG->wwwroot) {
//Same server, lets see by id
- $dbcourse = get_record('course','id',$child->id);
+ $dbcourse = $DB->get_record('course', array('id'=>$child->id));
} else {
//Different server, lets see by idnumber and shortname, and only ONE record
- $dbcount = count_records('course','idnumber',$child->idnumber,'shortname',$child->shortname);
+ $dbcount = $DB->count_records('course', array('idnumber'=>$child->idnumber, 'shortname'=>$child->shortname));
if ($dbcount == 1) {
- $dbcourse = get_record('course','idnumber',$child->idnumber,'shortname',$child->shortname);
+ $dbcourse = $DB->get_record('course', array('idnumber'=>$child->idnumber, 'shortname'=>$child->shortname));
}
}
//If child course has been found, insert data
if ($dbcourse) {
$dbmetacourse->child_course = $dbcourse->id;
$dbmetacourse->parent_course = $restore->course_id;
- $status = insert_record ('course_meta',$dbmetacourse);
+ $status = $DB->insert_record('course_meta',$dbmetacourse);
} else {
//Child course not found, notice!
if (!defined('RESTORE_SILENTLY')) {
@@ -1258,12 +1256,12 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//(by id in the same server or by idnumber and shortname in other server)
if ($restore->original_wwwroot == $CFG->wwwroot) {
//Same server, lets see by id
- $dbcourse = get_record('course','id',$parent->id);
+ $dbcourse = $DB->get_record('course', array('id'=>$parent->id));
} else {
//Different server, lets see by idnumber and shortname, and only ONE record
- $dbcount = count_records('course','idnumber',$parent->idnumber,'shortname',$parent->shortname);
+ $dbcount = $DB->count_records('course', array('idnumber'=>$parent->idnumber, 'shortname'=>$parent->shortname));
if ($dbcount == 1) {
- $dbcourse = get_record('course','idnumber',$parent->idnumber,'shortname',$parent->shortname);
+ $dbcourse = $DB->get_record('course', array('idnumber'=>$parent->idnumber, 'shortname'=>$parent->shortname));
}
}
//If parent course has been found, insert data if it is a metacourse
@@ -1271,7 +1269,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if ($dbcourse->metacourse) {
$dbmetacourse->parent_course = $dbcourse->id;
$dbmetacourse->child_course = $restore->course_id;
- $status = insert_record ('course_meta',$dbmetacourse);
+ $status = $DB->insert_record ('course_meta',$dbmetacourse);
//Now, recreate student enrolments in parent course
sync_metacourse($dbcourse->id);
} else {
@@ -1297,7 +1295,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
* This function migrades all the pre 1.9 gradebook data from xml
*/
function restore_migrate_old_gradebook($restore,$xml_file) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
@@ -1352,12 +1350,12 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
/// Process letters
$context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
// respect current grade letters if defined
- if ($status and $restoreall and !record_exists('grade_letters', 'contextid', $context->id)) {
+ if ($status and $restoreall and !$DB->record_exists('grade_letters', array('contextid'=>$context->id))) {
if (!defined('RESTORE_SILENTLY')) {
echo ''.get_string('gradeletters','grades').'';
}
// Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'grade_letter' AND backup_code = $restore->backup_unique_code",
+ $recs = $DB->get_records("backup_ids", array("table_name"=>'grade_letter', "backup_code"=>$restore->backup_unique_code),
"",
"old_id");
if ($recs) {
@@ -1370,7 +1368,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->contextid = $context->id;
$dbrec->lowerboundary = backup_todb($info['GRADE_LETTER']['#']['GRADE_LOW']['0']['#']);
$dbrec->letter = backup_todb($info['GRADE_LETTER']['#']['LETTER']['0']['#']);
- insert_record('grade_letters', $dbrec);
+ $DB->insert_record('grade_letters', $dbrec);
}
}
}
@@ -1380,7 +1378,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
echo ''.get_string('categories','grades').'';
}
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'grade_category' AND backup_code = $restore->backup_unique_code",
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'grade_category', 'backup_code'=>$restore->backup_unique_code),
"old_id",
"old_id");
$cat_count = count($recs);
@@ -1482,7 +1480,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
* This function creates all the gradebook data from xml
*/
function restore_create_gradebook($restore,$xml_file) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
@@ -1531,7 +1529,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
unset($prev_grade_cats);
if ($restoreall) {
- if ($recs = get_records_select("backup_ids","table_name = 'grade_items' AND backup_code = $restore->backup_unique_code", "", "old_id")) {
+ if ($recs = $DB->get_records("backup_ids", array('table_name'=>'grade_items', 'backup_code'=>$restore->backup_unique_code), "", "old_id")) {
foreach ($recs as $rec) {
if ($data = backup_getid($restore->backup_unique_code,'grade_items',$rec->old_id)) {
@@ -1575,7 +1573,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
echo ''.get_string('gradeletters','grades').'';
}
// Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'grade_letters' AND backup_code = $restore->backup_unique_code",
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'grade_letters', 'backup_code'=>$restore->backup_unique_code),
"",
"old_id");
if ($recs) {
@@ -1588,7 +1586,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->contextid = $context->id;
$dbrec->lowerboundary = backup_todb($info['GRADE_LETTER']['#']['LOWERBOUNDARY']['0']['#']);
$dbrec->letter = backup_todb($info['GRADE_LETTER']['#']['LETTER']['0']['#']);
- insert_record('grade_letters', $dbrec);
+ $DB->insert_record('grade_letters', $dbrec);
}
}
}
@@ -1599,7 +1597,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if (!defined('RESTORE_SILENTLY')) {
echo ''.get_string('gradeoutcomes','grades').'';
}
- $recs = get_records_select("backup_ids","table_name = 'grade_outcomes' AND backup_code = '$restore->backup_unique_code'",
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'grade_outcomes', 'backup_code'=>$restore->backup_unique_code),
"",
"old_id");
if ($recs) {
@@ -1612,11 +1610,11 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//first find out if outcome already exists
$shortname = backup_todb($info['GRADE_OUTCOME']['#']['SHORTNAME']['0']['#']);
- if ($candidates = get_records_sql("SELECT *
- FROM {$CFG->prefix}grade_outcomes
- WHERE (courseid IS NULL OR courseid = $restore->course_id)
- AND shortname = '$shortname'
- ORDER BY courseid ASC, id ASC")) {
+ if ($candidates = $DB->get_records_sql("SELECT *
+ FROM {grade_outcomes}
+ WHERE (courseid IS NULL OR courseid = ?)
+ AND shortname = ?
+ ORDER BY courseid ASC, id ASC", array($restore->course_id, $shortname))) {
$grade_outcome = reset($candidates);
$outcomes[$rec->old_id] = $grade_outcome;
continue;
@@ -1672,7 +1670,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'grade_items' AND backup_code = '$restore->backup_unique_code'",
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'grade_items', 'backup_code'=>$restore->backup_unique_code),
"id", // restore in the backup order
"old_id");
@@ -1939,10 +1937,10 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if ($status and !$importing and $restore_histories) {
/// following code is very inefficient
- $gchcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_categories_history');
- $gghcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_grades_history');
- $gihcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_items_history');
- $gohcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_outcomes_history');
+ $gchcount = $DB->count_records('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'grade_categories_history'));
+ $gghcount = $DB->count_records('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'grade_grades_history'));
+ $gihcount = $DB->count_records('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'grade_items_history'));
+ $gohcount = $DB->count_records('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'grade_outcomes_history'));
// Number of records to get in every chunk
$recordset_size = 2;
@@ -1955,7 +1953,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
while ($counter < $gchcount) {
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'grade_categories_history' AND backup_code = '$restore->backup_unique_code'",
+ $recs = $DB->get_records("backup_ids",array('table_name'=>'grade_categories_history', 'backup_code'=>$restore->backup_unique_code),
"old_id",
"old_id",
$counter,
@@ -2024,7 +2022,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->aggregatesubcats = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATESUBCATS']['0']['#']);
$dbrec->courseid = $restore->course_id;
- insert_record('grade_categories_history', $dbrec);
+ $DB->insert_record('grade_categories_history', $dbrec);
unset($dbrec);
}
@@ -2053,7 +2051,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
while ($counter < $gghcount) {
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'grade_grades_history' AND backup_code = '$restore->backup_unique_code'",
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'grade_grades_history', 'backup_code'=>$restore->backup_unique_code),
"old_id",
"old_id",
$counter,
@@ -2115,7 +2113,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->information = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATION']['0']['#']);
$dbrec->informationformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATIONFORMAT']['0']['#']);
- insert_record('grade_grades_history', $dbrec);
+ $DB->insert_record('grade_grades_history', $dbrec);
unset($dbrec);
}
@@ -2145,7 +2143,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
while ($counter < $gihcount) {
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'grade_items_history' AND backup_code = '$restore->backup_unique_code'",
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'grade_items_history', 'backup_code'=>$restore->backup_unique_code),
"old_id",
"old_id",
$counter,
@@ -2222,7 +2220,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// find the course category with depth 1, and course id = current course id
// this would have been already restored
- $cat = get_record('grade_categories', 'depth', 1, 'courseid', $restore->course_id);
+ $cat = $DB->get_record('grade_categories', array('depth'=>1, 'courseid'=>$restore->course_id));
$dbrec->iteminstance = $cat->id;
} else {
@@ -2258,7 +2256,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->locktime = backup_todb($info['GRADE_ITEM_HISTORY']['#']['LOCKTIME']['0']['#']);
$dbrec->needsupdate = backup_todb($info['GRADE_ITEM_HISTORY']['#']['NEEDSUPDATE']['0']['#']);
- insert_record('grade_items_history', $dbrec);
+ $DB->insert_record('grade_items_history', $dbrec);
unset($dbrec);
}
@@ -2287,7 +2285,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
while ($counter < $gohcount) {
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'grade_outcomes_history' AND backup_code = '$restore->backup_unique_code'",
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'grade_outcomes_history', 'backup_code'=>$restore->backup_unique_code),
"old_id",
"old_id",
$counter,
@@ -2323,7 +2321,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->scaleid = $oldobj->new_id;
$dbrec->description = backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['DESCRIPTION']['0']['#']);
- insert_record('grade_outcomes_history', $dbrec);
+ $DB->insert_record('grade_outcomes_history', $dbrec);
unset($dbrec);
}
@@ -2355,8 +2353,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the user, user_students, user_teachers
//user_course_creators and user_admins from xml
function restore_create_users($restore,$xml_file) {
-
- global $CFG;
+ global $CFG, $DB;
require_once ($CFG->dirroot.'/tag/lib.php');
$status = true;
@@ -2377,7 +2374,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if (!empty($info->users)) {
/// Grab mnethosts keyed by wwwroot, to map to id
- $mnethosts = get_records('mnet_host', '', '',
+ $mnethosts = $DB->get_records('mnet_host', null,
'wwwroot', 'wwwroot, id');
/// Get languages for quick search later
@@ -2454,8 +2451,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$newid=null;
//check if it exists (by username) and get its id
$user_exists = true;
- $user_data = get_record("user","username",addslashes($user->username),
- 'mnethostid', $user->mnethostid);
+ $user_data = $DB->get_record("user", array("username"=>$user->username,
+ 'mnethostid'=>$user->mnethostid));
if (!$user_data) {
$user_exists = false;
} else {
@@ -2532,7 +2529,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//We are going to create the user
//The structure is exactly as we need
- $newid = insert_record ("user", addslashes_recursive($user));
+ $newid = $DB->insert_record("user", $user);
//Put the new id
$status = backup_putid($restore->backup_unique_code,"user",$userid,$newid,"new");
}
@@ -2648,7 +2645,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
if (!$is_course_user) {
//If the record (user) doesn't exists
- if (!record_exists("user","id",$newid)) {
+ if (!$DB->record_exists("user", array("id"=>$newid))) {
//Put status in backup_ids
$currinfo = $currinfo."user,";
$status = backup_putid($restore->backup_unique_code,"user",$userid,$newid,$currinfo);
@@ -2662,13 +2659,13 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
foreach($user->user_custom_profile_fields as $udata) {
/// If the profile field has data and the profile shortname-datatype is defined in server
if ($udata->field_data) {
- if ($field = get_record('user_info_field', 'shortname', $udata->field_name, 'datatype', $udata->field_type)) {
+ if ($field = $DB->get_record('user_info_field', array('shortname'=>$udata->field_name, 'datatype'=>$udata->field_type))) {
/// Insert the user_custom_profile_field
$rec = new object();
$rec->userid = $newid;
$rec->fieldid = $field->id;
$rec->data = $udata->field_data;
- insert_record('user_info_data', $rec);
+ $DB->insert_record('user_info_data', $rec);
}
}
}
@@ -2692,10 +2689,10 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if (isset($user->user_preferences)) {
foreach($user->user_preferences as $user_preference) {
//We check if that user_preference exists in DB
- if (!record_exists("user_preferences","userid",$newid,"name",$user_preference->name)) {
+ if (!$DB->record_exists("user_preferences", array("userid"=>$newid, "name"=>$user_preference->name))) {
//Prepare the record and insert it
$user_preference->userid = $newid;
- $status = insert_record("user_preferences",$user_preference);
+ $status = $DB->insert_record("user_preferences",$user_preference);
}
}
}
@@ -2720,8 +2717,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the structures messages and contacts
function restore_create_messages($restore,$xml_file) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
@@ -2738,9 +2734,9 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//If we have info, then process messages & contacts
if ($info > 0) {
//Count how many we have
- $unreadcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'message');
- $readcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'message_read');
- $contactcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'message_contacts');
+ $unreadcount = $DB->count_records ('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'message'));
+ $readcount = $DB->count_records ('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'message_read'));
+ $contactcount = $DB->count_records ('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'message_contacts'));
if ($unreadcount || $readcount || $contactcount) {
//Start ul
if (!defined('RESTORE_SILENTLY')) {
@@ -2757,7 +2753,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
while ($counter < $unreadcount) {
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'message' AND backup_code = '$restore->backup_unique_code'","old_id","old_id",$counter,$recordset_size);
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'message', 'backup_code'=>$restore->backup_unique_code),"old_id","old_id",$counter,$recordset_size);
if ($recs) {
foreach ($recs as $rec) {
//Get the full record from backup_ids
@@ -2789,12 +2785,12 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->useridto = $user->new_id;
}
//Check if the record doesn't exist in DB!
- $exist = get_record('message','useridfrom',$dbrec->useridfrom,
- 'useridto', $dbrec->useridto,
- 'timecreated',$dbrec->timecreated);
+ $exist = $DB->get_record('message', array('useridfrom'=>$dbrec->useridfrom,
+ 'useridto'=>$dbrec->useridto,
+ 'timecreated'=>$dbrec->timecreated));
if (!$exist) {
//Not exist. Insert
- $status = insert_record('message',$dbrec);
+ $status = $DB->insert_record('message',$dbrec);
} else {
//Duplicate. Do nothing
}
@@ -2823,7 +2819,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
while ($counter < $readcount) {
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'message_read' AND backup_code = '$restore->backup_unique_code'","old_id","old_id",$counter,$recordset_size);
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'message_read', 'backup_code'=>$restore->backup_unique_code),"old_id","old_id",$counter,$recordset_size);
if ($recs) {
foreach ($recs as $rec) {
//Get the full record from backup_ids
@@ -2856,12 +2852,12 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->useridto = $user->new_id;
}
//Check if the record doesn't exist in DB!
- $exist = get_record('message_read','useridfrom',$dbrec->useridfrom,
- 'useridto', $dbrec->useridto,
- 'timecreated',$dbrec->timecreated);
+ $exist = $DB->get_record('message_read', array('useridfrom'=>$dbrec->useridfrom,
+ 'useridto'=>$dbrec->useridto,
+ 'timecreated'=>$dbrec->timecreated));
if (!$exist) {
//Not exist. Insert
- $status = insert_record('message_read',$dbrec);
+ $status = $DB->insert_record('message_read',$dbrec);
} else {
//Duplicate. Do nothing
}
@@ -2890,7 +2886,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
while ($counter < $contactcount) {
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'message_contacts' AND backup_code = '$restore->backup_unique_code'","old_id","old_id",$counter,$recordset_size);
+ $recs = $DB->get_records("backup_ids", array('table_name'=>'message_contacts', 'backup_code'=>$restore->backup_unique_code),"old_id","old_id",$counter,$recordset_size);
if ($recs) {
foreach ($recs as $rec) {
//Get the full record from backup_ids
@@ -2918,11 +2914,11 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->contactid = $user->new_id;
}
//Check if the record doesn't exist in DB!
- $exist = get_record('message_contacts','userid',$dbrec->userid,
- 'contactid', $dbrec->contactid);
+ $exist = $DB->get_record('message_contacts', array('userid'=>$dbrec->userid,
+ 'contactid'=>$dbrec->contactid));
if (!$exist) {
//Not exist. Insert
- $status = insert_record('message_contacts',$dbrec);
+ $status = $DB->insert_record('message_contacts',$dbrec);
} else {
//Duplicate. Do nothing
}
@@ -2955,8 +2951,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the structures for blogs and blog tags
function restore_create_blogs($restore,$xml_file) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
@@ -2972,7 +2967,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//If we have info, then process blogs & blog_tags
if ($info > 0) {
//Count how many we have
- $blogcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'blog');
+ $blogcount = $DB->count_records('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'blog'));
if ($blogcount) {
//Number of records to get in every chunk
$recordset_size = 4;
@@ -2982,7 +2977,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
while ($counter < $blogcount) {
//Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'blog' AND backup_code = '$restore->backup_unique_code'","old_id","old_id",$counter,$recordset_size);
+ $recs = $DB->get_records("backup_ids", array("table_name"=>'blog', 'backup_code'=>$restore->backup_unique_code),"old_id","old_id",$counter,$recordset_size);
if ($recs) {
foreach ($recs as $rec) {
//Get the full record from backup_ids
@@ -3021,13 +3016,13 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
//Check if the record doesn't exist in DB!
- $exist = get_record('post','userid', $dbrec->userid,
- 'subject', $dbrec->subject,
- 'created', $dbrec->created);
+ $exist = $DB->get_record('post', array('userid'=>$dbrec->userid,
+ 'subject'=>$dbrec->subject,
+ 'created'=>$dbrec->created));
$newblogid = 0;
if (!$exist) {
//Not exist. Insert
- $newblogid = insert_record('post',$dbrec);
+ $newblogid = $DB->insert_record('post',$dbrec);
}
//Going to restore related tags. Check they are enabled and we have inserted a blog
@@ -3077,7 +3072,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the categories and questions
//from xml
function restore_create_questions($restore,$xml_file) {
-
global $CFG;
$status = true;
@@ -3105,8 +3099,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the scales
function restore_create_scales($restore,$xml_file) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
@@ -3157,11 +3150,9 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$course_to_search = $restore->course_id;
}
- // scale is not course unique, use get_record_sql to suppress warning
+ // scale is not course unique
- $sca_db = get_record_sql("SELECT * FROM {$CFG->prefix}scale
- WHERE scale = '$sca->scale'
- AND courseid = $course_to_search", true);
+ $sca_db = $DB->get_records('scale', array('scale'=>$sca->scale, 'courseid'=>$course_to_search), true);
//If it doesn't exist, create
if (!$sca_db) {
@@ -3182,7 +3173,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$sca->userid = $adminid;
}
//The structure is equal to the db, so insert the scale
- $newid = insert_record ("scale",$sca);
+ $newid = $DB->insert_record ("scale",$sca);
} else {
//get current scale id
$newid = $sca_db->id;
@@ -3231,8 +3222,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the groups
function restore_create_groups($restore,$xml_file) {
-
- global $CFG;
+ global $CFG, $DB;
//Check it exists
if (!file_exists($xml_file)) {
@@ -3280,18 +3270,19 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//restore->course_id course
//Going to compare LOB columns so, use the cross-db sql_compare_text() in both sides.
$description_clause = '';
+ $params = array('courseid'=>$restore->course_id, 'grname'=>$gro->name);
if (!empty($gro->description)) { /// Only for groups having a description
- $literal_description = "'" . $gro->description . "'";
$description_clause = " AND " .
- sql_compare_text('description') . " = " .
- sql_compare_text($literal_description);
+ $DB->sql_compare_text('description') . " = " .
+ $DB->sql_compare_text(':desc');
+ $params['desc'] = $gro->description;
}
- if (!$gro_db = get_record_sql("SELECT *
- FROM {$CFG->prefix}groups
- WHERE courseid = $restore->course_id AND
- name = '{$gro->name}'" . $description_clause, true)) {
+ if (!$gro_db = $DB->get_record_sql("SELECT *
+ FROM {groups}
+ WHERE courseid = :courseid AND
+ name = :grname $description_clause", $params, true)) {
//If it doesn't exist, create
- $newid = insert_record('groups', $gro);
+ $newid = $DB->insert_record('groups', $gro);
} else {
//get current group id
@@ -3327,6 +3318,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function restores the groups_members
function restore_create_groups_members($group_id,$info,$restore) {
+ global $DB;
if (! isset($info['GROUP']['#']['MEMBERS']['0']['#']['MEMBER'])) {
//OK, some groups have no members.
@@ -3361,7 +3353,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$group_member->userid = $user->new_id;
//The structure is equal to the db, so insert the groups_members
- if (!insert_record ("groups_members", $group_member)) {
+ if (!$DB->insert_record ("groups_members", $group_member)) {
$status = false;
continue;
}
@@ -3383,6 +3375,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the groupings
function restore_create_groupings($restore,$xml_file) {
+ global $DB;
//Check it exists
if (!file_exists($xml_file)) {
@@ -3413,13 +3406,13 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$gro->timecreated = backup_todb($info['GROUPING']['#']['TIMECREATED']['0']['#']);
//Now search if that group exists (by name and description field) in
- if ($gro_db = get_record('groupings', 'courseid', $restore->course_id, 'name', $gro->name, 'description', $gro->description)) {
+ if ($gro_db = $DB->get_record('groupings', array('courseid'=>$restore->course_id, 'name'=>$gro->name, 'description'=>$gro->description))) {
//get current group id
$newid = $gro_db->id;
} else {
//The structure is equal to the db, so insert the grouping
- if (!$newid = insert_record('groupings', $gro)) {
+ if (!$newid = $DB->insert_record('groupings', $gro)) {
$status = false;
continue;
}
@@ -3433,12 +3426,12 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// now fix the defaultgroupingid in course
- $course = get_record('course', 'id', $restore->course_id);
+ $course = $DB->get_record('course', array('id'=>$restore->course_id));
if ($course->defaultgroupingid) {
if ($grouping = restore_grouping_getid($restore, $course->defaultgroupingid)) {
- set_field('course', 'defaultgroupingid', $grouping->new_id, 'id', $course->id);
+ $DB->set_field('course', 'defaultgroupingid', $grouping->new_id, array('id'=>$course->id));
} else {
- set_field('course', 'defaultgroupingid', 0, 'id', $course->id);
+ $DB->set_field('course', 'defaultgroupingid', 0, array('id'=>$course->id));
}
}
@@ -3447,6 +3440,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the groupingsgroups
function restore_create_groupings_groups($restore,$xml_file) {
+ global $DB;
//Check it exists
if (!file_exists($xml_file)) {
@@ -3485,8 +3479,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$gro_member->groupid = $group->new_id;
$gro_member->groupingid = $grouping->new_id;
- if (!get_record('groupings_groups', 'groupid', $gro_member->groupid, 'groupingid', $gro_member->groupingid)) {
- if (!insert_record('groupings_groups', $gro_member)) {
+ if (!$DB->get_record('groupings_groups', array('groupid'=>$gro_member->groupid, 'groupingid'=>$gro_member->groupingid))) {
+ if (!$DB->insert_record('groupings_groups', $gro_member)) {
$status = false;
}
}
@@ -3498,6 +3492,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the course events
function restore_create_events($restore,$xml_file) {
+ global $DB;
global $CFG;
@@ -3561,8 +3556,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Now search if that event exists (by name, description, timestart fields) in
//restore->course_id course
- $eve_db = get_record_select("event",
- "courseid={$eve->courseid} AND name='{$eve->name}' AND description='{$eve->description}' AND timestart=$eve->timestart");
+ $eve_db = $DB->get_records("event",
+ array('courseid'=>$eve->courseid, 'name'=>$eve->name, 'description'=>$eve->description, 'timestart'=>$eve->timestart));
//If it doesn't exist, create
if (!$eve_db) {
$create_event = true;
@@ -3589,7 +3584,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
//The structure is equal to the db, so insert the event
- $newid = insert_record ("event",$eve);
+ $newid = $DB->insert_record ("event",$eve);
//We must recode the repeatid if the event has it
//The repeatid now refers to the id of the original event. (see Bug#5956)
@@ -3604,7 +3599,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
$eve->id = $newid;
// update the record to contain the correct repeatid
- update_record('event',$eve);
+ $DB->update_record('event',$eve);
}
} else {
//get current event id
@@ -3633,8 +3628,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//step in the restore execution, because we need to have it
//finished to know all the oldid, newid equivaleces
function restore_decode_absolute_links($content) {
-
- global $CFG,$restore;
+ global $CFG, $restore;
/// MDL-14072: Prevent NULLs, empties and numbers to be processed by the
/// heavy interlinking. Just a few cpu cycles saved.
@@ -3743,8 +3737,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function restores the groupfiles from the temp (group_files) directory to the
//dataroot/groups directory
function restore_group_files($restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -3766,9 +3759,9 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0;
foreach ($list as $dir) {
//Look for dir like groupid in backup_ids
- $data = get_record ("backup_ids","backup_code",$restore->backup_unique_code,
- "table_name","groups",
- "old_id",$dir);
+ $data = $DB->get_record ("backup_ids", array("backup_code"=>$restore->backup_unique_code,
+ "table_name"=>"groups",
+ "old_id"=>$dir));
//If that group exists in backup_ids
if ($data) {
if (!file_exists($dest_dir."/".$data->new_id)) {
@@ -3800,7 +3793,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function restores the course files from the temp (course_files) directory to the
//dataroot/course_id directory
function restore_course_files($restore) {
-
global $CFG;
$status = true;
@@ -3853,7 +3845,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function restores the site files from the temp (site_files) directory to the
//dataroot/SITEID directory
function restore_site_files($restore) {
-
global $CFG;
$status = true;
@@ -3907,8 +3898,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the structures for every module in backup file
//Depending what has been selected.
function restore_create_modules($restore,$xml_file) {
-
global $CFG;
+
$status = true;
//Check it exists
if (!file_exists($xml_file)) {
@@ -3956,8 +3947,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function creates all the structures for every log in backup file
//Depending what has been selected.
function restore_create_logs($restore,$xml_file) {
-
- global $CFG;
+ global $CFG, $DB;
//Number of records to get in every chunk
$recordset_size = 4;
@@ -3988,7 +3978,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
while ($counter < $count_logs) {
//Get a chunk of records
//Take old_id twice to avoid adodb limitation
- $logs = get_records_select("backup_ids","table_name = 'log' AND backup_code = '$restore->backup_unique_code'","old_id","old_id",$counter,$recordset_size);
+ $logs = $DB->get_records("backup_ids", array("table_name"=>'log', 'backup_code'=>$restore->backup_unique_code),"old_id","old_id",$counter,$recordset_size);
//We have logs
if ($logs) {
//Iterate
@@ -4067,6 +4057,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function inserts a course log record, calculating the URL field as necessary
function restore_log_course($restore,$log) {
+ global $DB;
$status = true;
$toinsert = false;
@@ -4222,13 +4213,14 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Now if $toinsert is set, insert the record
if ($toinsert) {
//echo "Inserting record
"; //Debug
- $status = insert_record("log",$log);
+ $status = $DB->insert_record("log",$log);
}
return $status;
}
//This function inserts a user log record, calculating the URL field as necessary
function restore_log_user($restore,$log) {
+ global $DB;
$status = true;
$toinsert = false;
@@ -4301,13 +4293,14 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Now if $toinsert is set, insert the record
if ($toinsert) {
//echo "Inserting record
"; //Debug
- $status = insert_record("log",$log);
+ $status = $DB->insert_record("log",$log);
}
return $status;
}
//This function inserts a module log record, calculating the URL field as necessary
function restore_log_module($restore,$log) {
+ global $DB;
$status = true;
$toinsert = false;
@@ -4332,7 +4325,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Now if $toinsert is set, insert the record
if ($toinsert) {
//echo "Inserting record
"; //Debug
- $status = insert_record("log",$log);
+ $status = $DB->insert_record("log",$log);
}
return $status;
}
@@ -4340,25 +4333,24 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//This function adjusts the instance field into course_modules. It's executed after
//modules restore. There, we KNOW the new instance id !!
function restore_check_instances($restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//We are going to iterate over each course_module saved in backup_ids
- $course_modules = get_records_sql("SELECT old_id,new_id
- FROM {$CFG->prefix}backup_ids
- WHERE backup_code = '$restore->backup_unique_code' AND
- table_name = 'course_modules'");
+ $course_modules = $DB->get_records_sql("SELECT old_id,new_id
+ FROM {backup_ids}
+ WHERE backup_code = ? AND
+ table_name = 'course_modules'", array($restore->backup_unique_code));
if ($course_modules) {
foreach($course_modules as $cm) {
//Get full record, using backup_getids
$cm_module = backup_getid($restore->backup_unique_code,"course_modules",$cm->old_id);
//Now we are going to the REAL course_modules to get its type (field module)
- $module = get_record("course_modules","id",$cm_module->new_id);
+ $module = $DB->get_record("course_modules", array("id"=>$cm_module->new_id));
if ($module) {
//We know the module type id. Get the name from modules
- $type = get_record("modules","id",$module->module);
+ $type = $DB->get_record("modules", array("id"=>$module->module));
if ($type) {
//We know the type name and the old_id. Get its new_id
//from backup_ids. It's the instance !!!
@@ -4367,7 +4359,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//We have the new instance, so update the record in course_modules
$module->instance = $instance->new_id;
//print_object ($module); //Debug
- $status = update_record("course_modules",$module);
+ $status = $DB->update_record("course_modules",$module);
} else {
$status = false;
}
@@ -7361,12 +7353,12 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
function restore_setup_for_check(&$restore,$backup_unique_code) {
- global $SESSION;
+ global $SESSION, $DB;
$restore->backup_unique_code=$backup_unique_code;
$restore->users = 2; // yuk
$restore->course_files = $SESSION->restore->restore_course_files;
$restore->site_files = $SESSION->restore->restore_site_files;
- if ($allmods = get_records("modules")) {
+ if ($allmods = $DB->get_records("modules")) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$var = "restore_".$modname;
@@ -7418,13 +7410,13 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
function restore_execute(&$restore,$info,$course_header,&$errorstr) {
+ global $CFG, $USER, $DB;
- global $CFG, $USER;
$status = true;
//Checks for the required files/functions to restore every module
//and include them
- if ($allmods = get_records("modules") ) {
+ if ($allmods = $DB->get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = "$CFG->dirroot/mod/$modname/restorelib.php";
@@ -7484,7 +7476,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
} else {
- $course = get_record("course","id",$restore->course_id);
+ $course = $DB->get_record("course", array("id"=>$restore->course_id));
if ($course) {
if (!defined('RESTORE_SILENTLY')) {
echo "".get_string("usingexistingcourse");
@@ -7545,9 +7537,9 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Now print info about the work done
if ($status) {
- $recs = get_records_sql("select old_id, new_id from {$CFG->prefix}backup_ids
- where backup_code = '$restore->backup_unique_code' and
- table_name = 'user'");
+ $recs = $DB->get_records_sql("select old_id, new_id from {backup_ids}
+ where backup_code = ? and
+ table_name = 'user'", array($restore->backup_unique_code));
//We've records
if ($recs) {
$new_count = 0;
@@ -8116,7 +8108,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
echo "".get_string("checkingcourse");
}
//categories table
- $course = get_record("course","id",$restore->course_id);
+ $course = $DB->get_record("course", array("id"=>$restore->course_id));
fix_course_sortorder();
// Check if the user has course update capability in the newly restored course
// there is no need to load his capabilities again, because restore_roles_settings
@@ -8185,7 +8177,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
//Create, open and write header of the html log file
function restore_open_html($restore,$course_header) {
-
global $CFG;
$status = true;
@@ -8229,7 +8220,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
}
//Create & close footer of the html log file
function restore_close_html($restore) {
-
global $CFG;
$status = true;
@@ -8269,6 +8259,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
* It isn't now, just overwriting
*/
function restore_create_roles($restore, $xmlfile) {
+ global $DB;
if (!defined('RESTORE_SILENTLY')) {
echo "".get_string("creatingrolesdefinitions").'';
}
@@ -8323,8 +8314,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$currentfullname = $fullname.$suffixfull;
// Limit the size of shortname - database column accepts <= 100 chars
$currentshortname = substr($shortname, 0, 100 - strlen($suffixshort)).$suffixshort;
- $coursefull = get_record("role","name",addslashes($currentfullname));
- $courseshort = get_record("role","shortname",addslashes($currentshortname));
+ $coursefull = $DB->get_record("role", array("name"=>$currentfullname));
+ $courseshort = $DB->get_record("role", array("shortname"=>$currentshortname));
$counter++;
} while ($coursefull || $courseshort);
@@ -8333,7 +8324,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// done finding a unique name
- $newroleid = create_role(addslashes($roledata->name),addslashes($roledata->shortname),'');
+ $newroleid = create_role($roledata->name, $roledata->shortname, '');
$status = backup_putid($restore->backup_unique_code,"role",$oldroleid,
$newroleid); // adding a new id
foreach ($roledata->capabilities as $capability) {
@@ -8344,7 +8335,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$roleinfo->capability = $capability->name;
$roleinfo->roleid = $newroleid;
- insert_record('role_capabilities', $roleinfo);
+ $DB->insert_record('role_capabilities', $roleinfo);
}
}
/// Now, restore role nameincourse
@@ -8356,9 +8347,9 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$rolename = new object();
$rolename->roleid = $newrole->new_id;
$rolename->contextid = $coursecontext->id;
- $rolename->name = addslashes($roledata->nameincourse);
+ $rolename->name = $roledata->nameincourse;
- insert_record('role_names', $rolename);
+ $DB->insert_record('role_names', $rolename);
}
}
}
diff --git a/mod/assignment/restorelib.php b/mod/assignment/restorelib.php
index 4aae4665e49..af89d2c9bf0 100644
--- a/mod/assignment/restorelib.php
+++ b/mod/assignment/restorelib.php
@@ -23,8 +23,7 @@
//This function executes all the restore procedure about this mod
function assignment_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -87,17 +86,17 @@
if (!in_array($assignment->assignmenttype, $plugins)) {
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","assignment")." \"".format_string(stripslashes($assignment->name),true)."\" - plugin '{$assignment->assignmenttype}' not available!";
+ echo "".get_string("modulename","assignment")." \"".format_string($assignment->name,true)."\" - plugin '{$assignment->assignmenttype}' not available!";
}
return true; // do not fail the restore
}
//The structure is equal to the db, so insert the assignment
- $newid = insert_record ("assignment",$assignment);
+ $newid = $DB->insert_record ("assignment",$assignment);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","assignment")." \"".format_string(stripslashes($assignment->name),true)."\"";
+ echo "".get_string("modulename","assignment")." \"".format_string($assignment->name,true)."\"";
}
backup_flush(300);
@@ -122,8 +121,7 @@
//This function restores the assignment_submissions
function assignment_submissions_restore_mods($old_assignment_id, $new_assignment_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -177,7 +175,7 @@
}
//The structure is equal to the db, so insert the assignment_submission
- $newid = insert_record ("assignment_submissions",$submission);
+ $newid = $DB->insert_record ("assignment_submissions",$submission);
//Do some output
if (($i+1) % 50 == 0) {
diff --git a/mod/chat/restorelib.php b/mod/chat/restorelib.php
index 883ff4289b9..f3429a4503b 100644
--- a/mod/chat/restorelib.php
+++ b/mod/chat/restorelib.php
@@ -23,8 +23,7 @@
//This function executes all the restore procedure about this mod
function chat_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -53,11 +52,11 @@
$chat->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
//The structure is equal to the db, so insert the chat
- $newid = insert_record ("chat",$chat);
+ $newid = $db->insert_record ("chat",$chat);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","chat")." \"".format_string(stripslashes($chat->name),true)."\"";
+ echo "".get_string("modulename","chat")." \"".format_string($chat->name,true)."\"";
}
backup_flush(300);
@@ -82,8 +81,7 @@
//This function restores the chat_messages
function chat_messages_restore_mods($old_chat_id, $new_chat_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -123,7 +121,7 @@
}
//The structure is equal to the db, so insert the chat_message
- $newid = insert_record ("chat_messages",$message);
+ $newid = $DB->insert_record ("chat_messages",$message);
//Do some output
if (($i+1) % 50 == 0) {
@@ -250,7 +248,6 @@
//This function returns a log record with all the necessay transformations
//done. It's used by restore_log_module() to restore modules log.
function chat_restore_logs($restore,$log) {
-
$status = false;
//Depending of the action, we recode different things
diff --git a/mod/choice/restorelib.php b/mod/choice/restorelib.php
index 44a6d4a7d8c..9974c8ab346 100644
--- a/mod/choice/restorelib.php
+++ b/mod/choice/restorelib.php
@@ -28,8 +28,7 @@
//This function executes all the restore procedure about this mod
function choice_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -84,7 +83,7 @@
}
}
//The structure is equal to the db, so insert the choice
- $newid = insert_record ("choice",$choice);
+ $newid = $DB->insert_record ("choice",$choice);
if ($newid) {
//We have the newid, update backup_ids
@@ -114,7 +113,7 @@
$option->choiceid = $newid;
$option->text = $options[$i];
$option->timemodified = $choice->timemodified;
- $newoptionid = insert_record ("choice_options",$option);
+ $newoptionid = $DB->insert_record ("choice_options",$option);
//Save this choice_option to backup_ids
backup_putid($restore->backup_unique_code,"choice_options",$i,$newoptionid);
}
@@ -134,7 +133,7 @@
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","choice")." \"".format_string(stripslashes($choice->name),true)."\"";
+ echo "".get_string("modulename","choice")." \"".format_string($choice->name,true)."\"";
}
backup_flush(300);
diff --git a/mod/data/restorelib.php b/mod/data/restorelib.php
index 9d0b7e1e6b8..63dd62b7c19 100644
--- a/mod/data/restorelib.php
+++ b/mod/data/restorelib.php
@@ -37,8 +37,7 @@ $fieldids = array(); //array in the format of $fieldids[$oldid]=$newid. This
//Return a content encoded to support interactivities linking. Every module
function data_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -100,11 +99,11 @@ function data_restore_mods($mod,$restore) {
unset($database->notification); /// Unset it if null to get proper Moodle 2.0 default (0) applied
}
- $newid = insert_record ('data', $database);
+ $newid = $DB->insert_record ('data', $database);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","data")." \"".format_string(stripslashes($database->name),true)."\"";
+ echo "".get_string("modulename","data")." \"".format_string($database->name,true)."\"";
}
if ($newid) {
@@ -161,8 +160,7 @@ function data_restore_mods($mod,$restore) {
}
function data_fields_restore_mods ($old_data_id, $new_data_id, $info, $restore) {
-
- global $CFG, $fieldids;
+ global $CFG, $fieldids, $DB;
$fields = $info['MOD']['#']['FIELDS']['0']['#']['FIELD'];
@@ -187,7 +185,7 @@ function data_fields_restore_mods ($old_data_id, $new_data_id, $info, $restore)
$field -> param9 = backup_todb($fie_info['#']['PARAM9']['0']['#']);
$field -> param10 = backup_todb($fie_info['#']['PARAM10']['0']['#']);
- $newid = insert_record ("data_fields",$field);
+ $newid = $DB->insert_record ("data_fields",$field);
$fieldids[$oldid] = $newid; //so we can use them in sub tables that depends on both fieldid and recordid
@@ -215,8 +213,7 @@ function data_fields_restore_mods ($old_data_id, $new_data_id, $info, $restore)
}
function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore) {
-
- global $CFG, $fieldids;
+ global $CFG, $fieldids, $DB;
$status = true;
@@ -244,7 +241,7 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore)
$record->groupid= $group->new_id;
}
- $newid = insert_record ("data_records",$record);
+ $newid = $DB->insert_record ("data_records",$record);
//Do some output
if (($i+1) % 50 == 0) {
@@ -273,8 +270,7 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore)
}
function data_content_restore_mods ($old_record_id, $new_record_id, $old_data_id, $new_data_id, $recinfo, $restore) {
-
- global $CFG, $fieldids;
+ global $CFG, $fieldids, $DB;
$status = true;
@@ -294,7 +290,7 @@ function data_content_restore_mods ($old_record_id, $new_record_id, $old_data_id
$content -> content2 = backup_todb($con_info['#']['CONTENT2']['0']['#']);
$content -> content3 = backup_todb($con_info['#']['CONTENT3']['0']['#']);
$content -> content4 = backup_todb($con_info['#']['CONTENT4']['0']['#']);
- $newid = insert_record ("data_content",$content);
+ $newid = $DB->insert_record ("data_content",$content);
//Do some output
if (($i+1) % 50 == 0) {
@@ -374,8 +370,7 @@ function data_restore_files ($old_data_id, $new_data_id, $old_field_id, $new_fie
}
function data_ratings_restore_mods ($oldid, $newid, $info, $rec_info) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -392,7 +387,7 @@ function data_ratings_restore_mods ($oldid, $newid, $info, $rec_info) {
$rating -> userid = backup_todb($rat_info['#']['USERID']['0']['#']);
$rating -> rating = backup_todb($rat_info['#']['RATING']['0']['#']);
- if (! insert_record ("data_ratings",$rating)) {
+ if (! $DB->insert_record ("data_ratings",$rating)) {
$status = false;
}
}
@@ -400,8 +395,7 @@ function data_ratings_restore_mods ($oldid, $newid, $info, $rec_info) {
}
function data_comments_restore_mods ($oldid, $newid, $info, $rec_info) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -420,7 +414,7 @@ function data_comments_restore_mods ($oldid, $newid, $info, $rec_info) {
$comment -> content = backup_todb($com_info['#']['CONTENT']['0']['#']);
$comment -> created = backup_todb($com_info['#']['CREATED']['0']['#']);
$comment -> modified = backup_todb($com_info['#']['MODIFIED']['0']['#']);
- if (! insert_record ("data_comments",$comment)) {
+ if (! $DB->insert_record ("data_comments",$comment)) {
$status = false;
}
diff --git a/mod/feedback/restorelib.php b/mod/feedback/restorelib.php
index 6b8b00adf7c..279aa1dee46 100644
--- a/mod/feedback/restorelib.php
+++ b/mod/feedback/restorelib.php
@@ -29,8 +29,7 @@
define('FEEDBACK_MULTICHOICERESTORE_TYPE_SEP', '>>>>>');
function feedback_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
// $allValues = array();
// $allTrackings = array();
@@ -63,7 +62,7 @@
$feedback->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
//The structure is equal to the db, so insert the feedback
- $newid = insert_record ("feedback",$feedback);
+ $newid = $DB->insert_record ("feedback",$feedback);
//create events
// the open-event
@@ -178,7 +177,7 @@
$item->position = backup_todb($item_info['#']['POSITION']['0']['#']);
$item->required = backup_todb($item_info['#']['REQUIRED']['0']['#']);
//put this new item into the database
- $newitemid = insert_record('feedback_item', $item);
+ $newitemid = $DB->insert_record('feedback_item', $item);
//Now check if want to restore user data and do it.
if ($restore_userdata) {
@@ -192,10 +191,10 @@
$value->completed = 0;
$value->tmp_completed = backup_todb($value_info['#']['COMPLETED']['0']['#']);
$value->value = backup_todb($value_info['#']['VAL']['0']['#']);
- $value->value = addslashes($value->value);
+ $value->value = $value->value;
$value->course_id = backup_todb($value_info['#']['COURSE_ID']['0']['#']);
//put this new value into the database
- $newvalueid = insert_record('feedback_value', $value);
+ $newvalueid = $DB->insert_record('feedback_value', $value);
$value->id = $newvalueid;
// $allValues[] = $value;
}
@@ -224,7 +223,7 @@
}
//save the tracking
- $newtrackingid = insert_record('feedback_tracking', $tracking);
+ $newtrackingid = $DB->insert_record('feedback_tracking', $tracking);
$tracking->id = $newtrackingid;
// $allTrackings[] = $tracking;
}
@@ -255,25 +254,25 @@
$oldcompletedid = backup_todb($completed_info['#']['ID']['0']['#']);
//save the completed
- $newcompletedid = insert_record('feedback_completed', $completed);
+ $newcompletedid = $DB->insert_record('feedback_completed', $completed);
//the newcompletedid have to be changed at every values
- $tochangevals = get_records('feedback_value', 'tmp_completed', $oldcompletedid);
+ $tochangevals = $DB->get_records('feedback_value', array('tmp_completed'=>$oldcompletedid));
if($tochangevals) {
foreach($tochangevals as $tmpVal) {
$tmpVal->completed = $newcompletedid;
$tmpVal->tmp_completed = 0;
- update_record('feedback_value', $tmpVal);
+ $DB->update_record('feedback_value', $tmpVal);
}
}
//the newcompletedid have to be changed at every tracking
- $tochangetracks = get_records('feedback_tracking', 'completed', $oldcompletedid);
+ $tochangetracks = $DB->get_records('feedback_tracking', array('completed'=>$oldcompletedid));
if($tochangetracks) {
foreach($tochangetracks as $tmpTrack) {
$tmpTrack->completed = $newcompletedid;
$tmpTrack->tmp_completed = 0;
- update_record('feedback_tracking', $tmpTrack);
+ $DB->update_record('feedback_tracking', $tmpTrack);
}
}
}
diff --git a/mod/forum/restorelib.php b/mod/forum/restorelib.php
index 4494baa21cf..b7665c7dc9b 100644
--- a/mod/forum/restorelib.php
+++ b/mod/forum/restorelib.php
@@ -33,8 +33,7 @@
//-----------------------------------------------------------
function forum_restore_mods($mod,$restore) {
-
- global $CFG,$DB;
+ global $CFG, $DB;
$status = true;
@@ -91,7 +90,7 @@
}
}
- $newid = insert_record("forum", $forum);
+ $newid = $DB->insert_record("forum", $forum);
//Do some output
@@ -124,7 +123,7 @@
// If forum type is single, just recreate the initial discussion/post automatically
// if it hasn't been created still (because no user data was selected on backup or
// restore.
- if ($forum->type == 'single' && !record_exists('forum_discussions', 'forum', $newid)) {
+ if ($forum->type == 'single' && !$DB->record_exists('forum_discussions', array('forum'=>$newid))) {
//Load forum/lib.php
require_once ($CFG->dirroot.'/mod/forum/lib.php');
// Calculate the default format
@@ -146,7 +145,7 @@
$sdid = forum_add_discussion($sd, $sd->intro, $forum);
//Now, mark the initial post of the discussion as mailed!
if ($sdid) {
- set_field ('forum_posts','mailed', '1', 'discussion', $sdid);
+ $DB->set_field ('forum_posts','mailed', '1', array('discussion'=>$sdid));
}
}
@@ -159,7 +158,7 @@
// was made pre Moodle 1.7.
if (isset($forum->open) && isset($forum->assesspublic)) {
- $forummod = get_record('modules', 'name', 'forum');
+ $forummod = $DB->get_record('modules', array('name'=>'forum'));
if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
notice('Default teacher role was not found. Roles and permissions '.
@@ -188,8 +187,7 @@
//This function restores the forum_subscriptions
function forum_subscriptions_restore_mods($forum_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -221,7 +219,7 @@
}
//The structure is equal to the db, so insert the forum_subscription
- $newid = insert_record ("forum_subscriptions",$subscription);
+ $newid = $DB->insert_record ("forum_subscriptions",$subscription);
//Do some output
if (($i+1) % 50 == 0) {
@@ -248,8 +246,7 @@
//This function restores the forum_discussions
function forum_discussions_restore_mods($forum_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -306,7 +303,7 @@
}
//The structure is equal to the db, so insert the forum_discussions
- $newid = insert_record ("forum_discussions",$discussion);
+ $newid = $DB->insert_record ("forum_discussions",$discussion);
//Do some output
if (($i+1) % 50 == 0) {
@@ -332,7 +329,7 @@
if ($rec) {
//Put its new firstpost
$discussion->firstpost = $rec->new_id;
- if ($post = get_record("forum_posts", "id", $discussion->firstpost)) {
+ if ($post = $DB->get_record("forum_posts", array("id"=>$discussion->firstpost))) {
$discussion->userid = $post->userid;
}
} else {
@@ -344,7 +341,7 @@
$temp_discussion->firstpost = $discussion->firstpost;
$temp_discussion->userid = $discussion->userid;
//Update discussion (only firstpost and userid will be changed)
- $status = update_record("forum_discussions",$temp_discussion);
+ $status = $DB->update_record("forum_discussions",$temp_discussion);
//echo "Updated firstpost ".$old_firstpost." to ".$temp_discussion->firstpost."
"; //Debug
} else {
$status = false;
@@ -356,8 +353,7 @@
//This function restores the forum_read
function forum_read_restore_mods($forum_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -415,7 +411,7 @@
//The structure is equal to the db, so insert the forum_read
$newid = 0;
if ($toinsert) {
- $newid = insert_record ("forum_read",$read);
+ $newid = $DB->insert_record ("forum_read",$read);
}
//Do some output
@@ -443,8 +439,7 @@
//This function restores the forum_posts
function forum_posts_restore_mods($new_forum_id,$discussion_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -485,7 +480,7 @@
}
//The structure is equal to the db, so insert the forum_posts
- $newid = insert_record ("forum_posts",$post);
+ $newid = $DB->insert_record ("forum_posts",$post);
//Do some output
if (($i+1) % 50 == 0) {
@@ -504,9 +499,9 @@
$newid);
//Get old forum id from backup_ids
- $rec = get_record("backup_ids","backup_code",$restore->backup_unique_code,
- "table_name","forum",
- "new_id",$new_forum_id);
+ $rec =$DB->get_record("backup_ids", array("backup_code"=>$restore->backup_unique_code,
+ "table_name"=>"forum",
+ "new_id"=>$new_forum_id));
//Now copy moddata associated files
$status = forum_restore_files ($rec->old_id, $new_forum_id,
$oldid, $newid, $restore);
@@ -520,7 +515,7 @@
}
//Now we get every post in this discussion_id and recalculate its parent post
- $posts = get_records ("forum_posts","discussion",$discussion_id);
+ $posts = $DB->get_records ("forum_posts",array("discussion"=>$discussion_id));
if ($posts) {
//Iterate over each post
foreach ($posts as $post) {
@@ -539,7 +534,7 @@
$temp_post->parent = $post->parent;
//echo "Updated parent ".$old_parent." to ".$temp_post->parent."
"; //Debug
//Update post (only parent will be changed)
- $status = update_record("forum_posts",$temp_post);
+ $status = $DB->update_record("forum_posts",$temp_post);
}
}
@@ -549,7 +544,6 @@
//This function copies the forum related info from backup temp dir to course moddata folder,
//creating it if needed and recoding everything (forum id and post id)
function forum_restore_files ($oldforid, $newforid, $oldpostid, $newpostid, $restore) {
-
global $CFG;
$status = true;
@@ -602,8 +596,7 @@
//This function restores the forum_ratings
function forum_ratings_restore_mods($new_post_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -637,7 +630,7 @@
}
//The structure is equal to the db, so insert the forum_ratings
- $newid = insert_record ("forum_ratings",$rating);
+ $newid = $DB->insert_record ("forum_ratings",$rating);
//Do some output
if (($i+1) % 50 == 0) {
@@ -665,24 +658,23 @@
//This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
//some texts in the module
function forum_restore_wiki2markdown ($restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Convert forum_posts->message
- if ($records = get_records_sql ("SELECT p.id, p.message, p.format
- FROM {$CFG->prefix}forum_posts p,
- {$CFG->prefix}forum_discussions d,
- {$CFG->prefix}forum f,
- {$CFG->prefix}backup_ids b
- WHERE d.id = p.discussion AND
- f.id = d.forum AND
- f.course = $restore->course_id AND
- p.format = ".FORMAT_WIKI. " AND
- b.backup_code = $restore->backup_unique_code AND
- b.table_name = 'forum_posts' AND
- b.new_id = p.id")) {
+ if ($records = $DB->get_records_sql("SELECT p.id, p.message, p.format
+ FROM {forum_posts} p,
+ {forum_discussions} d,
+ {forum} f,
+ {backup_ids} b
+ WHERE d.id = p.discussion AND
+ f.id = d.forum AND
+ f.course = ? AND
+ p.format = ".FORMAT_WIKI. " AND
+ b.backup_code = ? AND
+ b.table_name = 'forum_posts' AND
+ b.new_id = p.id", array($restore->course_id, $restore->backup_unique_code))) {
foreach ($records as $record) {
//Rebuild wiki links
$record->message = restore_decode_wiki_content($record->message, $restore);
@@ -690,7 +682,7 @@
$wtm = new WikiToMarkdown();
$record->message = $wtm->convert($record->message, $restore->course_id);
$record->format = FORMAT_MARKDOWN;
- $status = update_record('forum_posts', addslashes_object($record));
+ $status = $DB->update_record('forum_posts', $record);
//Do some output
$i++;
if (($i+1) % 1 == 0) {
@@ -1130,7 +1122,7 @@
//working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process
function forum_decode_content_links_caller($restore) {
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Process every POST (message) in the course
@@ -1148,8 +1140,8 @@
$result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) {
//Update record
- $post->message = addslashes($result);
- $status = update_record("forum_posts",$post);
+ $post->message = $result;
+ $status = $DB->update_record("forum_posts",$post);
if (debugging()) {
if (!defined('RESTORE_SILENTLY')) {
echo '
'.s($content).'
changed to
'.s($result).'
';
diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php
index 7c93daa4d0c..93e291b27b5 100644
--- a/mod/glossary/restorelib.php
+++ b/mod/glossary/restorelib.php
@@ -30,8 +30,7 @@
//This function executes all the restore procedure about this mod
function glossary_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -113,11 +112,11 @@
}
//The structure is equal to the db, so insert the glossary
- $newid = insert_record ("glossary",$glossary);
+ $newid = $DB->insert_record ("glossary",$glossary);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","glossary")." \"".format_string(stripslashes($glossary->name),true)."\"";
+ echo "".get_string("modulename","glossary")." \"".format_string($glossary->name,true)."\"";
}
backup_flush(300);
@@ -141,8 +140,7 @@
//This function restores the glossary_entries
function glossary_entries_restore_mods($old_glossary_id,$new_glossary_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -189,7 +187,7 @@
//If it's a teacher entry or userinfo was selected, restore the entry
if ($entry->teacherentry or restore_userdata_selected($restore,'glossary',$old_glossary_id)) {
//The structure is equal to the db, so insert the glossary_entries
- $newid = insert_record ("glossary_entries",$entry);
+ $newid = $DB->insert_record ("glossary_entries",$entry);
//Do some output
if (($i+1) % 50 == 0) {
@@ -226,8 +224,7 @@
//This function restores the glossary_comments
function glossary_comments_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -262,7 +259,7 @@
}
//The structure is equal to the db, so insert the glossary_comments
- $newid = insert_record ("glossary_comments",$comment);
+ $newid = $DB->insert_record ("glossary_comments",$comment);
//Do some output
if (($i+1) % 50 == 0) {
@@ -287,8 +284,7 @@
//This function restores the glossary_ratings
function glossary_ratings_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -315,7 +311,7 @@
}
//The structure is equal to the db, so insert the glossary_ratings
- $newid = insert_record ("glossary_ratings",$rating);
+ $newid = $DB->insert_record ("glossary_ratings",$rating);
//Do some output
if (($i+1) % 50 == 0) {
@@ -338,8 +334,7 @@
//This function restores the glossary_alias table
function glossary_alias_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -355,7 +350,7 @@
$alias->alias = backup_todb(trim($alias_info['#']['ALIAS_TEXT']['0']['#']));
//The structure is equal to the db, so insert the glossary_comments
- $newid = insert_record ("glossary_alias",$alias);
+ $newid = $DB->insert_record ("glossary_alias",$alias);
//Do some output
if (($i+1) % 50 == 0) {
@@ -378,8 +373,7 @@
//This function restores the glossary_categories
function glossary_categories_restore_mods($old_glossary_id,$new_glossary_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -401,7 +395,7 @@
$category->name = backup_todb($cat_info['#']['NAME']['0']['#']);
$category->usedynalink = backup_todb($cat_info['#']['USEDYNALINK']['0']['#']);
- $newid = insert_record ("glossary_categories",$category);
+ $newid = $DB->insert_record ("glossary_categories",$category);
//Do some output
if (($i+1) % 50 == 0) {
@@ -430,8 +424,7 @@
//This function restores the glossary_entries_categories
function glossary_entries_categories_restore_mods($old_category_id,$new_category_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -455,7 +448,7 @@
$entry_category->entryid = $entry->new_id;
}
- $newid = insert_record ("glossary_entries_categories",$entry_category);
+ $newid = $DB->insert_record ("glossary_entries_categories",$entry_category);
//Do some output
if (($i+1) % 50 == 0) {
@@ -479,7 +472,6 @@
//This function copies the glossary related info from backup temp dir to course moddata folder,
//creating it if needed and recoding everything (glossary id and entry id)
function glossary_restore_files ($oldgloid, $newgloid, $oldentryid, $newentryid, $restore) {
-
global $CFG;
$status = true;
diff --git a/mod/hotpot/restorelib.php b/mod/hotpot/restorelib.php
index 8a0a344bb9f..844818dd909 100644
--- a/mod/hotpot/restorelib.php
+++ b/mod/hotpot/restorelib.php
@@ -296,6 +296,8 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
// if the $record->$secondarykey value does not already exist in $table
// maintain a cache of info on table columns
+ global $DB;
+
static $table_columns = array();
if (empty($table_columns[$table])) {
global $CFG, $DB;
@@ -387,7 +389,7 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
// if there is a secondary key field ...
if ($secondary_key) {
// check to see if a record with the same value already exists
- $key_record = get_record($table, $secondary_key, $record->$secondary_key);
+ $key_record = $DB->get_record($table, array($secondary_key=>$record->$secondary_key));
if ($key_record) {
// set new record id from already existing record
$record->id = $key_record->id;
@@ -395,7 +397,7 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
}
if (empty($record->id)) {
// add the $record (and get new id)
- $record->id = insert_record($table, $record);
+ $record->id = $DB->insert_record($table, $record);
}
// check $record was added (or found)
if (is_numeric($record->id)) {
diff --git a/mod/label/restorelib.php b/mod/label/restorelib.php
index ab6259955ec..6bbe3529503 100644
--- a/mod/label/restorelib.php
+++ b/mod/label/restorelib.php
@@ -18,8 +18,7 @@
//This function executes all the restore procedure about this mod
function label_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -40,11 +39,11 @@
$label->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
//The structure is equal to the db, so insert the label
- $newid = insert_record ("label",$label);
+ $newid = $DB->insert_record ("label",$label);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","label")." \"".format_string(stripslashes($label->name),true)."\"";
+ echo "".get_string("modulename","label")." \"".format_string($label->name,true)."\"";
}
backup_flush(300);
diff --git a/mod/lesson/restorelib.php b/mod/lesson/restorelib.php
index 9e35c8b5b9f..6e2c8c9225b 100644
--- a/mod/lesson/restorelib.php
+++ b/mod/lesson/restorelib.php
@@ -40,8 +40,7 @@
//This function executes all the restore procedure about this mod
function lesson_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -101,11 +100,11 @@
$lesson->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
//The structure is equal to the db, so insert the lesson
- $newid = insert_record("lesson", $lesson);
+ $newid = $DB->insert_record("lesson", $lesson);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","lesson")." \"".format_string(stripslashes($lesson->name),true)."\"";
+ echo "".get_string("modulename","lesson")." \"".format_string($lesson->name,true)."\"";
}
backup_flush(300);
@@ -147,8 +146,7 @@
//This function restores the lesson_pages
function lesson_pages_restore_mods($lessonid,$info,$restore,$userdata=false) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -179,11 +177,11 @@
$page->contents = backup_todb($page_info['#']['CONTENTS']['0']['#']);
//The structure is equal to the db, so insert the lesson_pages
- $newid = insert_record ("lesson_pages",$page);
+ $newid = $DB->insert_record ("lesson_pages",$page);
//Fix the forwards link of the previous page
if ($prevpageid) {
- if (!set_field("lesson_pages", "nextpageid", $newid, "id", $prevpageid)) {
+ if (!$DB->set_field("lesson_pages", "nextpageid", $newid, array("id"=>$prevpageid))) {
print_error("Lesson restorelib: unable to update link");
}
}
@@ -213,7 +211,7 @@
if (($page->qtype == 3 && $page->qoption) ||
$page->qtype == 5) {
// get all the attempt records for this page
- if ($attempts = get_records("lesson_attempts", "pageid", $newid)) {
+ if ($attempts = $DB->get_records("lesson_attempts", array("pageid"=>$newid))) {
foreach ($attempts as $attempt) {
unset($newuseranswer);
if ($attempt->useranswer != NULL) {
@@ -227,7 +225,7 @@
// get the useranswer in the right format
$attempt->useranswer = implode(",", $newuseranswer);
// update it
- update_record("lesson_attempts", $attempt);
+ $DB->update_record("lesson_attempts", $attempt);
}
}
}
@@ -247,13 +245,13 @@
//We've restored all the pages and answers, we now need to fix the jumps in the
//answer records if they are absolute
- if ($answers = get_records("lesson_answers", "lessonid", $lessonid)) {
+ if ($answers = $DB->get_records("lesson_answers", array("lessonid"=>$lessonid))) {
foreach ($answers as $answer) {
if ($answer->jumpto > 0) {
// change the absolute page id
$page = backup_getid($restore->backup_unique_code,"lesson_pages",$answer->jumpto);
if ($page) {
- if (!set_field("lesson_answers", "jumpto", $page->new_id, "id", $answer->id)) {
+ if (!$DB->set_field("lesson_answers", "jumpto", $page->new_id, array("id"=>$answer->id))) {
print_error("Lesson restorelib: unable to reset jump");
}
}
@@ -266,8 +264,7 @@
//This function restores the lesson_answers
function lesson_answers_restore($lessonid,$pageid,$info,$restore,$userdata=false) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -285,8 +282,8 @@
$newanswer->pageid = $pageid;
$newanswer->timecreated = $time;
$newanswer->timemodified = 0;
- insert_record('lesson_answers', $newanswer);
- insert_record('lesson_answers', $newanswer);
+ $DB->insert_record('lesson_answers', $newanswer);
+ $DB->insert_record('lesson_answers', $newanswer); // TODO: why is this here twice?
}
}
}
@@ -317,7 +314,7 @@
$answer->response = backup_todb($answer_info['#']['RESPONSE']['0']['#']);
//The structure is equal to the db, so insert the lesson_answers
- $newid = insert_record ("lesson_answers",$answer);
+ $newid = $DB->insert_record ("lesson_answers",$answer);
//Do some output
if (($i+1) % 10 == 0) {
@@ -350,8 +347,7 @@
//This function restores the attempts
function lesson_attempts_restore($lessonid, $pageid, $answerid, $info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -385,7 +381,7 @@
}
//The structure is equal to the db, so insert the lesson_attempt
- $newid = insert_record ("lesson_attempts",$attempt);
+ $newid = $DB->insert_record ("lesson_attempts",$attempt);
//Do some output
if (($i+1) % 50 == 0) {
@@ -405,8 +401,7 @@
//This function restores the lesson_grades
function lesson_grades_restore_mods($lessonid, $info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -438,7 +433,7 @@
}
//The structure is equal to the db, so insert the lesson_grade
- $newid = insert_record ("lesson_grades",$grade);
+ $newid = $DB->insert_record ("lesson_grades",$grade);
//Do some output
if (($i+1) % 50 == 0) {
@@ -464,8 +459,7 @@
//This function restores the lesson_branch
function lesson_branch_restore($lessonid, $pageid, $info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -497,7 +491,7 @@
}
//The structure is equal to the db, so insert the lesson_attempt
- $newid = insert_record ("lesson_branch",$branch);
+ $newid = $DB->insert_record ("lesson_branch",$branch);
//Do some output
if (($i+1) % 50 == 0) {
@@ -517,8 +511,7 @@
//This function restores the lesson_timer
function lesson_timer_restore_mods($lessonid, $info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Get the timer array (optional)
@@ -547,7 +540,7 @@
}
//The structure is equal to the db, so insert the lesson_grade
- $newid = insert_record ("lesson_timer",$time);
+ $newid = $DB->insert_record ("lesson_timer",$time);
//Do some output
if (($i+1) % 50 == 0) {
@@ -571,8 +564,7 @@
//This function restores the lesson_high_scores
function lesson_high_scores_restore_mods($lessonid, $info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -602,7 +594,7 @@
}
//The structure is equal to the db, so insert the lesson_grade
- $newid = insert_record ("lesson_high_scores",$highscore);
+ $newid = $DB->insert_record ("lesson_high_scores",$highscore);
//Do some output
if (($i+1) % 50 == 0) {
@@ -626,8 +618,7 @@
//This function restores the lesson_default
function lesson_default_restore_mods($info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -677,7 +668,7 @@
$default->maxhighscores = backup_todb($default_info['#']['MAXHIGHSCORES']['0']['#']);
//The structure is equal to the db, so insert the lesson_grade
- $newid = insert_record ("lesson_default",$default);
+ $newid = $DB->insert_record ("lesson_default",$default);
if ($newid) {
backup_putid($restore->backup_unique_code,'lesson_default',
@@ -709,7 +700,6 @@
//lesson_decode_content_links_caller() function in each module
//in the restore process
function lesson_decode_content_links ($content,$restore) {
-
global $CFG;
$result = $content;
diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php
index 758e2b2b186..0952290ac94 100644
--- a/mod/quiz/restorelib.php
+++ b/mod/quiz/restorelib.php
@@ -37,8 +37,7 @@
include_once("$CFG->dirroot/question/restorelib.php");
function quiz_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -94,11 +93,11 @@
$quiz->questions = quiz_recode_layout($quiz->questions, $restore);
//The structure is equal to the db, so insert the quiz
- $newid = insert_record ("quiz",$quiz);
+ $newid = $DB->insert_record ("quiz",$quiz);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","quiz")." \"".format_string(stripslashes($quiz->name),true)."\"";
+ echo "".get_string("modulename","quiz")." \"".format_string($quiz->name,true)."\"";
}
backup_flush(300);
@@ -133,8 +132,7 @@
//This function restores the quiz_question_instances
function quiz_question_instances_restore_mods($quiz_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -168,7 +166,7 @@
}
//The structure is equal to the db, so insert the quiz_question_instances
- $newid = insert_record ("quiz_question_instances",$instance);
+ $newid = $DB->insert_record ("quiz_question_instances",$instance);
//Do some output
if (($i+1) % 10 == 0) {
@@ -195,6 +193,8 @@
//This function restores the quiz_question_instances
function quiz_feedback_restore_mods($quiz_id, $info, $restore, $quiz) {
+ global $DB;
+
$status = true;
//Get the quiz_feedback array
@@ -218,7 +218,7 @@
$feedback->maxgrade = backup_todb($feedback_info['#']['MAXGRADE']['0']['#']);
//The structure is equal to the db, so insert the quiz_question_instances
- $newid = insert_record('quiz_feedback', $feedback);
+ $newid = $DB->insert_record('quiz_feedback', $feedback);
if ($newid) {
//We have the newid, update backup_ids
@@ -233,7 +233,7 @@
$feedback->feedbacktext = '';
$feedback->mingrade = 0;
$feedback->maxgrade = $quiz->grade + 1;
- insert_record('quiz_feedback', $feedback);
+ $DB->insert_record('quiz_feedback', $feedback);
}
return $status;
@@ -241,8 +241,7 @@
//This function restores the quiz_question_versions
function quiz_question_versions_restore_mods($quiz_id,$info,$restore) {
-
- global $CFG, $USER;
+ global $CFG, $USER, $DB;
$status = true;
@@ -299,7 +298,7 @@
}
//The structure is equal to the db, so insert the quiz_question_versions
- $newid = insert_record ("quiz_question_versions",$version);
+ $newid = $DB->insert_record ("quiz_question_versions",$version);
//Do some output
if (($i+1) % 10 == 0) {
@@ -326,8 +325,7 @@
//This function restores the quiz_attempts
function quiz_attempts_restore_mods($quiz_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -374,7 +372,7 @@
$attempt->layout = quiz_recode_layout($attempt->layout, $restore);
//The structure is equal to the db, so insert the quiz_attempts
- $newid = insert_record ("quiz_attempts",$attempt);
+ $newid = $DB->insert_record ("quiz_attempts",$attempt);
//Do some output
if (($i+1) % 10 == 0) {
@@ -404,8 +402,7 @@
//This function restores the quiz_grades
function quiz_grades_restore_mods($quiz_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -441,7 +438,7 @@
}
//The structure is equal to the db, so insert the quiz_grades
- $newid = insert_record ("quiz_grades",$grade);
+ $newid = $DB->insert_record ("quiz_grades",$grade);
//Do some output
if (($i+1) % 10 == 0) {
@@ -471,7 +468,6 @@
//quiz_decode_content_links_caller() function in each module
//in the restore process
function quiz_decode_content_links ($content,$restore) {
-
global $CFG;
$result = $content;
diff --git a/mod/quiz/restorelibpre15.php b/mod/quiz/restorelibpre15.php
index 35233b78b8d..c34d279fe63 100644
--- a/mod/quiz/restorelibpre15.php
+++ b/mod/quiz/restorelibpre15.php
@@ -97,8 +97,7 @@
//STEP 1. Restore categories/questions and associated structures
// (course independent)
function quiz_restore_pre15_question_categories($category,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -127,7 +126,7 @@
if (!$quiz_cat->stamp) {
$quiz_cat->stamp = make_unique_id_code();
}
- $newid = insert_record ("question_categories",$quiz_cat);
+ $newid = $DB->insert_record ("question_categories",$quiz_cat);
}
//Do some output
@@ -163,8 +162,7 @@
}
function quiz_restore_pre15_questions ($old_category_id,$new_category_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -223,17 +221,17 @@
//Check if the question exists
//by category and stamp
- $question_exists = get_record ("question","category",$question->category,
- "stamp",$question->stamp);
+ $question_exists = $DB->get_record ("question", array("category"=>$question->category,
+ "stamp"=>$question->stamp));
//If the stamp doesn't exists, check if question exists
//by category, name and questiontext and calculate stamp
//Mantains pre Beta 1.1 compatibility !!
if (!$question->stamp) {
$question->stamp = make_unique_id_code();
$question->version = 1;
- $question_exists = get_record ("question","category",$question->category,
- "name",$question->name,
- "questiontext",$question->questiontext);
+ $question_exists = $DB->get_record ("question", array("category"=>$question->category,
+ "name"=>$question->name,
+ "questiontext"=>$question->questiontext));
}
//If the question exists, only record its id
@@ -243,10 +241,10 @@
//Else, create a new question
} else {
//The structure is equal to the db, so insert the question
- $newid = insert_record ("question",$question);
+ $newid = $DB->insert_record ("question",$question);
//If it is a random question, parent = id
if ($newid && $question->qtype == RANDOM) {
- set_field ('question', 'parent', $newid, 'id', $newid);
+ $DB->set_field ('question', 'parent', $newid, array('id'=>$newid));
}
$creatingnewquestion = true;
}
@@ -328,8 +326,7 @@
}
function quiz_restore_pre15_answers ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -354,7 +351,7 @@
$answer->feedback = backup_todb($ans_info['#']['FEEDBACK']['0']['#']);
//The structure is equal to the db, so insert the question_answers
- $newid = insert_record ("question_answers",$answer);
+ $newid = $DB->insert_record ("question_answers",$answer);
//Do some output
if (($i+1) % 50 == 0) {
@@ -381,8 +378,7 @@
}
function quiz_restore_pre15_map_answers ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -415,9 +411,9 @@
//mappings in backup_ids to use them later where restoring responses (user level).
//Get the answer from DB (by question, answer and fraction)
- $db_answer = get_record ("question_answers","question",$new_question_id,
- "answer",$answer->answer,
- "fraction",$answer->fraction);
+ $db_answer = $DB->get_record ("question_answers", array("question"=>$new_question_id,
+ "answer"=>$answer->answer,
+ "fraction"=>$answer->fraction));
//Do some output
if (($i+1) % 50 == 0) {
@@ -443,8 +439,7 @@
}
function quiz_restore_pre15_shortanswer ($old_question_id,$new_question_id,$info,$restore,$restrictto = '') {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -488,7 +483,7 @@
//The structure is equal to the db, so insert the question_shortanswer
//Only if there aren't restrictions or there are restriction concordance
if (empty($restrictto) || (!empty($restrictto) && $shortanswer->answers == $restrictto)) {
- $newid = insert_record ("question_shortanswer",$shortanswer);
+ $newid = $DB->insert_record ("question_shortanswer",$shortanswer);
}
//Do some output
@@ -511,8 +506,7 @@
}
function quiz_restore_pre15_truefalse ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -544,7 +538,7 @@
}
//The structure is equal to the db, so insert the question_truefalse
- $newid = insert_record ("question_truefalse",$truefalse);
+ $newid = $DB->insert_record ("question_truefalse",$truefalse);
//Do some output
if (($i+1) % 50 == 0) {
@@ -566,8 +560,7 @@
}
function quiz_restore_pre15_multichoice ($old_question_id,$new_question_id,$info,$restore, $restrictto = '') {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -612,7 +605,7 @@
//The structure is equal to the db, so insert the question_shortanswer
//Only if there aren't restrictions or there are restriction concordance
if (empty($restrictto) || (!empty($restrictto) && $multichoice->answers == $restrictto)) {
- $newid = insert_record ("question_multichoice",$multichoice);
+ $newid = $DB->insert_record ("question_multichoice",$multichoice);
}
//Do some output
@@ -635,8 +628,7 @@
}
function quiz_restore_pre15_match ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -663,7 +655,7 @@
$match_sub->answertext = backup_todb($mat_info['#']['ANSWERTEXT']['0']['#']);
//The structure is equal to the db, so insert the question_match_sub
- $newid = insert_record ("question_match_sub",$match_sub);
+ $newid = $DB->insert_record ("question_match_sub",$match_sub);
//Do some output
if (($i+1) % 50 == 0) {
@@ -697,7 +689,7 @@
$match->subquestions = $subquestions_field;
//The structure is equal to the db, so insert the question_match_sub
- $newid = insert_record ("question_match",$match);
+ $newid = $DB->insert_record ("question_match",$match);
if (!$newid) {
$status = false;
@@ -707,8 +699,7 @@
}
function quiz_restore_pre15_map_match ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -740,9 +731,9 @@
//mappings in backup_ids to use them later where restoring responses (user level).
//Get the match_sub from DB (by question, questiontext and answertext)
- $db_match_sub = get_record ("question_match_sub","question",$new_question_id,
- "questiontext",$match_sub->questiontext,
- "answertext",$match_sub->answertext);
+ $db_match_sub = $DB->get_record ("question_match_sub", array("question"=>$new_question_id,
+ "questiontext"=>$match_sub->questiontext,
+ "answertext"=>$match_sub->answertext));
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
@@ -768,8 +759,7 @@
}
function quiz_restore_pre15_randomsamatch ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -788,7 +778,7 @@
$randomsamatch->choose = backup_todb($ran_info['#']['CHOOSE']['0']['#']);
//The structure is equal to the db, so insert the question_randomsamatch
- $newid = insert_record ("question_randomsamatch",$randomsamatch);
+ $newid = $DB->insert_record ("question_randomsamatch",$randomsamatch);
//Do some output
if (($i+1) % 50 == 0) {
@@ -810,8 +800,7 @@
}
function quiz_restore_pre15_numerical ($old_question_id,$new_question_id,$info,$restore, $restrictto = '') {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -847,7 +836,7 @@
//The structure is equal to the db, so insert the question_numerical
//Only if there aren't restrictions or there are restriction concordance
if (empty($restrictto) || (!empty($restrictto) && in_array($numerical->answer,explode(",",$restrictto)))) {
- $newid = insert_record ("question_numerical",$numerical);
+ $newid = $DB->insert_record ("question_numerical",$numerical);
}
//Do some output
@@ -875,8 +864,7 @@
}
function quiz_restore_pre15_calculated ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -910,7 +898,7 @@
}
//The structure is equal to the db, so insert the question_calculated
- $newid = insert_record ("question_calculated",$calculated);
+ $newid = $DB->insert_record ("question_calculated",$calculated);
//Do some output
if (($i+1) % 50 == 0) {
@@ -945,7 +933,7 @@
$status = true;
//We need some question fields here so we get the full record from DB
- $parentquestion = get_record('question','id',$new_question_id);
+ $parentquestion = $DB->get_record('question', array('id'=>$new_question_id));
//We need to store all the positions with their created questions
//to be able to calculate the sequence field
@@ -1002,7 +990,7 @@
$question->stamp = make_unique_id_code();
//Save the new question to DB
- $newid = insert_record('question', $question);
+ $newid = $DB->insert_record('question', $question);
if ($newid) {
$createdquestions[$multianswer->positionkey] = $newid;
@@ -1050,7 +1038,7 @@
$multianswerdb = new object;
$multianswerdb->question = $parentquestion->id;
$multianswerdb->sequence = implode(",",$createdquestions);
- $mid = insert_record('question_multianswer', $multianswerdb);
+ $mid = $DB->insert_record('question_multianswer', $multianswerdb);
if (!$mid) {
$status = false;
@@ -1061,8 +1049,7 @@
}
function quiz_restore_pre15_numerical_units ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -1082,7 +1069,7 @@
$numerical_unit->unit = backup_todb($nu_info['#']['UNIT']['0']['#']);
//The structure is equal to the db, so insert the question_numerical_units
- $newid = insert_record ("question_numerical_units",$numerical_unit);
+ $newid = $DB->insert_record ("question_numerical_units",$numerical_unit);
if (!$newid) {
$status = false;
@@ -1093,8 +1080,7 @@
}
function quiz_restore_pre15_dataset_definitions ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -1132,11 +1118,9 @@
} else {
//The category isn't 0, so it's a category question dataset_definition, we have to see if it exists
//Look for a definition with the same category, name and type
- if ($definitionrec = get_record_sql("SELECT d.*
- FROM {$CFG->prefix}question_dataset_definitions d
- WHERE d.category = '$dataset_definition->category' AND
- d.name = '$dataset_definition->name' AND
- d.type = '$dataset_definition->type'")) {
+ if ($definitionrec = $DB->get_records('question_dataset_definitions', array('category'=>$dataset_definition->category,
+ 'name'=>$dataset_definition->name,
+ 'type'=>$dataset_definition->type))) {
//Such dataset_definition exist. Now we must check if it has enough itemcount
if ($definitionrec->itemcount < $dataset_definition->itemcount) {
//We haven't enough itemcount, so we have to create the definition as an individual question one.
@@ -1156,7 +1140,7 @@
//If we've to create the definition, do it
if ($create_definition) {
//The structure is equal to the db, so insert the question_dataset_definitions
- $newid = insert_record ("question_dataset_definitions",$dataset_definition);
+ $newid = $DB->insert_record ("question_dataset_definitions",$dataset_definition);
if ($newid) {
//Restore question_dataset_items
$status = quiz_restore_pre15_dataset_items($newid,$dd_info,$restore);
@@ -1168,7 +1152,7 @@
if ($newid) {
$question_dataset->question = $new_question_id;
$question_dataset->datasetdefinition = $newid;
- $newid = insert_record ("question_datasets",$question_dataset);
+ $newid = $DB->insert_record ("question_datasets",$question_dataset);
}
if (!$newid) {
@@ -1180,8 +1164,7 @@
}
function quiz_restore_pre15_dataset_items ($definitionid,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -1201,7 +1184,7 @@
$dataset_item->value = backup_todb($di_info['#']['VALUE']['0']['#']);
//The structure is equal to the db, so insert the question_dataset_items
- $newid = insert_record ("question_dataset_items",$dataset_item);
+ $newid = $DB-insert_record ("question_dataset_items",$dataset_item);
if (!$newid) {
$status = false;
@@ -1214,8 +1197,7 @@
//STEP 2. Restore quizzes and associated structures
// (course dependent)
function quiz_restore_pre15_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -1292,11 +1274,11 @@
$quiz->review = $review;
//The structure is equal to the db, so insert the quiz
- $newid = insert_record ("quiz",$quiz);
+ $newid = $DB->insert_record ("quiz",$quiz);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","quiz")." \"".format_string(stripslashes($quiz->name),true)."\"";
+ echo "".get_string("modulename","quiz")." \"".format_string($quiz->name,true)."\"";
}
backup_flush(300);
@@ -1329,8 +1311,7 @@
//This function restores the quiz_question_instances (old quiz_question_grades)
function quiz_question_instances_restore_pre15_mods($quiz_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -1359,7 +1340,7 @@
}
//The structure is equal to the db, so insert the quiz_question_grades
- $newid = insert_record ("quiz_question_instances",$grade);
+ $newid = $DB->insert_record ("quiz_question_instances",$grade);
//Do some output
if (($i+1) % 10 == 0) {
@@ -1386,8 +1367,7 @@
//This function restores the quiz_question_versions
function quiz_question_versions_restore_pre15_mods($quiz_id,$info,$restore) {
-
- global $CFG, $USER;
+ global $CFG, $USER, $DB;
$status = true;
@@ -1432,7 +1412,7 @@
}
//The structure is equal to the db, so insert the quiz_question_versions
- $newid = insert_record ("quiz_question_versions",$version);
+ $newid = $DB->insert_record ("quiz_question_versions",$version);
//Do some output
if (($i+1) % 10 == 0) {
@@ -1459,8 +1439,7 @@
//This function restores the quiz_attempts
function quiz_attempts_restore_pre15_mods($quiz_id,$info,$restore,$quizquestions) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -1506,7 +1485,7 @@
$attempt->uniqueid = question_new_attempt_uniqueid();
//The structure is equal to the db, so insert the quiz_attempts
- $newid = insert_record ("quiz_attempts",$attempt);
+ $newid = $DB->insert_record ("quiz_attempts",$attempt);
//Do some output
if (($i+1) % 10 == 0) {
@@ -1535,8 +1514,7 @@
//This function restores the question_states (old quiz_responses)
function question_states_restore_pre15_mods($attempt_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -1577,7 +1555,7 @@
//We have to recode the answer field
//It depends of the question type !!
//We get the question first
- $question = get_record("question","id",$response->question);
+ $question = $DB->get_record("question", array("id"=>$response->question));
//It exists
if ($question) {
//Depending of the qtype, we make different recodes
@@ -1692,7 +1670,7 @@
case 9: //MULTIANSWER QTYPE
//The answer is a comma separated list of hypen separated multianswer ids and answers. We must recode them.
//We need to have the sequence of questions here to be able to detect qtypes
- $multianswerdb = get_record('question_multianswer','question',$response->question);
+ $multianswerdb = $DB->get_record('question_multianswer',array('question'=>$response->question));
//Make an array of sequence to easy access
$sequencearr = explode(",",$multianswerdb->sequence);
$answer_field = "";
@@ -1713,7 +1691,7 @@
continue;
}
//Calculate question type
- $questiondb = get_record('question','id',$sequencearr[$counter-1]);
+ $questiondb = $DB->get_record('question', array('id'=>$sequencearr[$counter-1]));
$questiontype = $questiondb->qtype;
//Now, depending of the answertype field in question_multianswer
//we do diferent things
@@ -1756,7 +1734,7 @@
}
//The structure is equal to the db, so insert the question_states
- $newid = insert_record ("question_states",$response);
+ $newid = $DB->insert_record ("question_states",$response);
//Do some output
if (($i+1) % 10 == 0) {
@@ -1783,8 +1761,7 @@
//This function restores the quiz_grades
function quiz_grades_restore_pre15_mods($quiz_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -1815,7 +1792,7 @@
}
//The structure is equal to the db, so insert the quiz_grades
- $newid = insert_record ("quiz_grades",$grade);
+ $newid = $DB->insert_record ("quiz_grades",$grade);
//Do some output
if (($i+1) % 10 == 0) {
@@ -1843,19 +1820,18 @@
//This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
//some texts in the module
function quiz_restore_pre15_wiki2markdown ($restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Convert question->questiontext
- if ($records = get_records_sql ("SELECT q.id, q.questiontext, q.questiontextformat
- FROM {$CFG->prefix}question q,
- {$CFG->prefix}backup_ids b
- WHERE b.backup_code = $restore->backup_unique_code AND
- b.table_name = 'question' AND
- q.id = b.new_id AND
- q.questiontextformat = ".FORMAT_WIKI)) {
+ if ($records = $DB->get_records_sql ("SELECT q.id, q.questiontext, q.questiontextformat
+ FROM {question} q,
+ {backup_ids} b
+ WHERE b.backup_code = ? AND
+ b.table_name = 'question' AND
+ q.id = b.new_id AND
+ q.questiontextformat = ".FORMAT_WIKI, array($restore->backup_unique_code))) {
foreach ($records as $record) {
//Rebuild wiki links
$record->questiontext = restore_decode_wiki_content($record->questiontext, $restore);
@@ -1863,7 +1839,7 @@
$wtm = new WikiToMarkdown();
$record->questiontext = $wtm->convert($record->questiontext, $restore->course_id);
$record->questiontextformat = FORMAT_MARKDOWN;
- $status = update_record('question', addslashes_object($record));
+ $status = $DB->update_record('question', addslashes_object($record));
//Do some output
$i++;
if (($i+1) % 1 == 0) {
diff --git a/mod/resource/restorelib.php b/mod/resource/restorelib.php
index 21cabb71071..0862c22b904 100644
--- a/mod/resource/restorelib.php
+++ b/mod/resource/restorelib.php
@@ -18,8 +18,7 @@
//This function executes all the restore procedure about this mod
function resource_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -79,11 +78,11 @@
}
//The structure is equal to the db, so insert the resource
- $newid = insert_record ("resource",$resource);
+ $newid = $DB->insert_record ("resource",$resource);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","resource")." \"".format_string(stripslashes($resource->name),true)."\"";
+ echo "".get_string("modulename","resource")." \"".format_string($resource->name,true)."\"";
}
backup_flush(300);
diff --git a/mod/scorm/restorelib.php b/mod/scorm/restorelib.php
index 0c6c4863703..2ad7b344698 100755
--- a/mod/scorm/restorelib.php
+++ b/mod/scorm/restorelib.php
@@ -28,8 +28,7 @@
//This function executes all the restore procedure about this mod
function scorm_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -125,10 +124,10 @@
$scorm->timemodified = time();
//The structure is equal to the db, so insert the scorm
- $newid = insert_record ("scorm",$scorm);
+ $newid = $DB->insert_record ("scorm",$scorm);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","scorm")." \"".format_string(stripslashes($scorm->name),true)."\"";
+ echo "".get_string("modulename","scorm")." \"".format_string($scorm->name,true)."\"";
}
backup_flush(300);
@@ -145,7 +144,7 @@
if ($status) {
$launchsco = backup_getid($restore->backup_unique_code,"scorm_scoes",$oldlaunch);
$scorm->launch = $launchsco->new_id;
- update_record('scorm',$scorm);
+ $DB->update_record('scorm',$scorm);
}
}
@@ -161,8 +160,7 @@
//This function restores the scorm_scoes
function scorm_scoes_restore_mods($scorm_id,$info,$restore,$oldmodid) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -191,7 +189,7 @@
}
//The structure is equal to the db, so insert the scorm_scoes
- $newid = insert_record ("scorm_scoes",$sco);
+ $newid = $DB->insert_record ("scorm_scoes",$sco);
if ($newid) {
//We have the newid, update backup_ids
@@ -221,8 +219,7 @@
function scorm_scoes_seq_objective_restore_mods($sco_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -248,7 +245,7 @@
$objective->minnormalizedmeasure = backup_todb($obj_info['#']['MINNORMALIZEDMEASURE']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
- $newid = insert_record ("scorm_seq_objective",$objective);
+ $newid = $DB->insert_record ("scorm_seq_objective",$objective);
if ($newid) {
//We have the newid, update backup_ids
@@ -280,8 +277,7 @@
function scorm_scoes_seq_rolluprule_restore_mods($sco_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -308,7 +304,7 @@
$rolluprule->action = backup_todb($rol_info['#']['ACTION']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
- $newid = insert_record ("scorm_seq_rolluprule",$rolluprule);
+ $newid = $DB->insert_record ("scorm_seq_rolluprule",$rolluprule);
if ($newid) {
//We have the newid, update backup_ids
@@ -338,8 +334,7 @@
}
function scorm_scoes_seq_ruleconds_restore_mods($sco_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -364,7 +359,7 @@
$rulecond->action = backup_todb($rul_info['#']['ACTION']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
- $newid = insert_record ("scorm_seq_ruleconds",$rulecond);
+ $newid = $DB->insert_record ("scorm_seq_ruleconds",$rulecond);
if ($newid) {
//We have the newid, update backup_ids
@@ -394,7 +389,6 @@
}
function scorm_scoes_seq_rulecond_restore_mods($sco_id,$rulecondid,$info,$restore) {
-
global $CFG;
$status = true;
@@ -422,7 +416,7 @@
$rulecondd->cond = backup_todb($ruld_info['#']['COND']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
- $newid = insert_record ("scorm_seq_rulecond",$rulecondd);
+ $newid = $DB->insert_record ("scorm_seq_rulecond",$rulecondd);
if ($newid) {
//We have the newid, update backup_ids
@@ -450,8 +444,7 @@
}
function scorm_scoes_seq_rolluprulecond_restore_mods($sco_id,$rolluprule,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -477,7 +470,7 @@
//The structure is equal to the db, so insert the forum_discussions
- $newid = insert_record ("scorm_seq_rolluprulecond",$rolluprulecond);
+ $newid = $DB->insert_record ("scorm_seq_rolluprulecond",$rolluprulecond);
if ($newid) {
//We have the newid, update backup_ids
@@ -505,8 +498,7 @@
}
function scorm_scoes_seq_mapinfo_restore_mods($sco_id,$objectiveid,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -535,7 +527,7 @@
//The structure is equal to the db, so insert the forum_discussions
- $newid = insert_record ("scorm_seq_mapinfo",$mapinfo);
+ $newid = $DB->insert_record ("scorm_seq_mapinfo",$mapinfo);
if ($newid) {
//We have the newid, update backup_ids
@@ -560,8 +552,7 @@
//This function restores the scorm_scoes_track
function scorm_scoes_tracks_restore_mods($scorm_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$scotracks = NULL;
@@ -597,7 +588,7 @@
$scotrack->timemodified = time();
//The structure is equal to the db, so insert the scorm_scoes_track
- $newid = insert_record ("scorm_scoes_track",$scotrack);
+ $newid = $DB->insert_record ("scorm_scoes_track",$scotrack);
//Do some output
if (($i+1) % 50 == 0) {
@@ -617,8 +608,7 @@
//This function restores the scorm_scoes_track from Moodle 1.4
function scorm_scoes_tracks_restore_mods_pre15 ($scorm_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$scousers = NULL;
@@ -675,7 +665,7 @@
}
//The structure is equal to the db, so insert the scorm_scoes_track
- $newid = insert_record ("scorm_scoes_track",$scotrack);
+ $newid = $DB->insert_record ("scorm_scoes_track",$scotrack);
}
$pos++;
}
diff --git a/mod/survey/restorelib.php b/mod/survey/restorelib.php
index 25b02b16bc1..47aa03891d5 100644
--- a/mod/survey/restorelib.php
+++ b/mod/survey/restorelib.php
@@ -24,8 +24,7 @@
function survey_restore_mods($mod,$restore) {
-
- global $CFG,$DB;
+ global $CFG, $DB;
$status = true;
@@ -50,11 +49,11 @@
$survey->questions = backup_todb($info['MOD']['#']['QUESTIONS']['0']['#']);
//The structure is equal to the db, so insert the survey
- $newid = insert_record ("survey",$survey);
+ $newid = $DB->insert_record ("survey",$survey);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","survey")." \"".format_string(stripslashes($survey->name),true)."\"";
+ echo "".get_string("modulename","survey")." \"".format_string($survey->name,true)."\"";
}
backup_flush(300);
@@ -83,8 +82,7 @@
//This function restores the survey_answers
function survey_answers_restore_mods($survey_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -117,7 +115,7 @@
}
//The structure is equal to the db, so insert the survey_answers
- $newid = insert_record ("survey_answers",$answer);
+ $newid = $DB->insert_record ("survey_answers",$answer);
//Do some output
if (($i+1) % 50 == 0) {
@@ -144,8 +142,7 @@
//This function restores the survey_analysis
function survey_analysis_restore_mods($survey_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -175,7 +172,7 @@
}
//The structure is equal to the db, so insert the survey_analysis
- $newid = insert_record ("survey_analysis",$analys);
+ $newid = $DB->insert_record ("survey_analysis",$analys);
//Do some output
if (($i+1) % 50 == 0) {
diff --git a/mod/wiki/restorelib.php b/mod/wiki/restorelib.php
index c4b269e4640..f34531d6ca3 100644
--- a/mod/wiki/restorelib.php
+++ b/mod/wiki/restorelib.php
@@ -23,8 +23,7 @@
//-----------------------------------------------------------
function wiki_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -60,11 +59,11 @@
$wiki->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
//The structure is equal to the db, so insert the wiki
- $newid = insert_record ("wiki",$wiki);
+ $newid = $DB->insert_record ("wiki",$wiki);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "".get_string("modulename","wiki")." \"".format_string(stripslashes($wiki->name),true)."\"";
+ echo "".get_string("modulename","wiki")." \"".format_string($wiki->name,true)."\"";
}
backup_flush(300);
@@ -89,8 +88,7 @@
//This function restores the wiki_entries
function wiki_entries_restore_mods($old_wiki_id,$new_wiki_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -128,7 +126,7 @@
}
//The structure is equal to the db, so insert the wiki_entries
- $newid = insert_record ("wiki_entries",$entry);
+ $newid = $DB->insert_record ("wiki_entries",$entry);
//Do some output
if (($i+1) % 50 == 0) {
@@ -159,8 +157,7 @@
//This function restores the wiki_pages
function wiki_pages_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -199,7 +196,7 @@
$page->userid = $user->new_id;
}
//The structure is equal to the db, so insert the wiki_pages
- $newid = insert_record ("wiki_pages",$page);
+ $newid = $DB->insert_record ("wiki_pages",$page);
//Do some output
if (($i+1) % 50 == 0) {
diff --git a/question/restorelib.php b/question/restorelib.php
index de606e423df..bd2317f0189 100644
--- a/question/restorelib.php
+++ b/question/restorelib.php
@@ -138,6 +138,8 @@
}
function restore_question_category($category, $restore){
+ global $DB;
+
$status = true;
//Skip empty categories (some backups can contain them)
if (!empty($category->id)) {
@@ -180,7 +182,7 @@
//does cat exist ?? if it does we check if the cat and questions already exist whether we have
//add permission or not if we have no permission to add questions to SYSTEM or COURSECAT context
//AND the question does not already exist then we create questions in COURSE context.
- if (!$fcat = get_record('question_categories','contextid', $question_cat->contextid, 'stamp', $question_cat->stamp)){
+ if (!$fcat = $DB->get_record('question_categories', array('contextid'=>$question_cat->contextid, 'stamp'=>$question_cat->stamp))) {
//no preexisting cat
if ((($tocontext->contextlevel == CONTEXT_SYSTEM) || ($tocontext->contextlevel == CONTEXT_COURSECAT))
&& !has_capability('moodle/question:add', $tocontext)){
@@ -189,7 +191,7 @@
$tocontext = get_context_instance(CONTEXT_COURSE, $restore->course_id);
}
$question_cat->contextid = $tocontext->id;
- if (!$fcat = get_record('question_categories','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);
} else {
$question_cat = $fcat;
@@ -294,8 +296,7 @@
}
function restore_questions ($old_category_id, $best_question_cat, $info, $restore) {
-
- global $CFG, $QTYPES;
+ global $CFG, $QTYPES, $DB;
$status = true;
$restored_questions = array();
@@ -347,7 +348,7 @@
//Check if the question exists by category, stamp, and version
//first check for the question in the context specified in backup
- $existingquestion = get_record ("question", "category", $best_question_cat->id, "stamp", $question->stamp,"version",$question->version);
+ $existingquestion = $DB->get_record ("question", array("category"=>$best_question_cat->id, "stamp"=>$question->stamp,"version"=>$question->version));
//If the question exists, only record its id
//always use existing question, no permissions check here
if ($existingquestion) {
@@ -364,8 +365,8 @@
$course_question_cat = clone($best_question_cat);
$course_question_cat->contextid = $coursecontext->id;
//create cat if it doesn't exist
- if (!$fcat = get_record('question_categories','contextid', $course_question_cat->contextid, 'stamp', $course_question_cat->stamp)){
- $course_question_cat->id = insert_record ("question_categories", $course_question_cat);
+ if (!$fcat = $DB->get_record('question_categories', array('contextid'=>$course_question_cat->contextid, 'stamp'=>$course_question_cat->stamp))) {
+ $course_question_cat->id = $DB->insert_record("question_categories", $course_question_cat);
backup_putid($restore->backup_unique_code, "question_categories", $old_category_id, $course_question_cat->id);
} else {
$course_question_cat = $fcat;
@@ -382,7 +383,7 @@
}
if (!$existingquestion){
//The structure is equal to the db, so insert the question
- $question->id = insert_record ("question", $question);
+ $question->id = $DB->insert_record ("question", $question);
$creatingnewquestion = true;
} else {
$question = $existingquestion;
@@ -394,7 +395,7 @@
// see: $QTYPES['random']->get_question_options()
if ($question->qtype == 'random' && $creatingnewquestion) {
$question->parent = $question->id;
- $status = set_field('question', 'parent', $question->parent, 'id', $question->id);
+ $status = $DB->set_field('question', 'parent', $question->parent, array('id'=>$question->id));
}
//Save newid to backup tables
@@ -434,7 +435,7 @@
if ($parent = backup_getid($restore->backup_unique_code,"question",$question->parent)) {
$question->parent = $parent->new_id;
if ($question->parent != $restored_questions[$i]->parent) {
- if (!set_field('question', 'parent', $question->parent, 'id', $newid)) {
+ if (!$DB->set_field('question', 'parent', $question->parent, array('id'=>$newid))) {
echo 'Could not update parent '.$question->parent.' for question '.$oldid.'
';
$status = false;
}
@@ -491,8 +492,7 @@
}
function question_restore_answers ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$qtype = backup_todb($info['#']['QTYPE']['0']['#']);
@@ -524,7 +524,7 @@
}
//The structure is equal to the db, so insert the question_answers
- $newid = insert_record ("question_answers",$answer);
+ $newid = $DB->insert_record ("question_answers",$answer);
//Do some output
if (($i+1) % 50 == 0) {
@@ -551,8 +551,7 @@
}
function question_restore_map_answers ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -585,8 +584,8 @@
//mappings in backup_ids to use them later where restoring states (user level).
//Get the answer from DB (by question and answer)
- $db_answer = get_record ("question_answers","question",$new_question_id,
- "answer",$answer->answer);
+ $db_answer = $DB->get_record ("question_answers", array("question"=>$new_question_id,
+ "answer"=>$answer->answer));
//Do some output
if (($i+1) % 50 == 0) {
@@ -612,8 +611,7 @@
}
function question_restore_numerical_units($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -634,7 +632,7 @@
// Check to see if this until already exists in the database, which it might, for
// Historical reasons.
$unit = backup_todb($nu_info['#']['UNIT']['0']['#']);
- if (!record_exists('question_numerical_units', 'question', $new_question_id, 'unit', $unit)) {
+ if (!$DB->record_exists('question_numerical_units', array('question'=>$new_question_id, 'unit'=>$unit))) {
//Now, build the question_numerical_UNITS record structure.
$numerical_unit = new stdClass;
@@ -643,7 +641,7 @@
$numerical_unit->unit = $unit;
//The structure is equal to the db, so insert the question_numerical_units
- $newid = insert_record("question_numerical_units", $numerical_unit);
+ $newid = $DB->insert_record("question_numerical_units", $numerical_unit);
if (!$newid) {
$status = false;
@@ -655,8 +653,7 @@
}
function question_restore_dataset_definitions ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -697,11 +694,9 @@
} else {
//The category isn't 0, so it's a category question dataset_definition, we have to see if it exists
//Look for a definition with the same category, name and type
- if ($definitionrec = get_record_sql("SELECT d.*
- FROM {$CFG->prefix}question_dataset_definitions d
- WHERE d.category = '$dataset_definition->category' AND
- d.name = '$dataset_definition->name' AND
- d.type = '$dataset_definition->type'")) {
+ if ($definitionrec = $DB->get_records('question_dataset_definitions', array('category'=>$dataset_definition->category,
+ 'name'=>$dataset_definition->name,
+ 'type'=>$dataset_definition->type))) {
//Such dataset_definition exist. Now we must check if it has enough itemcount
if ($definitionrec->itemcount < $dataset_definition->itemcount) {
//We haven't enough itemcount, so we have to create the definition as an individual question one.
@@ -721,7 +716,7 @@
//If we've to create the definition, do it
if ($create_definition) {
//The structure is equal to the db, so insert the question_dataset_definitions
- $newid = insert_record ("question_dataset_definitions",$dataset_definition);
+ $newid = $DB->insert_record ("question_dataset_definitions",$dataset_definition);
if ($newid) {
//Restore question_dataset_items
$status = question_restore_dataset_items($newid,$dd_info,$restore);
@@ -734,7 +729,7 @@
$question_dataset = new stdClass;
$question_dataset->question = $new_question_id;
$question_dataset->datasetdefinition = $newid;
- $newid = insert_record ("question_datasets",$question_dataset);
+ $newid = $DB->insert_record ("question_datasets",$question_dataset);
}
if (!$newid) {
@@ -746,8 +741,7 @@
}
function question_restore_dataset_items ($definitionid,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -768,7 +762,7 @@
$dataset_item->value = backup_todb($di_info['#']['VALUE']['0']['#']);
//The structure is equal to the db, so insert the question_dataset_items
- $newid = insert_record ("question_dataset_items",$dataset_item);
+ $newid = $DB->insert_record ("question_dataset_items",$dataset_item);
if (!$newid) {
$status = false;
@@ -781,8 +775,7 @@
//This function restores the question_states
function question_states_restore_mods($attempt_id,$info,$restore) {
-
- global $CFG, $QTYPES;
+ global $CFG, $QTYPES, $DB;
$status = true;
@@ -833,7 +826,7 @@
//We have to recode the answer field
//It depends of the question type !!
//We get the question first
- if (!$question = get_record("question","id",$state->question)) {
+ if (!$question = $DB->get_record("question", array("id"=>$state->question))) {
print_error("Can't find the record for question $state->question for which I am trying to restore a state");
}
//Depending on the qtype, we make different recodes
@@ -842,7 +835,7 @@
}
//The structure is equal to the db, so insert the question_states
- $newid = insert_record ("question_states",$state);
+ $newid = $DB->insert_record ("question_states",$state);
//Do some output
if (($i+1) % 10 == 0) {
@@ -913,7 +906,7 @@
}
//The structure is equal to the db, so insert the question_sessions
- $newid = insert_record ("question_sessions",$session);
+ $newid = $DB->insert_record ("question_sessions",$session);
}
diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php
index 81b03c98a35..f4cf5a10f5b 100644
--- a/question/type/calculated/questiontype.php
+++ b/question/type/calculated/questiontype.php
@@ -1016,6 +1016,7 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
@@ -1044,7 +1045,7 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype
}
//The structure is equal to the db, so insert the question_calculated
- $newid = insert_record ("question_calculated",$calculated);
+ $newid = $DB->insert_record ("question_calculated",$calculated);
//Do some output
if (($i+1) % 50 == 0) {
diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php
index a15a6f83a1a..a442f743892 100644
--- a/question/type/match/questiontype.php
+++ b/question/type/match/questiontype.php
@@ -458,6 +458,7 @@ class question_match_qtype extends default_questiontype {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
@@ -486,7 +487,7 @@ class question_match_qtype extends default_questiontype {
$match_sub->answertext = backup_todb($mat_info['#']['ANSWERTEXT']['0']['#']);
//The structure is equal to the db, so insert the question_match_sub
- $newid = insert_record ("question_match_sub",$match_sub);
+ $newid = $DB->insert_record ("question_match_sub",$match_sub);
//Do some output
if (($i+1) % 50 == 0) {
@@ -521,7 +522,7 @@ class question_match_qtype extends default_questiontype {
$match->subquestions = $subquestions_field;
//The structure is equal to the db, so insert the question_match_sub
- $newid = insert_record ("question_match",$match);
+ $newid = $DB->insert_record ("question_match",$match);
if (!$newid) {
$status = false;
diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php
index b2de038de94..2367509e372 100644
--- a/question/type/multianswer/questiontype.php
+++ b/question/type/multianswer/questiontype.php
@@ -546,6 +546,7 @@ class embedded_cloze_qtype extends default_questiontype {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
@@ -585,7 +586,7 @@ class embedded_cloze_qtype extends default_questiontype {
//We have the answers field recoded to its new ids
$multianswer->sequence = $sequence_field;
//The structure is equal to the db, so insert the question_multianswer
- $newid = insert_record("question_multianswer", $multianswer);
+ $newid = $DB->insert_record("question_multianswer", $multianswer);
//Save ids in backup_ids
if ($newid) {
@@ -609,6 +610,7 @@ class embedded_cloze_qtype extends default_questiontype {
}
function restore_map($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
@@ -634,8 +636,8 @@ class embedded_cloze_qtype extends default_questiontype {
//mappings in backup_ids to use them later where restoring states (user level).
//Get the multianswer from DB (by question and positionkey)
- $db_multianswer = get_record ("question_multianswer","question",$new_question_id,
- "positionkey",$multianswer->positionkey);
+ $db_multianswer = $DB->get_record ("question_multianswer",array("question"=>$new_question_id,
+ "positionkey"=>$multianswer->positionkey));
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php
index 05dbddce52b..f154f252eaa 100644
--- a/question/type/multichoice/questiontype.php
+++ b/question/type/multichoice/questiontype.php
@@ -437,6 +437,7 @@ class question_multichoice_qtype extends default_questiontype {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
@@ -493,7 +494,7 @@ class question_multichoice_qtype extends default_questiontype {
$multichoice->answers = $answers_field;
//The structure is equal to the db, so insert the question_shortanswer
- $newid = insert_record ("question_multichoice",$multichoice);
+ $newid = $DB->insert_record ("question_multichoice",$multichoice);
//Do some output
if (($i+1) % 50 == 0) {
diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php
index 5dee90e03cb..96d0c797e16 100644
--- a/question/type/numerical/questiontype.php
+++ b/question/type/numerical/questiontype.php
@@ -433,6 +433,7 @@ class question_numerical_qtype extends question_shortanswer_qtype {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
@@ -460,7 +461,7 @@ class question_numerical_qtype extends question_shortanswer_qtype {
}
//The structure is equal to the db, so insert the question_numerical
- $newid = insert_record ("question_numerical", $numerical);
+ $newid = $DB->insert_record ("question_numerical", $numerical);
//Do some output
if (($i+1) % 50 == 0) {
diff --git a/question/type/randomsamatch/questiontype.php b/question/type/randomsamatch/questiontype.php
index e6fbee99fe0..4700b20349c 100644
--- a/question/type/randomsamatch/questiontype.php
+++ b/question/type/randomsamatch/questiontype.php
@@ -300,6 +300,7 @@ class question_randomsamatch_qtype extends question_match_qtype {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
@@ -315,7 +316,7 @@ class question_randomsamatch_qtype extends question_match_qtype {
$randomsamatch->choose = backup_todb($ran_info['#']['CHOOSE']['0']['#']);
//The structure is equal to the db, so insert the question_randomsamatch
- $newid = insert_record ("question_randomsamatch",$randomsamatch);
+ $newid = $DB->insert_record ("question_randomsamatch",$randomsamatch);
//Do some output
if (($i+1) % 50 == 0) {
diff --git a/question/type/shortanswer/questiontype.php b/question/type/shortanswer/questiontype.php
index ac999b95a5e..7ba83ac624b 100644
--- a/question/type/shortanswer/questiontype.php
+++ b/question/type/shortanswer/questiontype.php
@@ -274,6 +274,7 @@ class question_shortanswer_qtype extends default_questiontype {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
@@ -313,7 +314,7 @@ class question_shortanswer_qtype extends default_questiontype {
$shortanswer->answers = $answers_field;
//The structure is equal to the db, so insert the question_shortanswer
- $newid = insert_record ("question_shortanswer",$shortanswer);
+ $newid = $DB->insert_record ("question_shortanswer",$shortanswer);
//Do some output
if (($i+1) % 50 == 0) {
diff --git a/question/type/truefalse/questiontype.php b/question/type/truefalse/questiontype.php
index b34c4bf2265..25b5aca7aef 100644
--- a/question/type/truefalse/questiontype.php
+++ b/question/type/truefalse/questiontype.php
@@ -279,6 +279,7 @@ class question_truefalse_qtype extends default_questiontype {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
@@ -312,7 +313,7 @@ class question_truefalse_qtype extends default_questiontype {
}
//The structure is equal to the db, so insert the question_truefalse
- $newid = insert_record ("question_truefalse", $truefalse);
+ $newid = $DB->insert_record ("question_truefalse", $truefalse);
//Do some output
if (($i+1) % 50 == 0) {