//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);
}
}
//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;
echo '<li>'.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);
//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)) {
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;
//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;
//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;
$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);
// 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;
}
//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->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->defaultgroupingid = $course_header->course_defaultgroupingid;
+ }
+ $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);
}
//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);
//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...
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);
$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;
//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
$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) {
$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;
//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
$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
$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 = "";
}
&& !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;
}
}
- $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
$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);
}
}
}
//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
//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
//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
//(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')) {
//(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
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 {
* 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
/// 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 '<li>'.get_string('gradeletters','grades').'</li>';
}
// 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) {
$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);
}
}
}
echo '<li>'.get_string('categories','grades').'</li>';
}
//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);
* 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
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)) {
echo '<li>'.get_string('gradeletters','grades').'</li>';
}
// 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) {
$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);
}
}
}
if (!defined('RESTORE_SILENTLY')) {
echo '<li>'.get_string('gradeoutcomes','grades').'</li>';
}
- $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) {
//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;
$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");
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;
$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,
$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);
}
$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,
$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);
}
$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,
// 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 {
$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);
}
$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,
$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);
}
//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;
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
$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 {
//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");
}
}
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);
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);
}
}
}
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);
}
}
}
//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
//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')) {
$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
$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
}
$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
$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
}
$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
$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
}
//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
//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;
$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
}
//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
//This function creates all the categories and questions
//from xml
function restore_create_questions($restore,$xml_file) {
-
global $CFG;
$status = true;
//This function creates all the scales
function restore_create_scales($restore,$xml_file) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//Check it exists
$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) {
$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;
//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)) {
//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);
- }
- if (!$gro_db = get_record_sql("SELECT *
- FROM {$CFG->prefix}groups
- WHERE courseid = $restore->course_id AND
- name = '{$gro->name}'" . $description_clause, true)) {
+ $DB->sql_compare_text('description') . " = " .
+ $DB->sql_compare_text(':desc');
+ $params['desc'] = $gro->description;
+ }
+ 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
//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.
$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;
}
//This function creates all the groupings
function restore_create_groupings($restore,$xml_file) {
+ global $DB;
//Check it exists
if (!file_exists($xml_file)) {
$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;
}
// 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));
}
}
//This function creates all the groupingsgroups
function restore_create_groupings_groups($restore,$xml_file) {
+ global $DB;
//Check it exists
if (!file_exists($xml_file)) {
$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;
}
}
//This function creates all the course events
function restore_create_events($restore,$xml_file) {
+ global $DB;
global $CFG;
//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;
}
//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)
}
$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
//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.
//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;
$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)) {
//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;
//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;
//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)) {
//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;
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
//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;
//Now if $toinsert is set, insert the record
if ($toinsert) {
//echo "Inserting record<br />"; //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;
//Now if $toinsert is set, insert the record
if ($toinsert) {
//echo "Inserting record<br />"; //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;
//Now if $toinsert is set, insert the record
if ($toinsert) {
//echo "Inserting record<br />"; //Debug
- $status = insert_record("log",$log);
+ $status = $DB->insert_record("log",$log);
}
return $status;
}
//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 !!!
//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;
}
}
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;
}
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";
}
} 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 "<li>".get_string("usingexistingcourse");
//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;
echo "<li>".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
}
//Create, open and write header of the html log file
function restore_open_html($restore,$course_header) {
-
global $CFG;
$status = true;
}
//Create & close footer of the html log file
function restore_close_html($restore) {
-
global $CFG;
$status = true;
* It isn't now, just overwriting
*/
function restore_create_roles($restore, $xmlfile) {
+ global $DB;
if (!defined('RESTORE_SILENTLY')) {
echo "<li>".get_string("creatingrolesdefinitions").'</li>';
}
$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);
// 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) {
$roleinfo->capability = $capability->name;
$roleinfo->roleid = $newroleid;
- insert_record('role_capabilities', $roleinfo);
+ $DB->insert_record('role_capabilities', $roleinfo);
}
}
/// Now, restore role nameincourse
$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);
}
}
}
//This function executes all the restore procedure about this mod
function assignment_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
if (!in_array($assignment->assignmenttype, $plugins)) {
if (!defined('RESTORE_SILENTLY')) {
- echo "<li><strong>".get_string("modulename","assignment")." \"".format_string(stripslashes($assignment->name),true)."\" - plugin '{$assignment->assignmenttype}' not available!</strong></li>";
+ echo "<li><strong>".get_string("modulename","assignment")." \"".format_string($assignment->name,true)."\" - plugin '{$assignment->assignmenttype}' not available!</strong></li>";
}
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 "<li>".get_string("modulename","assignment")." \"".format_string(stripslashes($assignment->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","assignment")." \"".format_string($assignment->name,true)."\"</li>";
}
backup_flush(300);
//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;
}
//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) {
//This function executes all the restore procedure about this mod
function chat_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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 "<li>".get_string("modulename","chat")." \"".format_string(stripslashes($chat->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","chat")." \"".format_string($chat->name,true)."\"</li>";
}
backup_flush(300);
//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;
}
//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) {
//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
//This function executes all the restore procedure about this mod
function choice_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
}
//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
$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);
}
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "<li>".get_string("modulename","choice")." \"".format_string(stripslashes($choice->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","choice")." \"".format_string($choice->name,true)."\"</li>";
}
backup_flush(300);
//Return a content encoded to support interactivities linking. Every module
function data_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
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 "<li>".get_string("modulename","data")." \"".format_string(stripslashes($database->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","data")." \"".format_string($database->name,true)."\"</li>";
}
if ($newid) {
}
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'];
$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
}
function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore) {
-
- global $CFG, $fieldids;
+ global $CFG, $fieldids, $DB;
$status = true;
$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) {
}
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;
$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) {
}
function data_ratings_restore_mods ($oldid, $newid, $info, $rec_info) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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;
}
}
}
function data_comments_restore_mods ($oldid, $newid, $info, $rec_info) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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;
}
define('FEEDBACK_MULTICHOICERESTORE_TYPE_SEP', '>>>>>');
function feedback_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
// $allValues = array();
// $allTrackings = array();
$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
$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) {
$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;
}
}
//save the tracking
- $newtrackingid = insert_record('feedback_tracking', $tracking);
+ $newtrackingid = $DB->insert_record('feedback_tracking', $tracking);
$tracking->id = $newtrackingid;
// $allTrackings[] = $tracking;
}
$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);
}
}
}
//-----------------------------------------------------------
function forum_restore_mods($mod,$restore) {
-
- global $CFG,$DB;
+ global $CFG, $DB;
$status = true;
}
}
- $newid = insert_record("forum", $forum);
+ $newid = $DB->insert_record("forum", $forum);
//Do some output
// 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
$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));
}
}
// 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 '.
//This function restores the forum_subscriptions
function forum_subscriptions_restore_mods($forum_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//This function restores the forum_discussions
function forum_discussions_restore_mods($forum_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
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 {
$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."<br />"; //Debug
} else {
$status = false;
//This function restores the forum_read
function forum_read_restore_mods($forum_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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
//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;
}
//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) {
$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);
}
//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) {
$temp_post->parent = $post->parent;
//echo "Updated parent ".$old_parent." to ".$temp_post->parent."<br />"; //Debug
//Update post (only parent will be changed)
- $status = update_record("forum_posts",$temp_post);
+ $status = $DB->update_record("forum_posts",$temp_post);
}
}
//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;
//This function restores the forum_ratings
function forum_ratings_restore_mods($new_post_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//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);
$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) {
//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
$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 '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
//This function executes all the restore procedure about this mod
function glossary_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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 "<li>".get_string("modulename","glossary")." \"".format_string(stripslashes($glossary->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","glossary")." \"".format_string($glossary->name,true)."\"</li>";
}
backup_flush(300);
//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;
//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) {
//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;
}
//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) {
//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;
}
//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) {
//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;
$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) {
//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;
$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) {
//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;
$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) {
//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;
// 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;
// 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;
}
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)) {
//This function executes all the restore procedure about this mod
function label_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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 "<li>".get_string("modulename","label")." \"".format_string(stripslashes($label->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","label")." \"".format_string($label->name,true)."\"</li>";
}
backup_flush(300);
//This function executes all the restore procedure about this mod
function lesson_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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 "<li>".get_string("modulename","lesson")." \"".format_string(stripslashes($lesson->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","lesson")." \"".format_string($lesson->name,true)."\"</li>";
}
backup_flush(300);
//This function restores the lesson_pages
function lesson_pages_restore_mods($lessonid,$info,$restore,$userdata=false) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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");
}
}
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) {
// get the useranswer in the right format
$attempt->useranswer = implode(",", $newuseranswer);
// update it
- update_record("lesson_attempts", $attempt);
+ $DB->update_record("lesson_attempts", $attempt);
}
}
}
//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");
}
}
//This function restores the lesson_answers
function lesson_answers_restore($lessonid,$pageid,$info,$restore,$userdata=false) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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?
}
}
}
$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) {
//This function restores the attempts
function lesson_attempts_restore($lessonid, $pageid, $answerid, $info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//This function restores the lesson_grades
function lesson_grades_restore_mods($lessonid, $info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//This function restores the lesson_branch
function lesson_branch_restore($lessonid, $pageid, $info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//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)
}
//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) {
//This function restores the lesson_high_scores
function lesson_high_scores_restore_mods($lessonid, $info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//This function restores the lesson_default
function lesson_default_restore_mods($info, $restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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',
//lesson_decode_content_links_caller() function in each module
//in the restore process
function lesson_decode_content_links ($content,$restore) {
-
global $CFG;
$result = $content;
include_once("$CFG->dirroot/question/restorelib.php");
function quiz_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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 "<li>".get_string("modulename","quiz")." \"".format_string(stripslashes($quiz->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","quiz")." \"".format_string($quiz->name,true)."\"</li>";
}
backup_flush(300);
//This function restores the quiz_question_instances
function quiz_question_instances_restore_mods($quiz_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//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
$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
$feedback->feedbacktext = '';
$feedback->mingrade = 0;
$feedback->maxgrade = $quiz->grade + 1;
- insert_record('quiz_feedback', $feedback);
+ $DB->insert_record('quiz_feedback', $feedback);
}
return $status;
//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;
}
//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) {
//This function restores the quiz_attempts
function quiz_attempts_restore_mods($quiz_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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) {
//This function restores the quiz_grades
function quiz_grades_restore_mods($quiz_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//quiz_decode_content_links_caller() function in each module
//in the restore process
function quiz_decode_content_links ($content,$restore) {
-
global $CFG;
$result = $content;
//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;
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
}
function quiz_restore_pre15_questions ($old_category_id,$new_category_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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
//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;
}
}
function quiz_restore_pre15_answers ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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) {
}
function quiz_restore_pre15_map_answers ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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) {
}
function quiz_restore_pre15_shortanswer ($old_question_id,$new_question_id,$info,$restore,$restrictto = '') {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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
}
function quiz_restore_pre15_truefalse ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
}
function quiz_restore_pre15_multichoice ($old_question_id,$new_question_id,$info,$restore, $restrictto = '') {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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
}
function quiz_restore_pre15_match ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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) {
$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;
}
function quiz_restore_pre15_map_match ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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')) {
}
function quiz_restore_pre15_randomsamatch ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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) {
}
function quiz_restore_pre15_numerical ($old_question_id,$new_question_id,$info,$restore, $restrictto = '') {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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
}
function quiz_restore_pre15_calculated ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
$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
$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;
$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;
}
function quiz_restore_pre15_numerical_units ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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;
}
function quiz_restore_pre15_dataset_definitions ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
} 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.
//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);
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) {
}
function quiz_restore_pre15_dataset_items ($definitionid,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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;
//STEP 2. Restore quizzes and associated structures
// (course dependent)
function quiz_restore_pre15_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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 "<li>".get_string("modulename","quiz")." \"".format_string(stripslashes($quiz->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","quiz")." \"".format_string($quiz->name,true)."\"</li>";
}
backup_flush(300);
//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;
}
//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) {
//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;
}
//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) {
//This function restores the quiz_attempts
function quiz_attempts_restore_pre15_mods($quiz_id,$info,$restore,$quizquestions) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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) {
//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;
//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
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 = "";
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
}
//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) {
//This function restores the quiz_grades
function quiz_grades_restore_pre15_mods($quiz_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//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);
$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) {
//This function executes all the restore procedure about this mod
function resource_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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 "<li>".get_string("modulename","resource")." \"".format_string(stripslashes($resource->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","resource")." \"".format_string($resource->name,true)."\"</li>";
}
backup_flush(300);
//This function executes all the restore procedure about this mod
function scorm_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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 "<li>".get_string("modulename","scorm")." \"".format_string(stripslashes($scorm->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","scorm")." \"".format_string($scorm->name,true)."\"</li>";
}
backup_flush(300);
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);
}
}
//This function restores the scorm_scoes
function scorm_scoes_restore_mods($scorm_id,$info,$restore,$oldmodid) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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
function scorm_scoes_seq_objective_restore_mods($sco_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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
function scorm_scoes_seq_rolluprule_restore_mods($sco_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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
}
function scorm_scoes_seq_ruleconds_restore_mods($sco_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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
}
function scorm_scoes_seq_rulecond_restore_mods($sco_id,$rulecondid,$info,$restore) {
-
global $CFG;
$status = true;
$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
}
function scorm_scoes_seq_rolluprulecond_restore_mods($sco_id,$rolluprule,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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
}
function scorm_scoes_seq_mapinfo_restore_mods($sco_id,$objectiveid,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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
//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;
$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) {
//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;
}
//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++;
}
function survey_restore_mods($mod,$restore) {
-
- global $CFG,$DB;
+ global $CFG, $DB;
$status = true;
$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 "<li>".get_string("modulename","survey")." \"".format_string(stripslashes($survey->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","survey")." \"".format_string($survey->name,true)."\"</li>";
}
backup_flush(300);
//This function restores the survey_answers
function survey_answers_restore_mods($survey_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//This function restores the survey_analysis
function survey_analysis_restore_mods($survey_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
}
//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) {
//-----------------------------------------------------------
function wiki_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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 "<li>".get_string("modulename","wiki")." \"".format_string(stripslashes($wiki->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","wiki")." \"".format_string($wiki->name,true)."\"</li>";
}
backup_flush(300);
//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;
}
//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) {
//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;
$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) {
}
function restore_question_category($category, $restore){
+ global $DB;
+
$status = true;
//Skip empty categories (some backups can contain them)
if (!empty($category->id)) {
//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)){
$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;
}
function restore_questions ($old_category_id, $best_question_cat, $info, $restore) {
-
- global $CFG, $QTYPES;
+ global $CFG, $QTYPES, $DB;
$status = true;
$restored_questions = array();
//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) {
$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;
}
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;
// 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
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.'<br />';
$status = false;
}
}
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']['#']);
}
//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) {
}
function question_restore_map_answers ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
//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) {
}
function question_restore_numerical_units($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
// 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;
$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;
}
function question_restore_dataset_definitions ($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
} 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.
//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);
$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) {
}
function question_restore_dataset_items ($definitionid,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
$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;
//This function restores the question_states
function question_states_restore_mods($attempt_id,$info,$restore) {
-
- global $CFG, $QTYPES;
+ global $CFG, $QTYPES, $DB;
$status = true;
//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
}
//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) {
}
//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);
}
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
}
//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) {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
$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) {
$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;
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
//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) {
}
function restore_map($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
//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')) {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
$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) {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
}
//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) {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
$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) {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
$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) {
* This is used in question/restorelib.php
*/
function restore($old_question_id,$new_question_id,$info,$restore) {
+ global $DB;
$status = true;
}
//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) {