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="") {
101 // if we've been given a directory that doesn't exist yet, return true.
102 // this happens when we're trying to clear out a course that has only just
108 // Create arrays to store files and directories
109 $dir_files = array();
110 $dir_subdirs = array();
112 // Make sure we can delete it
115 if ((($handle = opendir($dir))) == FALSE) {
116 // The directory could not be opened
120 // Loop through all directory entries, and construct two temporary arrays containing files and sub directories
121 while(false !== ($entry = readdir($handle))) {
122 if (is_dir($dir. $slash .$entry) && $entry != ".." && $entry != "." && $entry != $excludeddir) {
123 $dir_subdirs[] = $dir. $slash .$entry;
125 else if ($entry != ".." && $entry != "." && $entry != $excludeddir) {
126 $dir_files[] = $dir. $slash .$entry;
130 // Delete all files in the curent directory return false and halt if a file cannot be removed
131 for($i=0; $i<count($dir_files); $i++
) {
132 chmod($dir_files[$i], 0777);
133 if (((unlink($dir_files[$i]))) == FALSE) {
138 // Empty sub directories and then remove the directory
139 for($i=0; $i<count($dir_subdirs); $i++
) {
140 chmod($dir_subdirs[$i], 0777);
141 if (delete_dir_contents($dir_subdirs[$i]) == FALSE) {
145 if (remove_dir($dir_subdirs[$i]) == FALSE) {
154 // Success, every thing is gone return true
158 //Function to clear (empty) the contents of the backup_dir
159 function clear_backup_dir($backup_unique_code) {
162 $rootdir = $CFG->dataroot
."/temp/backup/".$backup_unique_code;
165 $status = delete_dir_contents($rootdir);
170 //Returns the module type of a course_module's id in a course
171 function get_module_type ($courseid,$moduleid) {
174 $results = $DB->get_records_sql("SELECT cm.id, m.name
175 FROM {course_modules} cm, {modules} m
176 WHERE cm.course = ? AND cm.id = ? AND
177 m.id = cm.module", array($courseid, $moduleid));
180 $name = $results[$moduleid]->name
;
187 //This function return the names of all directories under a give directory
189 function list_directories ($rootdir) {
193 $dir = opendir($rootdir);
194 while (false !== ($file=readdir($dir))) {
195 if ($file=="." ||
$file=="..") {
198 if (is_dir($rootdir."/".$file)) {
199 $results[$file] = $file;
206 //This function return the names of all directories and files under a give directory
208 function list_directories_and_files ($rootdir) {
212 $dir = opendir($rootdir);
213 while (false !== ($file=readdir($dir))) {
214 if ($file=="." ||
$file=="..") {
217 $results[$file] = $file;
223 //This function clean data from backup tables and
224 //delete all temp files used
225 function clean_temp_data ($preferences) {
230 //true->do it, false->don't do it. To debug if necessary.
232 //Now delete from tables
233 $status = $DB->delete_records('backup_ids', array('backup_code'=>$preferences->backup_unique_code
))
234 && $DB->delete_records('backup_files', array('backup_code'=>$preferences->backup_unique_code
));
236 //Now, delete temp directory (if exists)
237 $file_path = $CFG->dataroot
."/temp/backup/".$preferences->backup_unique_code
;
238 if (is_dir($file_path)) {
239 $status = delete_dir_contents($file_path);
240 //There is nothing, delete the directory itself
242 $status = rmdir($file_path);
249 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
250 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
251 //This functions are used to copy any file or directory ($from_file)
252 //to a new file or directory ($to_file). It works recursively and
253 //mantains file perms.
254 //I've copied it from: http://www.php.net/manual/en/function.copy.php
255 //Little modifications done
257 function backup_copy_file ($from_file,$to_file,$log_clam=false) {
260 if (is_file($from_file)) {
261 //echo "<br />Copying ".$from_file." to ".$to_file; //Debug
262 //$perms=fileperms($from_file);
263 //return copy($from_file,$to_file) && chmod($to_file,$perms);
265 if (copy($from_file,$to_file)) {
266 chmod($to_file,$CFG->directorypermissions
);
267 if (!empty($log_clam)) {
268 //clam_log_upload($to_file,null,true);
274 else if (is_dir($from_file)) {
275 return backup_copy_dir($from_file,$to_file);
278 //echo "<br />Error: not file or dir ".$from_file; //Debug
283 function backup_copy_dir($from_file,$to_file) {
286 $status = true; // Initialize this, next code will change its value if needed
288 if (!is_dir($to_file)) {
289 //echo "<br />Creating ".$to_file; //Debug
291 $status = mkdir($to_file,$CFG->directorypermissions
);
293 $dir = opendir($from_file);
294 while (false !== ($file=readdir($dir))) {
295 if ($file=="." ||
$file=="..") {
298 $status = backup_copy_file ("$from_file/$file","$to_file/$file");
303 ///Ends copy file/dirs functions
304 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
305 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
308 * Are we restoring a backup that was made on the same site that we are restoring to?
309 * This relies on some information that was only added to backup files in January 2009.
310 * For older backup files, fall back to guessing based on wwwroot. MDL-16614 explains
311 * when this guess could give the wrong answer.
312 * @return boolean true if the backup was made on the same site we are restoring to.
314 function backup_is_same_site(&$restore) {
316 static $hashedsiteid = null;
317 if (is_null($hashedsiteid)) {
318 $hashedsiteid = md5(get_site_identifier());
320 if (!empty($restore->original_siteidentifier
)) {
321 return $restore->original_siteidentifier
== $hashedsiteid;
323 return $restore->original_wwwroot
== $CFG->wwwroot
;
327 //This function is used to insert records in the backup_ids table
328 //If the info field is greater than max_db_storage, then its info
329 //is saved to filesystem
330 function backup_putid($backup_unique_code, $table, $old_id, $new_id, $info="") {
333 $max_db_storage = 128; //Max bytes to save to db, else save to file
337 //First delete to avoid PK duplicates
338 $status = backup_delid($backup_unique_code, $table, $old_id);
340 //Now, serialize info
341 $info_ser = serialize($info);
343 //Now, if the size of $info_ser > $max_db_storage, save it to filesystem and
344 //insert a "infile" in the info field
346 if (strlen($info_ser) > $max_db_storage) {
347 //Calculate filename (in current_backup_dir, $backup_unique_code_$table_$old_id.info)
348 $filename = $CFG->dataroot
."/temp/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
350 $status = backup_data2file($filename,$info_ser);
352 $info_to_save = "infile";
355 $info_to_save = $info_ser;
358 //Now, insert the record
362 $rec->backup_code
= $backup_unique_code;
363 $rec->table_name
= $table;
364 $rec->old_id
= $old_id;
365 $rec->new_id
= ($new_id === null?
0 : $new_id);
366 $rec->info
= $info_to_save;
368 $DB->insert_record('backup_ids', $rec, false);
373 //This function is used to delete recods from the backup_ids table
374 //If the info field is "infile" then the file is deleted too
375 function backup_delid ($backup_unique_code, $table, $old_id) {
377 return $DB->delete_records('backup_ids', array('backup_code'=>$backup_unique_code, 'table_name'=>$table, 'old_id'=>$old_id));
380 //This function is used to get a record from the backup_ids table
381 //If the info field is "infile" then its info
382 //is read from filesystem
383 function backup_getid ($backup_unique_code, $table, $old_id) {
389 $status = $DB->get_record("backup_ids", array("backup_code"=>$backup_unique_code,
390 "table_name"=>$table, "old_id"=>$old_id));
392 //If info field = "infile", get file contents
393 if (!empty($status->info
) && $status->info
== "infile") {
394 $filename = $CFG->dataroot
."/temp/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
395 //Read data from file
396 $status2 = backup_file2data($filename,$info);
399 $status->info
= unserialize($info);
404 //Only if status (record exists)
405 if (!empty($status->info
)) {
406 if ($status->info
=== 'needed') {
407 // TODO: ugly hack - fix before 1.9.1
408 debugging('Incorrect string "needed" in $status->info, please fix the code (table:'.$table.'; old_id:'.$old_id.').', DEBUG_DEVELOPER
);
410 ////First strip slashes
411 $temp = $status->info
;
413 $status->info
= unserialize($temp);
421 //This function is used to add slashes (and decode from UTF-8 if needed)
422 //It's used intensivelly when restoring modules and saving them in db
423 function backup_todb ($data) {
425 if ($data === '$@NULL@$') {
428 return restore_decode_absolute_links($data);
432 //This function is used to check that every necessary function to
433 //backup/restore exists in the current php installation. Thanks to
434 //gregb@crowncollege.edu by the idea.
435 function backup_required_functions($justcheck=false) {
437 if(!function_exists('utf8_encode')) {
438 if (empty($justcheck)) {
439 print_error('needphpext', '', '', 'XML');
448 //This function send n white characters to the browser and flush the
449 //output buffer. Used to avoid browser timeouts and to show the progress.
450 function backup_flush($n=0,$time=false) {
451 if (defined('RESTORE_SILENTLY_NOFLUSH')) {
455 $ti = strftime("%X",time());
459 echo str_repeat(" ", $n) . $ti . "\n";
463 //This function creates the filename and write data to it
464 //returning status as result
465 function backup_data2file ($file,&$data) {
470 $f = fopen($file,"w");
471 $status = fwrite($f,$data);
472 $status2 = fclose($f);
474 return ($status && $status2);
477 //This function read the filename and read data from it
478 function backup_file2data ($file,&$data) {
483 $f = fopen($file,"r");
484 $data = fread ($f,filesize($file));
485 $status2 = fclose($f);
487 return ($status && $status2);
490 /** this function will restore an entire backup.zip into the specified course
491 * using standard moodle backup/restore functions, but silently.
492 * @param string $pathtofile the absolute path to the backup file.
493 * @param int $destinationcourse the course id to restore to.
494 * @param boolean $emptyfirst whether to delete all coursedata first.
495 * @param boolean $userdata whether to include any userdata that may be in the backup file.
496 * @param array $preferences optional, 0 will be used. Can contain:
502 function import_backup_file_silently($pathtofile,$destinationcourse,$emptyfirst=false,$userdata=false, $preferences=array()) {
503 global $CFG,$SESSION,$USER, $DB; // is there such a thing on cron? I guess so..
505 if (!defined('RESTORE_SILENTLY')) {
506 define('RESTORE_SILENTLY',true); // don't output all the stuff to us.
509 $debuginfo = 'import_backup_file_silently: ';
510 $cleanupafter = false;
511 $errorstr = ''; // passed by reference to restore_precheck to get errors from.
514 if ($destinationcourse && !$course = $DB->get_record('course', array('id'=>$destinationcourse))) {
515 mtrace($debuginfo.'Course with id $destinationcourse was not a valid course!');
519 // first check we have a valid file.
520 if (!file_exists($pathtofile) ||
!is_readable($pathtofile)) {
521 mtrace($debuginfo.'File '.$pathtofile.' either didn\'t exist or wasn\'t readable');
525 // now make sure it's a zip file
526 require_once($CFG->dirroot
.'/lib/filelib.php');
527 $filename = substr($pathtofile,strrpos($pathtofile,'/')+
1);
528 $mimetype = mimeinfo("type", $filename);
529 if ($mimetype != 'application/zip') {
530 mtrace($debuginfo.'File '.$pathtofile.' was of wrong mimetype ('.$mimetype.')' );
534 // restore_precheck wants this within dataroot, so lets put it there if it's not already..
535 if (strstr($pathtofile,$CFG->dataroot
) === false) {
536 // first try and actually move it..
537 if (!check_dir_exists($CFG->dataroot
.'/temp/backup/',true)) {
538 mtrace($debuginfo.'File '.$pathtofile.' outside of dataroot and couldn\'t move it! ');
541 if (!copy($pathtofile,$CFG->dataroot
.'/temp/backup/'.$filename)) {
542 mtrace($debuginfo.'File '.$pathtofile.' outside of dataroot and couldn\'t move it! ');
545 $pathtofile = 'temp/backup/'.$filename;
546 $cleanupafter = true;
549 // it is within dataroot, so take it off the path for restore_precheck.
550 $pathtofile = substr($pathtofile,strlen($CFG->dataroot
.'/'));
553 if (!backup_required_functions()) {
554 mtrace($debuginfo.'Required function check failed (see backup_required_functions)');
557 @ini_set
("max_execution_time","3000");
558 if (empty($CFG->extramemorylimit
)) {
559 raise_memory_limit('128M');
561 raise_memory_limit($CFG->extramemorylimit
);
564 if (!$backup_unique_code = restore_precheck($destinationcourse,$pathtofile,$errorstr,true)) {
565 mtrace($debuginfo.'Failed restore_precheck (error was '.$errorstr.')');
569 global $restore; // ick
570 $restore = new StdClass
;
571 // copy back over the stuff that gets set in restore_precheck
572 $restore->course_header
= $SESSION->course_header
;
573 $restore->info
= $SESSION->info
;
575 $xmlfile = "$CFG->dataroot/temp/backup/$backup_unique_code/moodle.xml";
576 $info = restore_read_xml_roles($xmlfile);
577 $restore->rolesmapping
= array();
578 if (isset($info->roles
) && is_array($info->roles
)) {
579 foreach ($info->roles
as $id => $info) {
580 if ($newroleid = get_field('role', 'id', 'shortname', $info->shortname
)) {
581 $restore->rolesmapping
[$id] = $newroleid;
586 // add on some extra stuff we need...
587 $restore->metacourse
= (isset($preferences['restore_metacourse']) ?
$preferences['restore_metacourse'] : 0);
588 $restore->course_id
= $destinationcourse;
589 if ($destinationcourse) {
590 $restore->restoreto
= RESTORETO_CURRENT_ADDING
;
591 $restore->course_startdateoffset
= $course->startdate
- $restore->course_header
->course_startdate
;
593 $restore->restoreto
= RESTORETO_NEW_COURSE
;
594 $restore->restore_restorecatto
= 0; // let this be handled by the headers
595 $restore->course_startdateoffset
= 0;
599 $restore->users
= $userdata;
600 $restore->user_files
= $userdata;
601 $restore->deleting
= $emptyfirst;
603 $restore->groups
= (isset($preferences['restore_groups']) ?
$preferences['restore_groups'] : RESTORE_GROUPS_NONE
);
604 $restore->logs
= (isset($preferences['restore_logs']) ?
$preferences['restore_logs'] : 0);
605 $restore->messages
= (isset($preferences['restore_messages']) ?
$preferences['restore_messages'] : 0);
606 $restore->blogs
= (isset($preferences['restore_blogs']) ?
$preferences['restore_blogs'] : 0);
607 $restore->course_files
= (isset($preferences['restore_course_files']) ?
$preferences['restore_course_files'] : 0);
608 $restore->site_files
= (isset($preferences['restore_site_files']) ?
$preferences['restore_site_files'] : 0);
610 $restore->backup_version
= $restore->info
->backup_backup_version
;
611 $restore->original_wwwroot
= $restore->info
->original_wwwroot
;
613 // now copy what we have over to the session
614 // this needs to happen before restore_setup_for_check
615 // which for some reason reads the session
616 $SESSION->restore
=& $restore;
617 // rename the things that are called differently
618 $SESSION->restore
->restore_course_files
= $restore->course_files
;
619 $SESSION->restore
->restore_site_files
= $restore->site_files
;
620 $SESSION->restore
->backup_version
= $restore->info
->backup_backup_version
;
622 restore_setup_for_check($restore, $backup_unique_code);
624 // maybe we need users (defaults to 2 (none) in restore_setup_for_check)
625 // so set this again here
626 if (!empty($userdata)) {
630 // we also need modules...
631 if ($allmods = $DB->get_records("modules")) {
632 foreach ($allmods as $mod) {
633 $modname = $mod->name
;
634 //Now check that we have that module info in the backup file
635 if (isset($restore->info
->mods
[$modname]) && $restore->info
->mods
[$modname]->backup
== "true") {
636 $restore->mods
[$modname]->restore
= true;
637 $restore->mods
[$modname]->userinfo
= $userdata;
641 $restore->mods
[$modname]->restore
= false;
642 $restore->mods
[$modname]->userinfo
= false;
646 if (!$status = restore_execute($restore,$restore->info
,$restore->course_header
,$errorstr)) {
647 mtrace($debuginfo.'Failed restore_execute (error was '.$errorstr.')');
650 // now get out the new courseid and return that
651 if ($restore->restoreto
= RESTORETO_NEW_COURSE
) {
652 if (!empty($SESSION->restore
->course_id
)) {
653 return $SESSION->restore
->course_id
;
661 * Function to backup an entire course silently and create a zipfile.
663 * @param int $courseid the id of the course
664 * @param array $prefs see {@link backup_generate_preferences_artificially}
666 function backup_course_silently($courseid, $prefs, &$errorstring) {
667 global $CFG, $preferences, $DB; // global preferences here because something else wants it :(
668 if (!defined('BACKUP_SILENTLY')) {
669 define('BACKUP_SILENTLY', 1);
671 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
672 debugging("Couldn't find course with id $courseid in backup_course_silently");
675 $preferences = backup_generate_preferences_artificially($course, $prefs);
676 $preferences->destination
= array_key_exists('destination', $prefs) ?
$prefs['destination'] : 0;
677 if (backup_execute($preferences, $errorstring)) {
678 return $CFG->dataroot
. '/' . $course->id
. '/backupdata/' . $preferences->backup_name
;
686 * Function to generate the $preferences variable that
687 * backup uses. This will back up all modules and instances in a course.
689 * @param object $course course object
690 * @param array $prefs can contain:
699 * and if not provided, they will not be included.
702 function backup_generate_preferences_artificially($course, $prefs) {
704 $preferences = new StdClass
;
705 $preferences->backup_unique_code
= time();
706 $preferences->backup_users
= (isset($prefs['backup_users']) ?
$prefs['backup_users'] : 0);
707 $preferences->backup_name
= backup_get_zipfile_name($course, $preferences->backup_unique_code
);
708 $preferences->mods
= array();
711 if ($allmods = $DB->get_records("modules") ) {
712 foreach ($allmods as $mod) {
713 $modname = $mod->name
;
714 $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
715 $modbackup = $modname."_backup_mods";
716 $modbackupone = $modname."_backup_one_mod";
717 $modcheckbackup = $modname."_check_backup_mods";
718 if (!file_exists($modfile)) {
721 include_once($modfile);
722 if (!function_exists($modbackup) ||
!function_exists($modcheckbackup)) {
725 $var = "exists_".$modname;
726 $preferences->$var = true;
728 // check that there are instances and we can back them up individually
729 if (!$DB->count_records('course_modules', array('course'=>$course->id
), array('module'=>$mod->id
)) ||
!function_exists($modbackupone)) {
732 $var = 'exists_one_'.$modname;
733 $preferences->$var = true;
734 $varname = $modname.'_instances';
735 $preferences->$varname = get_all_instances_in_course($modname, $course, NULL, true);
736 foreach ($preferences->$varname as $instance) {
737 $preferences->mods
[$modname]->instances
[$instance->id
]->name
= $instance->name
;
738 $var = 'backup_'.$modname.'_instance_'.$instance->id
;
739 $preferences->$var = true;
740 $preferences->mods
[$modname]->instances
[$instance->id
]->backup
= true;
741 $var = 'backup_user_info_'.$modname.'_instance_'.$instance->id
;
742 $preferences->$var = (!array_key_exists('userdata', $prefs) ||
$prefs['userdata']);
743 $preferences->mods
[$modname]->instances
[$instance->id
]->userinfo
= $preferences->$var;
744 $var = 'backup_'.$modname.'_instances';
745 $preferences->$var = 1; // we need this later to determine what to display in modcheckbackup.
750 $preferences->mods
[$modname]->name
= $modname;
752 $var = "backup_".$modname;
753 $preferences->$var = true;
754 $preferences->mods
[$modname]->backup
= true;
756 //Check include user info
757 $var = "backup_user_info_".$modname;
758 $preferences->$var = (!array_key_exists('userdata', $prefs) ||
$prefs['userdata']);
759 $preferences->mods
[$modname]->userinfo
= $preferences->$var;
761 //Call the check function to show more info
762 $modcheckbackup = $modname."_check_backup_mods";
763 $var = $modname.'_instances';
764 $instancestopass = array();
765 if (!empty($preferences->$var) && is_array($preferences->$var) && count($preferences->$var)) {
766 $table->data
= array();
768 foreach ($preferences->$var as $instance) {
769 $var1 = 'backup_'.$modname.'_instance_'.$instance->id
;
770 $var2 = 'backup_user_info_'.$modname.'_instance_'.$instance->id
;
771 if (!empty($preferences->$var1)) {
773 $obj->name
= $instance->name
;
774 $obj->userdata
= $preferences->$var2;
775 $obj->id
= $instance->id
;
776 $instancestopass[$instance->id
]= $obj;
782 $modcheckbackup($course->id
,$preferences->$var,$preferences->backup_unique_code
,$instancestopass);
786 //Check other parameters
787 $preferences->backup_metacourse
= (isset($prefs['backup_metacourse']) ?
$prefs['backup_metacourse'] : 0);
788 $preferences->backup_logs
= (isset($prefs['backup_logs']) ?
$prefs['backup_logs'] : 0);
789 $preferences->backup_user_files
= (isset($prefs['backup_user_files']) ?
$prefs['backup_user_files'] : 0);
790 $preferences->backup_course_files
= (isset($prefs['backup_course_files']) ?
$prefs['backup_course_files'] : 0);
791 $preferences->backup_site_files
= (isset($prefs['backup_site_files']) ?
$prefs['backup_site_files'] : 0);
792 $preferences->backup_messages
= (isset($prefs['backup_messages']) ?
$prefs['backup_messages'] : 0);
793 $preferences->backup_gradebook_history
= (isset($prefs['backup_gradebook_history']) ?
$prefs['backup_gradebook_history'] : 0);
794 $preferences->backup_blogs
= (isset($prefs['backup_blogs']) ?
$prefs['backup_blogs'] : 0);
795 $preferences->backup_course
= $course->id
;
798 user_check_backup($course->id
,$preferences->backup_unique_code
,$preferences->backup_users
,$preferences->backup_messages
, $preferences->backup_blogs
);
801 log_check_backup($course->id
);
804 user_files_check_backup($course->id
,$preferences->backup_unique_code
);
807 course_files_check_backup($course->id
,$preferences->backup_unique_code
);
810 site_files_check_backup($course->id
,$preferences->backup_unique_code
);
813 $roles = $DB->get_records('role', null, 'sortorder');
814 foreach ($roles as $role) {
815 $preferences->backuproleassignments
[$role->id
] = $role;
818 backup_add_static_preferences($preferences);
821 function add_to_backup_log($starttime,$courseid,$message, $backuptype) {
824 $log->courseid
= $courseid;
826 $log->laststarttime
= $starttime;
827 $log->info
= $message;
828 $log->backuptype
= $backuptype;
829 $DB->insert_record('backup_log', $log);