diff --git a/backup/upgrade.txt b/backup/upgrade.txt new file mode 100644 index 0000000000000..cb020956ed016 --- /dev/null +++ b/backup/upgrade.txt @@ -0,0 +1,17 @@ +This files describes API changes in /backup/*, +information provided here is intended especially for developers. + +=== 2.4 === + +* Since 2.3.1+ the backup file name schema has changed. The ID of the course will always be part of + the filename regardless of the setting 'backup_shortname'. See MDL-33812. + +=== 2.3 === + +* Since 2.3.1+ the backup file name schema has changed. The ID of the course will always be part of + the filename regardless of the setting 'backup_shortname'. See MDL-33812. + +=== 2.2 === + +* Since 2.2.4+ the backup file name schema has changed. The ID of the course will always be part of + the filename regardless of the setting 'backup_shortname'. See MDL-33812. \ No newline at end of file diff --git a/backup/util/dbops/backup_plan_dbops.class.php b/backup/util/dbops/backup_plan_dbops.class.php index e169a8a8ba130..2e2faaeb05e4e 100644 --- a/backup/util/dbops/backup_plan_dbops.class.php +++ b/backup/util/dbops/backup_plan_dbops.class.php @@ -197,19 +197,19 @@ public static function get_mnet_localhost_wwwroot() { * @param int $courseid/$sectionid/$cmid * @param bool $users Should be true is users were included in the backup * @param bool $anonymised Should be true is user information was anonymized. - * @param bool $useidasname true to use id, false to use strings (default) + * @param bool $useidonly only use the ID in the file name * @return string The filename to use */ - public static function get_default_backup_filename($format, $type, $id, $users, $anonymised, $useidasname = false) { + public static function get_default_backup_filename($format, $type, $id, $users, $anonymised, $useidonly = false) { global $DB; // Calculate backup word $backupword = str_replace(' ', '_', textlib::strtolower(get_string('backupfilename'))); $backupword = trim(clean_filename($backupword), '_'); + // Not $useidonly, lets fetch the name $shortname = ''; - // Not $useidasname, lets calculate it, else $id will be used - if (!$useidasname) { + if (!$useidonly) { // Calculate proper name element (based on type) switch ($type) { case backup::TYPE_1COURSE: @@ -231,7 +231,11 @@ public static function get_default_backup_filename($format, $type, $id, $users, $shortname = textlib::strtolower(trim(clean_filename($shortname), '_')); } - $name = empty($shortname) ? $id : $shortname; + // The name will always contain the ID, but we append the course short name if requested. + $name = $id; + if (!$useidonly && $shortname != '') { + $name .= '-' . $shortname; + } // Calculate date $backupdateformat = str_replace(' ', '_', get_string('backupnameformat', 'langconfig')); diff --git a/backup/util/helper/backup_cron_helper.class.php b/backup/util/helper/backup_cron_helper.class.php index a974883a5279d..e3ada4f6b0d82 100644 --- a/backup/util/helper/backup_cron_helper.class.php +++ b/backup/util/helper/backup_cron_helper.class.php @@ -561,18 +561,7 @@ public static function remove_excess_backups($course) { if (!empty($dir) && ($storage == 1 || $storage == 2)) { // Calculate backup filename regex, ignoring the date/time/info parts that can be // variable, depending of languages, formats and automated backup settings - - - // MDL-33531: use different filenames depending on backup_shortname option - if ( !empty($config->backup_shortname) ) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); - $courseref = format_string($course->shortname, true, array('context' => $context)); - $courseref = str_replace(' ', '_', $courseref); - $courseref = textlib::strtolower(trim(clean_filename($courseref), '_')); - } else { - $courseref = $course->id; - } - $filename = $backupword . '-' . backup::FORMAT_MOODLE . '-' . backup::TYPE_1COURSE . '-' .$courseref . '-'; + $filename = $backupword . '-' . backup::FORMAT_MOODLE . '-' . backup::TYPE_1COURSE . '-' .$course->id . '-'; $regex = '#^'.preg_quote($filename, '#').'.*\.mbz$#'; // Store all the matching files into fullpath => timemodified array diff --git a/lang/en/admin.php b/lang/en/admin.php index 7f8972a8564de..5e7b0d9826457 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -68,7 +68,7 @@ $string['backgroundcolour'] = 'Transparent colour'; $string['backups'] = 'Backups'; $string['backup_shortname'] = 'Use course name in backup filename'; -$string['backup_shortnamehelp'] = 'Use the course name as part of the backup filename instead of the course id number.'; +$string['backup_shortnamehelp'] = 'Use the course name as part of the backup filename.'; $string['badwordsconfig'] = 'Enter your list of bad words separated by commas.'; $string['badwordsdefault'] = 'If the custom list is empty, a default list from the language pack will be used.'; $string['badwordslist'] = 'Custom bad words list';