diff --git a/backup/backup_scheduled.php b/backup/backup_scheduled.php index 37def53d8f6..9addef8e7a2 100644 --- a/backup/backup_scheduled.php +++ b/backup/backup_scheduled.php @@ -404,6 +404,7 @@ function schedule_backup_course_configure($course,$starttime = 0) { } } } + // now set instances if ($coursemods = get_course_mods($course->id)) { foreach ($coursemods as $mod) { @@ -418,6 +419,13 @@ function schedule_backup_course_configure($course,$starttime = 0) { } } } + + // finally, clean all the $preferences->mods[] not having instances. Nothing to backup about them + foreach ($preferences->mods as $modname => $mod) { + if (!isset($mod->instances)) { + unset($preferences->mods[$modname]); + } + } } //Convert other parameters @@ -434,53 +442,28 @@ function schedule_backup_course_configure($course,$starttime = 0) { $preferences->backup_keep = $backup_config->backup_sche_keep; } - //Calculate the backup string + //Calculate various backup preferences if ($status) { schedule_backup_log($starttime,$course->id," calculating backup name"); - //Calculate the backup word - //Take off some characters in the filename !! - $takeoff = array(" ", ":", "/", "\\", "|"); - $backup_word = str_replace($takeoff,"_",moodle_strtolower(get_string("backupfilename"))); - //If non-translated, use "backup" - if (substr($backup_word,0,1) == "[") { - $backup_word= "backup"; - } - - //Calculate the date format string - $backup_date_format = str_replace(" ","_",get_string("backupnameformat")); - //If non-translated, use "%Y%m%d-%H%M" - if (substr($backup_date_format,0,1) == "[") { - $backup_date_format = "%%Y%%m%%d-%%H%%M"; - } - - //Calculate the shortname - $backup_shortname = clean_filename($course->shortname); - if (empty($backup_shortname) or $backup_shortname == '_' ) { - $backup_shortname = $course->id; - } - - //Calculate the final backup filename - //The backup word - $backup_name = $backup_word."-"; - //The shortname - $backup_name .= moodle_strtolower($backup_shortname)."-"; - //The date format - $backup_name .= userdate(time(),$backup_date_format,99,false); - //The extension - $backup_name .= ".zip"; - //And finally, clean everything - $backup_name = clean_filename($backup_name); + //Calculate the backup file name + $backup_name = backup_get_zipfile_name($course); //Calculate the string to match the keep preference - $keep_name = $backup_word."-"; - //The shortname - $keep_name .= moodle_strtolower($backup_shortname)."-"; - //And finally, clean everything - $keep_name = clean_filename($keep_name); + $keep_name = backup_get_keep_name($course); + //Set them $preferences->backup_name = $backup_name; $preferences->keep_name = $keep_name; + + //Roleasignments + $roles = get_records('role', '', '', 'sortorder'); + foreach ($roles as $role) { + $preferences->backuproleassignments[$role->id] = $role; + } + + //Another Info + backup_add_static_preferences($preferences); } //Calculate the backup unique code to allow simultaneus backups (to define @@ -567,6 +550,8 @@ function schedule_backup_course_configure($course,$starttime = 0) { return $status; } +//TODO: Unify this function with backup_execute() to have both backups 100% equivalent. Moodle 2.0 + //This function implements all the needed code to backup a course //copying it to the desired destination (default if not specified) function schedule_backup_course_execute($preferences,$starttime = 0) { @@ -575,12 +560,6 @@ function schedule_backup_course_execute($preferences,$starttime = 0) { $status = true; - //Another Info to add - $preferences->moodle_version = $CFG->version; - $preferences->moodle_release = $CFG->release; - $preferences->backup_version = $CFG->backup_version; - $preferences->backup_release = $CFG->backup_release; - //Some parts of the backup doesn't know about $preferences, so we //put a copy of it inside that CFG (always global) to be able to //use it. Then, when needed I search for preferences inside CFG @@ -676,6 +655,18 @@ function schedule_backup_course_execute($preferences,$starttime = 0) { $status = backup_groups_info($backup_file,$preferences); } + //Print groupings info + if ($status) { + schedule_backup_log($starttime,$preferences->backup_course," groupings"); + $status = backup_groupings_info($backup_file,$preferences); + } + + //Print groupings_groups info + if ($status) { + schedule_backup_log($starttime,$preferences->backup_course," groupings_groups"); + $status = backup_groupings_groups_info($backup_file,$preferences); + } + //Print events info if ($status) { schedule_backup_log($starttime,$preferences->backup_course," events"); @@ -715,6 +706,12 @@ function schedule_backup_course_execute($preferences,$starttime = 0) { } } + //Backup course format data, if any. + if ($status) { + schedule_backup_log($starttime,$preferences->backup_course," course format data"); + $status = backup_format_data($backup_file,$preferences); + } + //Prints course end if ($status) { $status = backup_course_end($backup_file,$preferences); diff --git a/backup/backuplib.php b/backup/backuplib.php index d7b09be199f..545702c11d8 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -3187,30 +3187,38 @@ } /** - * This function generates the default zipfile name for a backup - * based on the course id and the unique code. - * - * @param object $course course object - * @param string $backup_unique_code (optional, if left out current timestamp used) - * + * This function calculates the "backup" part of the file name + * from lang files. Used both in manual and scheduled backups + * + * @param object $course course object + * @return string "backup" part of the filename + */ + function backup_get_backup_string($course) { - * @return string filename (excluding path information) - */ - function backup_get_zipfile_name($course, $backup_unique_code='') { - - if (empty($backup_unique_code)) { - $backup_unique_code = time(); - } - - //Calculate the backup word - //Take off some characters in the filename !! + /// Calculate the backup word + /// Take off some characters in the filename !! $takeoff = array(" ", ":", "/", "\\", "|"); $backup_word = str_replace($takeoff,"_",moodle_strtolower(get_string("backupfilename"))); - //If non-translated, use "backup" + /// If non-translated, use "backup" if (substr($backup_word,0,1) == "[") { $backup_word= "backup"; } + return $backup_word; + } + + /** + * This function generates the default zipfile name for a backup + * based on the course shortname + * + * @param object $course course object + * @return string filename (excluding path information) + */ + function backup_get_zipfile_name($course) { + + //Calculate the backup word + $backup_word = backup_get_backup_string($course); + //Calculate the date format string $backup_date_format = str_replace(" ","_",get_string("backupnameformat")); //If non-translated, use "%Y%m%d-%H%M" @@ -3237,9 +3245,31 @@ $backup_name = clean_filename($backup_name); return $backup_name; - } + /** + * This function generates the common file substring for a course + * used to keep n copies by the scheduled backup + * + * @param object $course course object + * @return string common part of filename in backups of this course + */ + function backup_get_keep_name($course) { + + //Calculate the backup word + $backup_word = backup_get_backup_string($course); + + //Calculate the shortname + $backup_shortname = clean_filename($course->shortname); + if (empty($backup_shortname) or $backup_shortname == '_' ) { + $backup_shortname = $course->id; + } + + $keep_name = $backup_word . "-" . moodle_strtolower($backup_shortname)."-"; + $keep_name = clean_filename($keep_name); + + return $keep_name; + } /** * This function adds on the standard items to the preferences * Like moodle version and backup version