From 905185dca45a953f420fd1410176992b2baa440f Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 14 Aug 2012 16:52:39 +0800 Subject: [PATCH 1/3] MDL-33812 Backup: Respect of backup_auto_keep --- backup/util/dbops/backup_plan_dbops.class.php | 14 +++++++++----- lang/en/admin.php | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/backup/util/dbops/backup_plan_dbops.class.php b/backup/util/dbops/backup_plan_dbops.class.php index 30714ed8b178c..242116ed06181 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 $withoutname if false, include the name in the file name (default) * @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, $withoutname = false) { global $DB; // Calculate backup word $backupword = str_replace(' ', '_', textlib::strtolower(get_string('backupfilename'))); $backupword = trim(clean_filename($backupword), '_'); + // Not $withoutname, lets fetch the name $shortname = ''; - // Not $useidasname, lets calculate it, else $id will be used - if (!$useidasname) { + if (!$withoutname) { // 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 (!$withoutname && $shortname != '') { + $name .= '-' . $shortname; + } // Calculate date $backupdateformat = str_replace(' ', '_', get_string('backupnameformat', 'langconfig')); diff --git a/lang/en/admin.php b/lang/en/admin.php index 26fbe3bf115d9..5d2668039b19c 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'; From 2fd679c5e13d89c8e7cd7be84a6dcef2b44a4a53 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 21 Aug 2012 13:50:55 +0800 Subject: [PATCH 2/3] MDL-33812 Backup: Revert MDL-33521 --- backup/util/helper/backup_cron_helper.class.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/backup/util/helper/backup_cron_helper.class.php b/backup/util/helper/backup_cron_helper.class.php index b6d81abde7f59..8a3b19d103a8b 100644 --- a/backup/util/helper/backup_cron_helper.class.php +++ b/backup/util/helper/backup_cron_helper.class.php @@ -530,18 +530,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 From 640f8eed6d26f89b4a9f3562fae092193cedcfe7 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 29 Aug 2012 16:00:19 +0800 Subject: [PATCH 3/3] MDL-33812 Backup: Added some upgrade information about the changes --- backup/upgrade.txt | 17 +++++++++++++++++ backup/util/dbops/backup_plan_dbops.class.php | 10 +++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 backup/upgrade.txt 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 242116ed06181..0752f0d303834 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 $withoutname if false, include the name in the file name (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, $withoutname = 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 $withoutname, lets fetch the name + // Not $useidonly, lets fetch the name $shortname = ''; - if (!$withoutname) { + if (!$useidonly) { // Calculate proper name element (based on type) switch ($type) { case backup::TYPE_1COURSE: @@ -233,7 +233,7 @@ public static function get_default_backup_filename($format, $type, $id, $users, // The name will always contain the ID, but we append the course short name if requested. $name = $id; - if (!$withoutname && $shortname != '') { + if (!$useidonly && $shortname != '') { $name .= '-' . $shortname; }