From: skodak Date: Sun, 1 Jun 2008 14:46:48 +0000 (+0000) Subject: MDL-14679 towards /backup conversion X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ad4375ac7fba39521fe9e5a724b434fb1841cbb4;p=moodle.git MDL-14679 towards /backup conversion --- diff --git a/backup/backup.php b/backup/backup.php index 628972c331..861b122571 100644 --- a/backup/backup.php +++ b/backup/backup.php @@ -95,7 +95,7 @@ } //Get and check course - if (! $course = get_record("course", "id", $id)) { + if (! $course = $DB->get_record("course", array("id"=>$id))) { print_error('unknowncourseidnumber','error'); } diff --git a/backup/backup_check.html b/backup/backup_check.html index feb1d12079..2ac3868270 100644 --- a/backup/backup_check.html +++ b/backup/backup_check.html @@ -70,7 +70,7 @@ //inform the user. // TODO: Move this logic to one function to be shared by any (manual, scheduled) backup if ($backupprefs->backup_users == 2) { - if ($allmods = get_records('modules') ) { + if ($allmods = $DB->get_records('modules') ) { foreach ($allmods as $mod) { /// Reset global user_info settings to "no" (0) $modname = $mod->name; @@ -129,7 +129,7 @@ //This is the alignment of every row in the table $table->align = array ("left","right"); - if ($allmods = get_records("modules") ) { + if ($allmods = $DB->get_records("modules") ) { foreach ($allmods as $mod) { $modname = $mod->name; $modfile = $CFG->dirroot.'/mod/'.$modname.'/backuplib.php'; diff --git a/backup/backup_form.html b/backup/backup_form.html index fc1fe18253..46b0d93e8b 100644 --- a/backup/backup_form.html +++ b/backup/backup_form.html @@ -1,5 +1,6 @@ get_records('modules', array('visible'=>1)) ) { foreach ($allmods as $mod) { $modname = $mod->name; $modfile = "$CFG->dirroot/mod/$modname/backuplib.php"; @@ -42,7 +43,7 @@ $$var = true; $count++; // check that there are instances and we can back them up individually - if (count_records('course_modules','course',$course->id,'module',$mod->id) && function_exists($modbackupone)) { + if ($DB->count_records('course_modules',array('course'=>$course->id,'module'=>$mod->id)) && function_exists($modbackupone)) { $var = 'exists_one_'.$modname; $$var = true; } @@ -121,7 +122,7 @@ function selectItemInCheckboxByName(formId, checkName, checked ) { /// Acummulator for hidden options and proper XHTML output $hidden_options = ''; //Now, check modules and info and show posibilities - if ($allmods = get_records('modules', 'visible', 1) ) { + if ($allmods = $DB->get_records('modules', array('visible'=>1)) ) { //Print option to select/deselect everything with 1 click. echo ""; echo ""; @@ -331,7 +332,7 @@ function selectItemInCheckboxByName(formId, checkName, checked ) { echo ""; echo get_string("backuproleassignments"); echo ""; - $roles = get_records('role', '', '', 'sortorder'); + $roles = $DB->get_records('role', null, 'sortorder'); foreach ($roles as $role) { print_checkbox('backupassignments_' . $role->shortname, 1, true, strip_tags(format_string($role->name, true))); echo "
"; diff --git a/backup/backup_scheduled.php b/backup/backup_scheduled.php index 0416ecfbb1..a93404582d 100644 --- a/backup/backup_scheduled.php +++ b/backup/backup_scheduled.php @@ -4,8 +4,7 @@ //This function is executed via moodle cron //It prepares all the info and execute backups as necessary function schedule_backup_cron() { - - global $CFG; + global $CFG, $DB; $status = true; @@ -33,7 +32,7 @@ function schedule_backup_cron() { //for info in backup_logs to unlock status as necessary $timetosee = 1800; //Half an hour looking for activity $timeafter = time() - $timetosee; - $numofrec = count_records_select ("backup_log","time > $timeafter"); + $numofrec = $DB->count_records_select ("backup_log","time > ?", array($timeafter)); if (!$numofrec) { $timetoseemin = $timetosee/60; mtrace(" No activity in last ".$timetoseemin." minutes. Unlocking status"); @@ -66,10 +65,10 @@ function schedule_backup_cron() { //First of all, we delete everything from backup tables related to deleted courses mtrace(" Skipping deleted courses"); $skipped = 0; - if ($bckcourses = get_records('backup_courses')) { + if ($bckcourses = $DB->get_records('backup_courses')) { foreach($bckcourses as $bckcourse) { //Search if it exists - if (!$exists = get_record('course', 'id', "$bckcourse->courseid")) { + if (!$exists = $DB->get_record('course', array('id'=>$bckcourse->courseid))) { //Doesn't exist, so delete from backup tables delete_records('backup_courses', 'courseid', "$bckcourse->courseid"); delete_records('backup_log', 'courseid', "$bckcourse->courseid"); @@ -79,20 +78,20 @@ function schedule_backup_cron() { } mtrace(" $skipped courses"); //Now process existing courses - $courses = get_records("course"); + $courses = $DB->get_records("course"); //For each course, we check (insert, update) the backup_course table //with needed data foreach ($courses as $course) { if ($status) { mtrace(" $course->fullname"); //We check if the course exists in backup_course - $backup_course = get_record("backup_courses","courseid",$course->id); + $backup_course = $DB->get_record("backup_courses", array("courseid"=>$course->id)); //If it doesn't exist, create if (!$backup_course) { $temp_backup_course->courseid = $course->id; - $newid = insert_record("backup_courses",$temp_backup_course); + $newid = $DB->insert_record("backup_courses",$temp_backup_course); //And get it from db - $backup_course = get_record("backup_courses","id",$newid); + $backup_course = $DB->get_record("backup_courses", array("id"=>$newid)); } //If it doesn't exist now, error if (!$backup_course) { @@ -104,7 +103,7 @@ function schedule_backup_cron() { $skipped = false; if (!$course->visible && ($now - $course->timemodified) > 31*24*60*60) { //Hidden + unmodified last month mtrace(" SKIPPING - hidden+unmodified"); - set_field("backup_courses","laststatus","3","courseid",$backup_course->courseid); + $DB->set_field("backup_courses","laststatus","3", array("courseid"=>$backup_course->courseid)); $skipped = true; } //Now we backup every non skipped course with nextstarttime < now @@ -115,18 +114,18 @@ function schedule_backup_cron() { if ($backup_course->laststatus != 2) { //Set laststarttime $starttime = time(); - set_field("backup_courses","laststarttime",$starttime,"courseid",$backup_course->courseid); + $DB->set_field("backup_courses","laststarttime",$starttime, array("courseid"=>$backup_course->courseid)); //Set course status to unfinished, the process will reset it - set_field("backup_courses","laststatus","2","courseid",$backup_course->courseid); + $DB->set_field("backup_courses","laststatus","2", array("courseid"=>$backup_course->courseid)); //Launch backup $course_status = schedule_backup_launch_backup($course,$starttime); //Set lastendtime - set_field("backup_courses","lastendtime",time(),"courseid",$backup_course->courseid); + $DB->set_field("backup_courses","lastendtime",time(), array("courseid"=>$backup_course->courseid)); //Set laststatus if ($course_status) { - set_field("backup_courses","laststatus","1","courseid",$backup_course->courseid); + $DB->set_field("backup_courses","laststatus","1", array("courseid"=>$backup_course->courseid)); } else { - set_field("backup_courses","laststatus","0","courseid",$backup_course->courseid); + $DB->set_field("backup_courses","laststatus","0", array("courseid"=>$backup_course->courseid)); } } } @@ -134,7 +133,7 @@ function schedule_backup_cron() { //Now, calculate next execution of the course $nextstarttime = schedule_backup_next_execution ($backup_course,$backup_config,$now,$admin->timezone); //Save it to db - set_field("backup_courses","nextstarttime",$nextstarttime,"courseid",$backup_course->courseid); + $DB->set_field("backup_courses","nextstarttime",$nextstarttime, array("courseid"=>$backup_course->courseid)); //Print it to screen as necessary $showtime = "undefined"; if ($nextstarttime > 0) { @@ -149,7 +148,7 @@ function schedule_backup_cron() { if (!empty($CFG->loglifetime)) { mtrace(" Deleting old logs"); $loglifetime = $now - ($CFG->loglifetime * 86400); - delete_records_select("backup_log", "laststarttime < '$loglifetime'"); + $DB->delete_records_select("backup_log", "laststarttime < ?", array($loglifetime)); } //Send email to admin if necessary @@ -158,11 +157,11 @@ function schedule_backup_cron() { $message = ""; //Get info about the status of courses - $count_all = count_records('backup_courses'); - $count_ok = count_records('backup_courses','laststatus','1'); - $count_error = count_records('backup_courses','laststatus','0'); - $count_unfinished = count_records('backup_courses','laststatus','2'); - $count_skipped = count_records('backup_courses','laststatus','3'); + $count_all = $DB->count_records('backup_courses'); + $count_ok = $DB->count_records('backup_courses', array('laststatus'=>'1')); + $count_error = $DB->count_records('backup_courses', array('laststatus'=>'0')); + $count_unfinished = $DB->count_records('backup_courses', array('laststatus'=>'2')); + $count_skipped = $DB->count_records('backup_courses', array('laststatus'=>'3')); //Build the message text //Summary @@ -182,7 +181,7 @@ function schedule_backup_cron() { //Set message priority $admin->priority = 1; //Reset unfinished to error - set_field('backup_courses','laststatus','0','laststatus','2'); + $DB->set_field('backup_courses','laststatus','0', array('laststatus'=>'2')); } else { $message .= " ".get_string('backupfinished')."\n"; } @@ -245,14 +244,16 @@ function schedule_backup_launch_backup($course,$starttime = 0) { //This function saves to backup_log all the needed process info //to use it later. NOTE: If $starttime = 0 no info in saved function schedule_backup_log($starttime,$courseid,$message) { + global $DB; if ($starttime) { + $log = new object(); $log->courseid = $courseid; $log->time = time(); $log->laststarttime = $starttime; - $log->info = addslashes($message); + $log->info = $message; - insert_record ("backup_log",$log); + $DB->insert_record("backup_log", $log); } } @@ -297,8 +298,7 @@ function schedule_backup_next_execution ($backup_course,$backup_config,$now,$tim //This function implements all the needed code to prepare a course //to be in backup (insert temp info into backup temp tables). function schedule_backup_course_configure($course,$starttime = 0) { - - global $CFG; + global $CFG, $DB; $status = true; @@ -367,7 +367,7 @@ function schedule_backup_course_configure($course,$starttime = 0) { //Checks for the required files/functions to backup every mod //And check if there is data about it $count = 0; - if ($allmods = get_records("modules") ) { + if ($allmods = $DB->get_records("modules") ) { foreach ($allmods as $mod) { $modname = $mod->name; $modfile = "$CFG->dirroot/mod/$modname/backuplib.php"; @@ -461,7 +461,7 @@ function schedule_backup_course_configure($course,$starttime = 0) { $preferences->keep_name = $keep_name; //Roleasignments - $roles = get_records('role', '', '', 'sortorder'); + $roles = $DB->get_records('role', null, 'sortorder'); foreach ($roles as $role) { $preferences->backuproleassignments[$role->id] = $role; } @@ -480,7 +480,7 @@ function schedule_backup_course_configure($course,$starttime = 0) { //Calculate necesary info to backup modules if ($status) { schedule_backup_log($starttime,$course->id," calculating modules data"); - if ($allmods = get_records("modules") ) { + if ($allmods = $DB->get_records("modules") ) { foreach ($allmods as $mod) { $modname = $mod->name; $modbackup = $modname."_backup_mods"; diff --git a/backup/lib.php b/backup/lib.php index 303a42f086..fac9292c9c 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -6,20 +6,24 @@ //Sets a name/value pair in backup_config table function backup_set_config($name, $value) { - if (get_field("backup_config", "name", "name", $name)) { - return set_field("backup_config", "value", addslashes($value), "name", $name); + global $DB; + + if ($DB->get_field("backup_config", "name", array("name"=>$name))) { + return $DB->set_field("backup_config", "value", $value, array("name"=>$name)); } else { $config = new object(); - $config->name = $name; - $config->value = addslashes($value); - return insert_record("backup_config", $config); + $config->name = $name; + $config->value = $value; + return $DB->insert_record("backup_config", $config); } } //Gets all the information from backup_config table function backup_get_config() { + global $DB; + $backup_config = null; - if ($configs = get_records("backup_config")) { + if ($configs = $DB->get_records("backup_config")) { foreach ($configs as $config) { $backup_config[$config->name] = $config->value; } @@ -30,8 +34,7 @@ //Delete old data in backup tables (if exists) //Four hours seem to be appropiate now that backup is stable function backup_delete_old_data() { - - global $CFG; + global $CFG, $DB; //Change this if you want !! $hours = 4; @@ -39,11 +42,11 @@ $seconds = $hours * 60 * 60; $delete_from = time()-$seconds; //Now delete from tables - $status = execute_sql("DELETE FROM {$CFG->prefix}backup_ids - WHERE backup_code < '$delete_from'",false); + $status = $DB->execute("DELETE FROM {backup_ids} + WHERE backup_code < ?", array($delete_from)); if ($status) { - $status = execute_sql("DELETE FROM {$CFG->prefix}backup_files - WHERE backup_code < '$delete_from'",false); + $status = $DB->execute("DELETE FROM {backup_files} + WHERE backup_code < ?", array($delete_from)); } //Now, delete old directory (if exists) if ($status) { @@ -85,7 +88,6 @@ //Function to check and create the needed dir to //save all the backup function check_and_create_backup_dir($backup_unique_code) { - global $CFG; $status = check_dir_exists($CFG->dataroot."/temp",true); @@ -164,7 +166,6 @@ //Function to clear (empty) the contents of the backup_dir function clear_backup_dir($backup_unique_code) { - global $CFG; $rootdir = $CFG->dataroot."/temp/backup/".$backup_unique_code; @@ -177,15 +178,12 @@ //Returns the module type of a course_module's id in a course function get_module_type ($courseid,$moduleid) { + global $DB; - global $CFG; - - $results = get_records_sql ("SELECT cm.id, m.name - FROM {$CFG->prefix}course_modules cm, - {$CFG->prefix}modules m - WHERE cm.course = '$courseid' AND - cm.id = '$moduleid' AND - m.id = cm.module"); + $results = $DB->get_records_sql("SELECT cm.id, m.name + FROM {course_modules} cm, {modules} m + WHERE cm.course = ? AND cm.id = ? AND + m.id = cm.module", array($courseid, $moduleid)); if ($results) { $name = $results[$moduleid]->name; @@ -234,20 +232,16 @@ //This function clean data from backup tables and //delete all temp files used function clean_temp_data ($preferences) { - - global $CFG; + global $CFG, $DB; $status = true; //true->do it, false->don't do it. To debug if necessary. if (true) { //Now delete from tables - $status = execute_sql("DELETE FROM {$CFG->prefix}backup_ids - WHERE backup_code = '$preferences->backup_unique_code'",false); - if ($status) { - $status = execute_sql("DELETE FROM {$CFG->prefix}backup_files - WHERE backup_code = '$preferences->backup_unique_code'",false); - } + $status = $DB->delete_records('backup_ids', array('backup_code'=>$preferences->backup_unique_code)) + && $DB->delete_records('backup_files', array('backup_code'=>$preferences->backup_unique_code)); + //Now, delete temp directory (if exists) $file_path = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code; if (is_dir($file_path)) { @@ -270,7 +264,6 @@ //Little modifications done function backup_copy_file ($from_file,$to_file,$log_clam=false) { - global $CFG; if (is_file($from_file)) { @@ -297,7 +290,6 @@ } function backup_copy_dir($from_file,$to_file) { - global $CFG; $status = true; // Initialize this, next code will change its value if needed @@ -447,9 +439,8 @@ //This function is used to insert records in the backup_ids table //If the info field is greater than max_db_storage, then its info //is saved to filesystem - function backup_putid ($backup_unique_code, $table, $old_id, $new_id, $info="") { - - global $CFG; + function backup_putid($backup_unique_code, $table, $old_id, $new_id, $info="") { + global $CFG, $DB; $max_db_storage = 128; //Max bytes to save to db, else save to file @@ -473,7 +464,7 @@ $info_to_save = "infile"; } else { //Saving to db, addslashes - $info_to_save = addslashes($info_ser); + $info_to_save = $info_ser; } //Now, insert the record @@ -486,7 +477,7 @@ $rec->new_id = ($new_id === null? 0 : $new_id); $rec->info = $info_to_save; - if (!insert_record('backup_ids', $rec, false)) { + if (!$DB->insert_record('backup_ids', $rec, false)) { $status = false; } } @@ -496,31 +487,21 @@ //This function is used to delete recods from the backup_ids table //If the info field is "infile" then the file is deleted too function backup_delid ($backup_unique_code, $table, $old_id) { - - global $CFG; - - $status = true; - - $status = execute_sql("DELETE FROM {$CFG->prefix}backup_ids - WHERE backup_code = $backup_unique_code AND - table_name = '$table' AND - old_id = '$old_id'",false); - return $status; + global $DB; + return $DB->delete_records('backup_ids', array('backup_code'=>$backup_unique_code, '$table_name'=>$table, 'old_id'=>$old_id)); } //This function is used to get a record from the backup_ids table //If the info field is "infile" then its info //is read from filesystem function backup_getid ($backup_unique_code, $table, $old_id) { - - global $CFG; + global $CFG, $DB; $status = true; $status2 = true; - $status = get_record ("backup_ids","backup_code",$backup_unique_code, - "table_name",$table, - "old_id", $old_id); + $status = $DB->get_record("backup_ids", array("backup_code"=>$backup_unique_code, + "table_name"=>$table, "old_id"=>$old_id)); //If info field = "infile", get file contents if (!empty($status->info) && $status->info == "infile") { @@ -541,7 +522,7 @@ debugging('Incorrect string "needed" in $status->info, please fix the code (table:'.$table.'; old_id:'.$old_id.').', DEBUG_DEVELOPER); } else { ////First strip slashes - $temp = stripslashes($status->info); + $temp = $status->info; //Now unserialize $status->info = unserialize($temp); } @@ -636,7 +617,7 @@ * messages */ function import_backup_file_silently($pathtofile,$destinationcourse,$emptyfirst=false,$userdata=false, $preferences=array()) { - global $CFG,$SESSION,$USER; // is there such a thing on cron? I guess so.. + global $CFG,$SESSION,$USER, $DB; // is there such a thing on cron? I guess so.. global $restore; // ick if (empty($USER)) { $USER = get_admin(); @@ -649,7 +630,7 @@ $cleanupafter = false; $errorstr = ''; // passed by reference to restore_precheck to get errors from. - if (!$course = get_record('course','id',$destinationcourse)) { + if (!$course = $DB->get_record('course', array('id'=>$destinationcourse))) { mtrace($debuginfo.'Course with id $destinationcourse was not a valid course!'); return false; } @@ -726,7 +707,7 @@ } // we also need modules... - if ($allmods = get_records("modules")) { + if ($allmods = $DB->get_records("modules")) { foreach ($allmods as $mod) { $modname = $mod->name; //Now check that we have that module info in the backup file @@ -756,9 +737,9 @@ * @param array $prefs see {@link backup_generate_preferences_artificially} */ function backup_course_silently($courseid, $prefs, &$errorstring) { - global $CFG, $preferences; // global preferences here because something else wants it :( + global $CFG, $preferences, $DB; // global preferences here because something else wants it :( define('BACKUP_SILENTLY', 1); - if (!$course = get_record('course', 'id', $courseid)) { + if (!$course = $DB->get_record('course', array('id'=>$courseid))) { debugging("Couldn't find course with id $courseid in backup_course_silently"); return false; } @@ -788,13 +769,13 @@ */ function backup_generate_preferences_artificially($course, $prefs) { - global $CFG; + global $CFG, $DB; $preferences = new StdClass; $preferences->backup_unique_code = time(); $preferences->backup_name = backup_get_zipfile_name($course, $preferences->backup_unique_code); $count = 0; - if ($allmods = get_records("modules") ) { + if ($allmods = $DB->get_records("modules") ) { foreach ($allmods as $mod) { $modname = $mod->name; $modfile = "$CFG->dirroot/mod/$modname/backuplib.php"; @@ -812,7 +793,7 @@ $preferences->$var = true; $count++; // check that there are instances and we can back them up individually - if (!count_records('course_modules','course',$course->id,'module',$mod->id) || !function_exists($modbackupone)) { + if (!$DB->count_records('course_modules', array('course'=>$course->id), array('module'=>$mod->id)) || !function_exists($modbackupone)) { continue; } $var = 'exists_one_'.$modname; diff --git a/backup/restore.php b/backup/restore.php index 37f1328fe2..18663c7091 100644 --- a/backup/restore.php +++ b/backup/restore.php @@ -117,7 +117,7 @@ //We are here, so me have a file. //Get and check course - if (! $course = get_record("course", "id", $id)) { + if (! $course = $DB->get_record("course", array("id"=>$id))) { print_error('invalidcourseid', '', '', $id); } diff --git a/backup/restore_check.html b/backup/restore_check.html index c49b46dbd0..429e410c51 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -5,6 +5,9 @@ //It puts all the restore info in the session. //Finally, it calls restore_execute to do the hard work //Get objects from session + + global $DB; + if ($SESSION) { $info = $SESSION->info; $course_header = $SESSION->course_header; @@ -60,7 +63,7 @@ //file $file = required_param( 'file'); //Checks for the required restoremod parameters - if ($allmods = get_records("modules")) { + if ($allmods = $DB->get_records("modules")) { foreach ($allmods as $mod) { $modname = $mod->name; $var = "restore_".$modname; @@ -109,7 +112,7 @@ //Create the restore object and put it in the session $restore->backup_unique_code = $backup_unique_code; $restore->file = $file; - if ($allmods = get_records("modules")) { + if ($allmods = $DB->get_records("modules")) { foreach ($allmods as $mod) { $modname = $mod->name; $var = "restore_".$modname; diff --git a/backup/restore_form.html b/backup/restore_form.html index f74428ba11..c8496efc73 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -4,6 +4,8 @@ //that contains the backup contents and depending of every mod //capabilities. + global $DB; + //Get objects from session if (!($info = $SESSION->info)) { print_error('sessionmissing' ,'debug', '', 'info'); @@ -41,7 +43,7 @@ //Checks for the required files/functions to restore every mod $count = 0; - 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"; @@ -295,7 +297,7 @@ function selectItemInCheckboxByName(formId, checkName, checked ) { //Line echo "
"; //Now, check modules and info and show posibilities - if ($allmods = get_records("modules") ) { + if ($allmods = $DB->get_records("modules") ) { //Print option to select/deselect everything with 1 click. echo ""; echo ""; @@ -601,7 +603,7 @@ $info = restore_read_xml_info($xml_file); // fix for MDL-9068, front page course is just a normal course $siterolesarray = get_assignable_roles (get_context_instance(CONTEXT_COURSE, $course->id), "shortname", ROLENAME_ORIGINAL); $siterolesnamearray = get_assignable_roles (get_context_instance(CONTEXT_COURSE, $course->id), "name", ROLENAME_ORIGINAL); -$allroles = get_records('role'); +$allroles = $DB->get_records('role'); echo (''); echo (''); @@ -717,20 +719,20 @@ echo ('
'.get_string('sourcerole').''.get_string('targetrole').'
'); // end of role mappings table * @param object $role the rest of the definition of the role from the backup file. */ function restore_samerole($roleid, $rolefromxml) { - global $CFG; + global $CFG, $DB; // First we try some intelligent guesses, then, if none of those work, we do a more extensive // search. // First guess, try let's use the id if (restore_is_samerole($roleid, $rolefromxml)) { - return get_record('role', 'id', $roleid); + return $DB->get_record('role', array('id'=>$roleid)); } // Second guess, try the shortname - $testroleid = get_field('role', 'id', 'shortname', $rolefromxml->shortname); + $testroleid = $DB->get_field('role', 'id', array('shortname'=>$rolefromxml->shortname)); if ($testroleid && restore_is_samerole($testroleid, $rolefromxml)) { - return get_record('role', 'id', $testroleid); + return $DB->get_record('role', array('id'=>$testroleid)); } // Finally, search all other roles. In orter to speed things up, we exclude the ones we have @@ -740,15 +742,16 @@ function restore_samerole($roleid, $rolefromxml) { if ($testroleid) { $extracondition = "AND roleid <> $testroleid"; } - $candidateroleids = get_records_sql("SELECT roleid - FROM {$CFG->prefix}role_capabilities - WHERE roleid <> $roleid $extracondition - GROUP BY roleid - HAVING COUNT(capability) = ".count($rolefromxml->capabilities)); + $candidateroleids = $DB->get_records_sql( + "SELECT roleid + FROM {role_capabilities} + WHERE roleid <> $roleid $extracondition + GROUP BY roleid + HAVING COUNT(capability) = ".count($rolefromxml->capabilities)); if (!empty($candidateroleids)) { foreach ($candidateroleids as $testroleid => $notused) { if (restore_is_samerole($testroleid, $rolefromxml)) { - return get_record('role', 'id', $testroleid); + return $DB->get_record('role', array('id'=>$testroleid)); } } } @@ -764,8 +767,10 @@ function restore_samerole($roleid, $rolefromxml) { * @return boolean true if the two roles are identical. */ function restore_is_samerole($testroleid, $rolefromxml) { + global $DB; + // Load the role definition from the databse. - $rolefromdb = get_records('role_capabilities', 'roleid', $testroleid, '', 'capability,permission'); + $rolefromdb = $DB->get_records('role_capabilities', array('roleid'=>$testroleid), '', 'capability,permission'); if (!$rolefromdb) { return false; } diff --git a/backup/try.php b/backup/try.php index ec4fc821d4..038f7b3fe8 100644 --- a/backup/try.php +++ b/backup/try.php @@ -25,7 +25,7 @@ $status = true; - $courses = get_records("course"); + $courses = $DB->get_records("course"); foreach ($courses as $course) { echo "Start course ". format_string($course->fullname); $preferences = schedule_backup_course_configure($course);