MDL-40228 backup: Settings were ignored during automated backups

This commit is contained in:
Frederic Massart
2014-06-20 15:37:32 +08:00
parent 337075d17b
commit 073be367e2
2 changed files with 42 additions and 22 deletions
@@ -547,7 +547,8 @@ abstract class backup_controller_dbops extends backup_dbops {
self::apply_general_config_defaults($controller);
break;
case backup::MODE_AUTOMATED:
// TODO: Move the loading from automatic stuff to here
// Load the automated defaults.
self::apply_auto_config_defaults($controller);
break;
default:
// Nothing to do for other modes (IMPORT/HUB...). Some day we
@@ -555,6 +556,43 @@ abstract class backup_controller_dbops extends backup_dbops {
}
}
/**
* Sets the controller settings default values from the automated backup config.
*
* @param backup_controller $controller
*/
private static function apply_auto_config_defaults(backup_controller $controller) {
$settings = array(
// Config name => Setting name.
'backup_auto_users' => 'users',
'backup_auto_role_assignments' => 'role_assignments',
'backup_auto_activities' => 'activities',
'backup_auto_blocks' => 'blocks',
'backup_auto_filters' => 'filters',
'backup_auto_comments' => 'comments',
'backup_auto_badges' => 'badges',
'backup_auto_userscompletion' => 'userscompletion',
'backup_auto_logs' => 'logs',
'backup_auto_histories' => 'grade_histories',
'backup_auto_questionbank' => 'questionbank'
);
$plan = $controller->get_plan();
foreach ($settings as $config => $settingname) {
$value = get_config('backup', $config);
if ($value === false) {
// The setting is not set.
$controller->log('Could not find a value for the config ' . $config, BACKUP::LOG_DEBUG);
continue;
}
if ($plan->setting_exists($settingname)) {
$setting = $plan->get_setting($settingname);
$setting->set_value($value);
} else {
$controller->log('Unknown setting: ' . $settingname, BACKUP::LOG_DEBUG);
}
}
}
/**
* Sets the controller settings default values from the backup config.
*
@@ -583,6 +621,7 @@ abstract class backup_controller_dbops extends backup_dbops {
// Ignore this because the config has not been set. get_config
// returns false if a setting doesn't exist, '0' is returned when
// the configuration is set to false.
$controller->log('Could not find a value for the config ' . $config, BACKUP::LOG_DEBUG);
continue;
}
$locked = (get_config('backup', $config.'_locked') == true);
@@ -594,6 +633,8 @@ abstract class backup_controller_dbops extends backup_dbops {
$setting->set_status(base_setting::LOCKED_BY_CONFIG);
}
}
} else {
$controller->log('Unknown setting: ' . $setting, BACKUP::LOG_DEBUG);
}
}
}
@@ -381,27 +381,6 @@ abstract class backup_cron_automated_helper {
try {
$settings = array(
'users' => 'backup_auto_users',
'role_assignments' => 'backup_auto_role_assignments',
'activities' => 'backup_auto_activities',
'blocks' => 'backup_auto_blocks',
'filters' => 'backup_auto_filters',
'comments' => 'backup_auto_comments',
'badges' => 'backup_auto_badges',
'completion_information' => 'backup_auto_userscompletion',
'logs' => 'backup_auto_logs',
'histories' => 'backup_auto_histories',
'questionbank' => 'backup_auto_questionbank'
);
foreach ($settings as $setting => $configsetting) {
if ($bc->get_plan()->setting_exists($setting)) {
if (isset($config->{$configsetting})) {
$bc->get_plan()->get_setting($setting)->set_value($config->{$configsetting});
}
}
}
// Set the default filename.
$format = $bc->get_format();
$type = $bc->get_type();