]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14679 towards /backup conversion
authorskodak <skodak>
Sun, 1 Jun 2008 14:46:48 +0000 (14:46 +0000)
committerskodak <skodak>
Sun, 1 Jun 2008 14:46:48 +0000 (14:46 +0000)
backup/backup.php
backup/backup_check.html
backup/backup_form.html
backup/backup_scheduled.php
backup/lib.php
backup/restore.php
backup/restore_check.html
backup/restore_form.html
backup/try.php

index 628972c331cbd6e682f4441d698e4f550d1633f2..861b122571c7f92f61249b0327a7e706b587b307 100644 (file)
@@ -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');
     }
 
index feb1d12079cc0022221fcbedc303c90f00838891..2ac3868270df681d523b0fde268907f0124a1629 100644 (file)
@@ -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;
     //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';
index fc1fe182536075978ef01d6d2cc45afd40968fe8..46b0d93e8bf8b00e4e4f220d95b90d02a706c9c8 100644 (file)
@@ -1,5 +1,6 @@
 <?php //$Id$
     //This page prints the backup form to select everything
+    global $DB;
 
     //Check login
     require_login();
@@ -28,7 +29,7 @@
     //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', 'visible', 1) ) {
+    if ($allmods = $DB_>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 "<tr>";
         echo "<td align=\"right\">";
@@ -331,7 +332,7 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
         echo "<td align=\"right\" valign=\"top\" colspan=\"2\"><b>";
         echo get_string("backuproleassignments");
         echo "</b></td><td colspan=\"2\">";
-        $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 "<br />";
index 0416ecfbb1dd3d1aba9f7ab7a925dc57bec5c418..a93404582dbceda13ff1c5a6ec707270a4604375 100644 (file)
@@ -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";
index 303a42f0860e619cb341774385857b37dc1b13ff..fac9292c9cfe383d1ffb1a5dcd05b07133519765 100644 (file)
@@ -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;
         $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);
 
     //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;
 
     //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;
     //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)) {
     //Little modifications done
 
     function backup_copy_file ($from_file,$to_file,$log_clam=false) {
-
         global $CFG;
 
         if (is_file($from_file)) {
     }
 
     function backup_copy_dir($from_file,$to_file) {
-
         global $CFG;
 
         $status = true; // Initialize this, next code will change its value if needed
     //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
 
             $info_to_save = "infile";
         } else {
             //Saving to db, addslashes
-            $info_to_save = addslashes($info_ser);
+            $info_to_save = $info_ser;
         }
 
         //Now, insert the record
             $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;
             }
         }
     //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") {
                     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);
                 }
      *   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();
         $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;
         }
         }
 
         // 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
     * @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;
         }
     */
 
     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";
                 $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;
index 37f1328fe2057071830d3f57fd69ce148ab89eb5..18663c70912a74d89d1d268f175b097025fe0f30 100644 (file)
     //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);
     }
 
index c49b46dbd0155628bd09922c66ed13ae7019a4e3..429e410c517bccfddd234e5040aedfdd9d71c05f 100644 (file)
@@ -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;
         //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;
index f74428ba1172d66b1d1d5924c6a0920b24a654e3..c8496efc73f7931775dff3e268af5c07842a57ca 100644 (file)
@@ -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 "<tr><td colspan=\"4\"><hr /></td></tr>";
     //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 "<tr>";
         echo "<td align=\"right\">";
@@ -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 ('<table width="100%" class="restore-form-instances">');
 echo ('<tr><td align="right" style="width:50%"><b>'.get_string('sourcerole').'</b></td><td align="left" style="width:50%"><b>'.get_string('targetrole').'</b></td></tr>');
@@ -717,20 +719,20 @@ echo ('</table>'); // 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;
     }
index ec4fc821d4c9a22ae8ec3dd4cf0d35df710b8fb8..038f7b3fe8481cea0f1d2cbcdfcc9e37c1d56354 100644 (file)
@@ -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);