2 //This file contains all the general function needed (file manipulation...)
3 //not directly part of the backup/restore utility plus some constants
5 // Define "restoreto" options
6 define('RESTORETO_CURRENT_DELETING', 0);
7 define('RESTORETO_CURRENT_ADDING', 1);
8 define('RESTORETO_NEW_COURSE', 2);
9 define('RESTORETO_EXISTING_DELETING', 3);
10 define('RESTORETO_EXISTING_ADDING', 4);
12 require_once($CFG->libdir . '/completionlib.php');
14 //Sets a name/value pair in config_plugin table
15 function backup_set_config($name, $value) {
16 return set_config($name, $value, 'backup');
19 //Gets all the information from config_plugin table
20 function backup_get_config() {
21 $backup_config = get_config('backup');
22 return (object)$backup_config;
25 //Delete old data in backup tables (if exists)
26 //Four hours seem to be appropiate now that backup is stable
27 function backup_delete_old_data() {
30 //Change this if you want !!
33 $seconds = $hours * 60 * 60;
34 $delete_from = time()-$seconds;
35 //Now delete from tables
36 $status = $DB->execute("DELETE FROM {backup_ids}
37 WHERE backup_code < ?", array($delete_from));
39 $status = $DB->execute("DELETE FROM {backup_files}
40 WHERE backup_code < ?", array($delete_from));
42 //Now, delete old directory (if exists)
44 $status = backup_delete_old_dirs($delete_from);
49 //Function to delete dirs/files into temp/backup directory
50 //older than $delete_from
51 function backup_delete_old_dirs($delete_from) {
56 //Get files and directories in the temp backup dir witout descend
57 $list = get_directory_list($CFG->dataroot."/temp/backup", "", false, true, true);
58 foreach ($list as $file) {
59 $file_path = $CFG->dataroot."/temp/backup/".$file;
60 $moddate = filemtime($file_path);
61 if ($status && $moddate < $delete_from) {
62 //If directory, recurse
63 if (is_dir($file_path)) {
64 $status = delete_dir_contents($file_path);
65 //There is nothing, delete the directory itself
67 $status = rmdir($file_path);
79 //Function to check and create the needed dir to
81 function check_and_create_backup_dir($backup_unique_code) {
84 $status = check_dir_exists($CFG->dataroot."/temp",true);
86 $status = check_dir_exists($CFG->dataroot."/temp/backup",true);
89 $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code,true);
95 //Function to delete all the directory contents recursively
96 //it supports a excluded dit too
97 //Copied from the web !!
98 function delete_dir_contents ($dir,$excludeddir="") {
102 // if we've been given a directory that doesn't exist yet, return true.
103 // this happens when we're trying to clear out a course that has only just
109 // Create arrays to store files and directories
110 $dir_files = array();
111 $dir_subdirs = array();
113 // Make sure we can delete it
114 chmod($dir, $CFG->directorypermissions);
116 if ((($handle = opendir($dir))) == FALSE) {
117 // The directory could not be opened
121 // Loop through all directory entries, and construct two temporary arrays containing files and sub directories
122 while(false !== ($entry = readdir($handle))) {
123 if (is_dir($dir. $slash .$entry) && $entry != ".." && $entry != "." && $entry != $excludeddir) {
124 $dir_subdirs[] = $dir. $slash .$entry;
126 else if ($entry != ".." && $entry != "." && $entry != $excludeddir) {
127 $dir_files[] = $dir. $slash .$entry;
131 // Delete all files in the curent directory return false and halt if a file cannot be removed
132 for($i=0; $i<count($dir_files); $i++) {
133 chmod($dir_files[$i], $CFG->directorypermissions);
134 if (((unlink($dir_files[$i]))) == FALSE) {
139 // Empty sub directories and then remove the directory
140 for($i=0; $i<count($dir_subdirs); $i++) {
141 chmod($dir_subdirs[$i], $CFG->directorypermissions);
142 if (delete_dir_contents($dir_subdirs[$i]) == FALSE) {
146 if (remove_dir($dir_subdirs[$i]) == FALSE) {
155 // Success, every thing is gone return true
159 //Function to clear (empty) the contents of the backup_dir
160 function clear_backup_dir($backup_unique_code) {
163 $rootdir = $CFG->dataroot."/temp/backup/".$backup_unique_code;
166 $status = delete_dir_contents($rootdir);
171 //Returns the module type of a course_module's id in a course
172 function get_module_type ($courseid,$moduleid) {
175 $results = $DB->get_records_sql("SELECT cm.id, m.name
176 FROM {course_modules} cm, {modules} m
177 WHERE cm.course = ? AND cm.id = ? AND
178 m.id = cm.module", array($courseid, $moduleid));
181 $name = $results[$moduleid]->name;
188 //This function return the names of all directories under a give directory
190 function list_directories ($rootdir) {
194 $dir = opendir($rootdir);
195 while (false !== ($file=readdir($dir))) {
196 if ($file=="." || $file=="..") {
199 if (is_dir($rootdir."/".$file)) {
200 $results[$file] = $file;
207 //This function return the names of all directories and files under a give directory
209 function list_directories_and_files ($rootdir) {
213 $dir = opendir($rootdir);
214 while (false !== ($file=readdir($dir))) {
215 if ($file=="." || $file=="..") {
218 $results[$file] = $file;
224 //This function clean data from backup tables and
225 //delete all temp files used
226 function clean_temp_data ($preferences) {
231 //true->do it, false->don't do it. To debug if necessary.
233 //Now delete from tables
234 $status = $DB->delete_records('backup_ids', array('backup_code'=>$preferences->backup_unique_code))
235 && $DB->delete_records('backup_files', array('backup_code'=>$preferences->backup_unique_code));
237 //Now, delete temp directory (if exists)
238 $file_path = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code;
239 if (is_dir($file_path)) {
240 $status = delete_dir_contents($file_path);
241 //There is nothing, delete the directory itself
243 $status = rmdir($file_path);
250 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
251 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
252 //This functions are used to copy any file or directory ($from_file)
253 //to a new file or directory ($to_file). It works recursively and
254 //mantains file perms.
255 //I've copied it from: http://www.php.net/manual/en/function.copy.php
256 //Little modifications done
258 function backup_copy_file ($from_file,$to_file,$log_clam=false) {
261 if (is_file($from_file)) {
262 //echo "<br />Copying ".$from_file." to ".$to_file; //Debug
263 //$perms=fileperms($from_file);
264 //return copy($from_file,$to_file) && chmod($to_file,$perms);
266 if (copy($from_file,$to_file)) {
267 chmod($to_file,$CFG->directorypermissions);
268 if (!empty($log_clam)) {
269 //clam_log_upload($to_file,null,true);
275 else if (is_dir($from_file)) {
276 return backup_copy_dir($from_file,$to_file);
279 //echo "<br />Error: not file or dir ".$from_file; //Debug
284 function backup_copy_dir($from_file,$to_file) {
287 $status = true; // Initialize this, next code will change its value if needed
289 if (!is_dir($to_file)) {
290 //echo "<br />Creating ".$to_file; //Debug
292 $status = mkdir($to_file,$CFG->directorypermissions);
294 $dir = opendir($from_file);
295 while (false !== ($file=readdir($dir))) {
296 if ($file=="." || $file=="..") {
299 $status = backup_copy_file ("$from_file/$file","$to_file/$file");
304 ///Ends copy file/dirs functions
305 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
306 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
309 * Are we restoring a backup that was made on the same site that we are restoring to?
310 * This relies on some information that was only added to backup files in January 2009.
311 * For older backup files, fall back to guessing based on wwwroot. MDL-16614 explains
312 * when this guess could give the wrong answer.
313 * @return boolean true if the backup was made on the same site we are restoring to.
315 function backup_is_same_site(&$restore) {
317 static $hashedsiteid = null;
318 if (is_null($hashedsiteid)) {
319 $hashedsiteid = md5(get_site_identifier());
321 if (!empty($restore->original_siteidentifier)) {
322 return $restore->original_siteidentifier == $hashedsiteid;
324 return $restore->original_wwwroot == $CFG->wwwroot;
328 //This function is used to insert records in the backup_ids table
329 //If the info field is greater than max_db_storage, then its info
330 //is saved to filesystem
331 function backup_putid($backup_unique_code, $table, $old_id, $new_id, $info="") {
334 $max_db_storage = 128; //Max bytes to save to db, else save to file
338 //First delete to avoid PK duplicates
339 $status = backup_delid($backup_unique_code, $table, $old_id);
341 //Now, serialize info
342 $info_ser = serialize($info);
344 //Now, if the size of $info_ser > $max_db_storage, save it to filesystem and
345 //insert a "infile" in the info field
347 if (strlen($info_ser) > $max_db_storage) {
348 //Calculate filename (in current_backup_dir, $backup_unique_code_$table_$old_id.info)
349 $filename = $CFG->dataroot."/temp/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
351 $status = backup_data2file($filename,$info_ser);
353 $info_to_save = "infile";
356 $info_to_save = $info_ser;
359 //Now, insert the record
362 $rec = new stdClass();
363 $rec->backup_code = $backup_unique_code;
364 $rec->table_name = $table;
365 $rec->old_id = $old_id;
366 $rec->new_id = ($new_id === null? 0 : $new_id);
367 $rec->info = $info_to_save;
369 $DB->insert_record('backup_ids', $rec, false);
374 //This function is used to delete recods from the backup_ids table
375 //If the info field is "infile" then the file is deleted too
376 function backup_delid ($backup_unique_code, $table, $old_id) {
378 return $DB->delete_records('backup_ids', array('backup_code'=>$backup_unique_code, 'table_name'=>$table, 'old_id'=>$old_id));
381 //This function is used to get a record from the backup_ids table
382 //If the info field is "infile" then its info
383 //is read from filesystem
384 function backup_getid ($backup_unique_code, $table, $old_id) {
390 $status = $DB->get_record("backup_ids", array("backup_code"=>$backup_unique_code,
391 "table_name"=>$table, "old_id"=>$old_id));
393 //If info field = "infile", get file contents
394 if (!empty($status->info) && $status->info == "infile") {
395 $filename = $CFG->dataroot."/temp/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
396 //Read data from file
397 $status2 = backup_file2data($filename,$info);
400 $status->info = unserialize($info);
405 //Only if status (record exists)
406 if (!empty($status->info)) {
407 if ($status->info === 'needed') {
408 // TODO: ugly hack - fix before 1.9.1
409 debugging('Incorrect string "needed" in $status->info, please fix the code (table:'.$table.'; old_id:'.$old_id.').', DEBUG_DEVELOPER);
411 ////First strip slashes
412 $temp = $status->info;
414 $status->info = unserialize($temp);
422 //This function is used to add slashes (and decode from UTF-8 if needed)
423 //It's used intensivelly when restoring modules and saving them in db
424 function backup_todb ($data) {
426 if ($data === '$@NULL@$') {
429 return restore_decode_absolute_links($data);
433 //This function is used to check that every necessary function to
434 //backup/restore exists in the current php installation. Thanks to
435 //gregb@crowncollege.edu by the idea.
436 function backup_required_functions($justcheck=false) {
438 if(!function_exists('utf8_encode')) {
439 if (empty($justcheck)) {
440 print_error('needphpext', '', '', 'XML');
449 //This function send n white characters to the browser and flush the
450 //output buffer. Used to avoid browser timeouts and to show the progress.
451 function backup_flush($n=0,$time=false) {
452 if (defined('RESTORE_SILENTLY_NOFLUSH')) {
456 $ti = strftime("%X",time());
460 echo str_repeat(" ", $n) . $ti . "\n";
464 //This function creates the filename and write data to it
465 //returning status as result
466 function backup_data2file ($file,&$data) {
471 $f = fopen($file,"w");
472 $status = fwrite($f,$data);
473 $status2 = fclose($f);
475 return ($status && $status2);
478 //This function read the filename and read data from it
479 function backup_file2data ($file,&$data) {
484 $f = fopen($file,"r");
485 $data = fread ($f,filesize($file));
486 $status2 = fclose($f);
488 return ($status && $status2);
491 /** this function will restore an entire backup.zip into the specified course
492 * using standard moodle backup/restore functions, but silently.
493 * @param string $pathtofile the absolute path to the backup file.
494 * @param int $destinationcourse the course id to restore to.
495 * @param boolean $emptyfirst whether to delete all coursedata first.
496 * @param boolean $userdata whether to include any userdata that may be in the backup file.
497 * @param array $preferences optional, 0 will be used. Can contain:
503 function import_backup_file_silently($pathtofile,$destinationcourse,$emptyfirst=false,$userdata=false, $preferences=array()) {
504 global $CFG,$SESSION,$USER, $DB; // is there such a thing on cron? I guess so..
506 if (!defined('RESTORE_SILENTLY')) {
507 define('RESTORE_SILENTLY',true); // don't output all the stuff to us.
510 $debuginfo = 'import_backup_file_silently: ';
511 $cleanupafter = false;
512 $errorstr = ''; // passed by reference to restore_precheck to get errors from.
515 if ($destinationcourse && !$course = $DB->get_record('course', array('id'=>$destinationcourse))) {
516 mtrace($debuginfo.'Course with id $destinationcourse was not a valid course!');
520 // first check we have a valid file.
521 if (!file_exists($pathtofile) || !is_readable($pathtofile)) {
522 mtrace($debuginfo.'File '.$pathtofile.' either didn\'t exist or wasn\'t readable');
526 // now make sure it's a zip file
527 require_once($CFG->dirroot.'/lib/filelib.php');
528 $filename = substr($pathtofile,strrpos($pathtofile,'/')+1);
529 $mimetype = mimeinfo("type", $filename);
530 if ($mimetype != 'application/zip') {
531 mtrace($debuginfo.'File '.$pathtofile.' was of wrong mimetype ('.$mimetype.')' );
535 // restore_precheck wants this within dataroot, so lets put it there if it's not already..
536 if (strstr($pathtofile,$CFG->dataroot) === false) {
537 // first try and actually move it..
538 if (!check_dir_exists($CFG->dataroot.'/temp/backup/',true)) {
539 mtrace($debuginfo.'File '.$pathtofile.' outside of dataroot and couldn\'t move it! ');
542 if (!copy($pathtofile,$CFG->dataroot.'/temp/backup/'.$filename)) {
543 mtrace($debuginfo.'File '.$pathtofile.' outside of dataroot and couldn\'t move it! ');
546 $pathtofile = 'temp/backup/'.$filename;
547 $cleanupafter = true;
550 // it is within dataroot, so take it off the path for restore_precheck.
551 $pathtofile = substr($pathtofile,strlen($CFG->dataroot.'/'));
554 if (!backup_required_functions()) {
555 mtrace($debuginfo.'Required function check failed (see backup_required_functions)');
558 @ini_set("max_execution_time","3000");
559 if (empty($CFG->extramemorylimit)) {
560 raise_memory_limit('128M');
562 raise_memory_limit($CFG->extramemorylimit);
565 if (!$backup_unique_code = restore_precheck($destinationcourse,$pathtofile,$errorstr,true)) {
566 mtrace($debuginfo.'Failed restore_precheck (error was '.$errorstr.')');
570 global $restore; // ick
571 $restore = new StdClass;
572 // copy back over the stuff that gets set in restore_precheck
573 $restore->course_header = $SESSION->course_header;
574 $restore->info = $SESSION->info;
576 $xmlfile = "$CFG->dataroot/temp/backup/$backup_unique_code/moodle.xml";
577 $info = restore_read_xml_roles($xmlfile);
578 $restore->rolesmapping = array();
579 if (isset($info->roles) && is_array($info->roles)) {
580 foreach ($info->roles as $id => $info) {
581 if ($newroleid = $DB->get_field('role', 'id', array('shortname' => $info->shortname))) {
582 $restore->rolesmapping[$id] = $newroleid;
587 // add on some extra stuff we need...
588 $restore->metacourse = (isset($preferences['restore_metacourse']) ? $preferences['restore_metacourse'] : 0);
589 $restore->course_id = $destinationcourse;
590 if ($destinationcourse) {
591 $restore->restoreto = RESTORETO_CURRENT_ADDING;
592 $restore->course_startdateoffset = $course->startdate - $restore->course_header->course_startdate;
594 $restore->restoreto = RESTORETO_NEW_COURSE;
595 $restore->restore_restorecatto = 0; // let this be handled by the headers
596 $restore->course_startdateoffset = 0;
600 $restore->users = $userdata;
601 $restore->user_files = $userdata;
602 $restore->deleting = $emptyfirst;
604 $restore->groups = (isset($preferences['restore_groups']) ? $preferences['restore_groups'] : RESTORE_GROUPS_NONE);
605 $restore->logs = (isset($preferences['restore_logs']) ? $preferences['restore_logs'] : 0);
606 $restore->messages = (isset($preferences['restore_messages']) ? $preferences['restore_messages'] : 0);
607 $restore->blogs = (isset($preferences['restore_blogs']) ? $preferences['restore_blogs'] : 0);
608 $restore->course_files = (isset($preferences['restore_course_files']) ? $preferences['restore_course_files'] : 0);
609 $restore->site_files = (isset($preferences['restore_site_files']) ? $preferences['restore_site_files'] : 0);
611 $restore->backup_version = $restore->info->backup_backup_version;
612 $restore->original_wwwroot = $restore->info->original_wwwroot;
614 // now copy what we have over to the session
615 // this needs to happen before restore_setup_for_check
616 // which for some reason reads the session
617 $SESSION->restore =& $restore;
618 // rename the things that are called differently
619 $SESSION->restore->restore_course_files = $restore->course_files;
620 $SESSION->restore->restore_site_files = $restore->site_files;
621 $SESSION->restore->backup_version = $restore->info->backup_backup_version;
623 restore_setup_for_check($restore, $backup_unique_code);
625 // maybe we need users (defaults to 2 (none) in restore_setup_for_check)
626 // so set this again here
627 if (!empty($userdata)) {
631 // we also need modules...
632 if ($allmods = $DB->get_records("modules")) {
633 foreach ($allmods as $mod) {
634 $modname = $mod->name;
635 //Now check that we have that module info in the backup file
636 if (isset($restore->info->mods[$modname]) && $restore->info->mods[$modname]->backup == "true") {
637 $restore->mods[$modname]->restore = true;
638 $restore->mods[$modname]->userinfo = $userdata;
642 $restore->mods[$modname]->restore = false;
643 $restore->mods[$modname]->userinfo = false;
647 if (!$status = restore_execute($restore,$restore->info,$restore->course_header,$errorstr)) {
648 mtrace($debuginfo.'Failed restore_execute (error was '.$errorstr.')');
651 // now get out the new courseid and return that
652 if ($restore->restoreto = RESTORETO_NEW_COURSE) {
653 if (!empty($SESSION->restore->course_id)) {
654 return $SESSION->restore->course_id;
662 * Function to backup an entire course silently and create a zipfile.
664 * @param int $courseid the id of the course
665 * @param array $prefs see {@link backup_generate_preferences_artificially}
667 function backup_course_silently($courseid, $prefs, &$errorstring) {
668 global $CFG, $preferences, $DB; // global preferences here because something else wants it :(
669 if (!defined('BACKUP_SILENTLY')) {
670 define('BACKUP_SILENTLY', 1);
672 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
673 debugging("Couldn't find course with id $courseid in backup_course_silently");
676 $preferences = backup_generate_preferences_artificially($course, $prefs);
677 $preferences->destination = array_key_exists('destination', $prefs) ? $prefs['destination'] : 0;
678 if (backup_execute($preferences, $errorstring)) {
679 return $CFG->dataroot . '/' . $course->id . '/backupdata/' . $preferences->backup_name;
687 * Function to generate the $preferences variable that
688 * backup uses. This will back up all modules and instances in a course.
690 * @param object $course course object
691 * @param array $prefs can contain:
700 * and if not provided, they will not be included.
703 function backup_generate_preferences_artificially($course, $prefs) {
705 $preferences = new StdClass;
706 $preferences->backup_unique_code = time();
707 $preferences->backup_users = (isset($prefs['backup_users']) ? $prefs['backup_users'] : 0);
708 $preferences->backup_name = backup_get_zipfile_name($course, $preferences->backup_unique_code);
709 $preferences->mods = array();
712 if ($allmods = $DB->get_records("modules") ) {
713 foreach ($allmods as $mod) {
714 $modname = $mod->name;
715 $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
716 $modbackup = $modname."_backup_mods";
717 $modbackupone = $modname."_backup_one_mod";
718 $modcheckbackup = $modname."_check_backup_mods";
719 if (!file_exists($modfile)) {
722 include_once($modfile);
723 if (!function_exists($modbackup) || !function_exists($modcheckbackup)) {
726 $var = "exists_".$modname;
727 $preferences->$var = true;
729 // check that there are instances and we can back them up individually
730 if (!$DB->count_records('course_modules', array('course'=>$course->id), array('module'=>$mod->id)) || !function_exists($modbackupone)) {
733 $var = 'exists_one_'.$modname;
734 $preferences->$var = true;
735 $varname = $modname.'_instances';
736 $preferences->$varname = get_all_instances_in_course($modname, $course, NULL, true);
737 foreach ($preferences->$varname as $instance) {
738 $preferences->mods[$modname]->instances[$instance->id]->name = $instance->name;
739 $var = 'backup_'.$modname.'_instance_'.$instance->id;
740 $preferences->$var = true;
741 $preferences->mods[$modname]->instances[$instance->id]->backup = true;
742 $var = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
743 $preferences->$var = (!array_key_exists('userdata', $prefs) || $prefs['userdata']);
744 $preferences->mods[$modname]->instances[$instance->id]->userinfo = $preferences->$var;
745 $var = 'backup_'.$modname.'_instances';
746 $preferences->$var = 1; // we need this later to determine what to display in modcheckbackup.
751 $preferences->mods[$modname]->name = $modname;
753 $var = "backup_".$modname;
754 $preferences->$var = true;
755 $preferences->mods[$modname]->backup = true;
757 //Check include user info
758 $var = "backup_user_info_".$modname;
759 $preferences->$var = (!array_key_exists('userdata', $prefs) || $prefs['userdata']);
760 $preferences->mods[$modname]->userinfo = $preferences->$var;
762 //Call the check function to show more info
763 $modcheckbackup = $modname."_check_backup_mods";
764 $var = $modname.'_instances';
765 $instancestopass = array();
766 if (!empty($preferences->$var) && is_array($preferences->$var) && count($preferences->$var)) {
767 $table->data = array();
769 foreach ($preferences->$var as $instance) {
770 $var1 = 'backup_'.$modname.'_instance_'.$instance->id;
771 $var2 = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
772 if (!empty($preferences->$var1)) {
774 $obj->name = $instance->name;
775 $obj->userdata = $preferences->$var2;
776 $obj->id = $instance->id;
777 $instancestopass[$instance->id]= $obj;
783 $modcheckbackup($course->id,$preferences->$var,$preferences->backup_unique_code,$instancestopass);
787 //Check other parameters
788 $preferences->backup_metacourse = (isset($prefs['backup_metacourse']) ? $prefs['backup_metacourse'] : 0);
789 $preferences->backup_logs = (isset($prefs['backup_logs']) ? $prefs['backup_logs'] : 0);
790 $preferences->backup_user_files = (isset($prefs['backup_user_files']) ? $prefs['backup_user_files'] : 0);
791 $preferences->backup_course_files = (isset($prefs['backup_course_files']) ? $prefs['backup_course_files'] : 0);
792 $preferences->backup_site_files = (isset($prefs['backup_site_files']) ? $prefs['backup_site_files'] : 0);
793 $preferences->backup_messages = (isset($prefs['backup_messages']) ? $prefs['backup_messages'] : 0);
794 $preferences->backup_gradebook_history = (isset($prefs['backup_gradebook_history']) ? $prefs['backup_gradebook_history'] : 0);
795 $preferences->backup_blogs = (isset($prefs['backup_blogs']) ? $prefs['backup_blogs'] : 0);
796 $preferences->backup_course = $course->id;
799 user_check_backup($course->id,$preferences->backup_unique_code,$preferences->backup_users,$preferences->backup_messages, $preferences->backup_blogs);
802 log_check_backup($course->id);
805 user_files_check_backup($course->id,$preferences->backup_unique_code);
808 course_files_check_backup($course->id,$preferences->backup_unique_code);
811 site_files_check_backup($course->id,$preferences->backup_unique_code);
814 $roles = $DB->get_records('role', null, 'sortorder');
815 foreach ($roles as $role) {
816 $preferences->backuproleassignments[$role->id] = $role;
819 backup_add_static_preferences($preferences);
822 function add_to_backup_log($starttime,$courseid,$message, $backuptype) {
824 $log = new stdClass();
825 $log->courseid = $courseid;
827 $log->laststarttime = $starttime;
828 $log->info = $message;
829 $log->backuptype = $backuptype;
830 $DB->insert_record('backup_log', $log);