MDL-51361 backup: Adding default settings for course import

Also adding "calendar events" and "competencies" default setting for other backup modes.
This commit is contained in:
Henning Bostelmann 2016-08-04 15:20:28 +01:00
parent 1f2744851f
commit 4151ed984a
4 changed files with 79 additions and 64 deletions

View File

@ -192,6 +192,7 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_filters', new lang_string('generalfilters','backup'), new lang_string('configgeneralfilters','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_comments', new lang_string('generalcomments','backup'), new lang_string('configgeneralcomments','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_badges', new lang_string('generalbadges','backup'), new lang_string('configgeneralbadges','backup'), array('value'=>1,'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_calendarevents', new lang_string('generalcalendarevents','backup'), new lang_string('configgeneralcalendarevents','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_userscompletion', new lang_string('generaluserscompletion','backup'), new lang_string('configgeneraluserscompletion','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_logs', new lang_string('generallogs','backup'), new lang_string('configgenerallogs','backup'), array('value'=>0, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_histories', new lang_string('generalhistories','backup'), new lang_string('configgeneralhistories','backup'), array('value'=>0, 'locked'=>0)));
@ -199,6 +200,7 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_groups',
new lang_string('generalgroups', 'backup'), new lang_string('configgeneralgroups', 'backup'),
array('value' => 1, 'locked' => 0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_competencies', new lang_string('generalcompetencies','backup'), new lang_string('configgeneralcompetencies','backup'), array('value'=>1, 'locked'=>0)));
$ADMIN->add('backups', $temp);
@ -208,6 +210,19 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
$temp->add(new admin_setting_configcheckbox('backup/import_general_duplicate_admin_allowed',
new lang_string('importgeneralduplicateadminallowed', 'backup'),
new lang_string('importgeneralduplicateadminallowed_desc', 'backup'), 0));
// Import defaults section.
$temp->add(new admin_setting_heading('importsettings', new lang_string('importsettings', 'backup'), ''));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_activities', new lang_string('generalactivities','backup'), new lang_string('configgeneralactivities','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_blocks', new lang_string('generalblocks','backup'), new lang_string('configgeneralblocks','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_filters', new lang_string('generalfilters','backup'), new lang_string('configgeneralfilters','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_calendarevents', new lang_string('generalcalendarevents','backup'), new lang_string('configgeneralcalendarevents','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_questionbank', new lang_string('generalquestionbank','backup'), new lang_string('configgeneralquestionbank','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_groups',
new lang_string('generalgroups', 'backup'), new lang_string('configgeneralgroups', 'backup'),
array('value' => 1, 'locked' => 0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_competencies', new lang_string('generalcompetencies','backup'), new lang_string('configgeneralcompetencies','backup'), array('value'=>1, 'locked'=>0)));
$ADMIN->add('backups', $temp);
// Create a page for automated backups configuration and defaults.
@ -312,12 +327,14 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_filters', new lang_string('generalfilters','backup'), new lang_string('configgeneralfilters','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_comments', new lang_string('generalcomments','backup'), new lang_string('configgeneralcomments','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_badges', new lang_string('generalbadges','backup'), new lang_string('configgeneralbadges','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_calendarevents', new lang_string('generalcalendarevents','backup'), new lang_string('configgeneralcalendarevents','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_userscompletion', new lang_string('generaluserscompletion','backup'), new lang_string('configgeneraluserscompletion','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_logs', new lang_string('generallogs', 'backup'), new lang_string('configgenerallogs', 'backup'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_histories', new lang_string('generalhistories','backup'), new lang_string('configgeneralhistories','backup'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_questionbank', new lang_string('generalquestionbank','backup'), new lang_string('configgeneralquestionbank','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_groups', new lang_string('generalgroups', 'backup'),
new lang_string('configgeneralgroups', 'backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_competencies', new lang_string('generalcompetencies','backup'), new lang_string('configgeneralcompetencies','backup'), 1));
//$temp->add(new admin_setting_configcheckbox('backup/backup_auto_messages', new lang_string('messages', 'message'), new lang_string('backupmessageshelp','message'), 0));
//$temp->add(new admin_setting_configcheckbox('backup/backup_auto_blogs', new lang_string('blogs', 'blog'), new lang_string('backupblogshelp','blog'), 0));

View File

@ -536,9 +536,8 @@ abstract class backup_controller_dbops extends backup_dbops {
/**
* Sets the default values for the settings in a backup operation
*
* Based on the mode of the backup it will delegate the process to
* other methods like {@link apply_general_config_defaults} ...
* to get proper defaults loaded
* Based on the mode of the backup it will load proper defaults
* using {@link apply_admin_config_defaults}.
*
* @param backup_controller $controller
*/
@ -550,64 +549,7 @@ abstract class backup_controller_dbops extends backup_dbops {
switch ($mode) {
case backup::MODE_GENERAL:
// Load the general defaults
self::apply_general_config_defaults($controller);
break;
case backup::MODE_AUTOMATED:
// Load the automated defaults.
self::apply_auto_config_defaults($controller);
break;
default:
// Nothing to do for other modes (IMPORT/HUB...). Some day we
// can define defaults (admin UI...) for them if we want to
}
}
/**
* 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',
'backup_auto_groups' => 'groups'
);
$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.
*
* @param backup_controller $controller
*/
private static function apply_general_config_defaults(backup_controller $controller) {
$settings = array(
// Config name => Setting name
'backup_general_users' => 'users',
'backup_general_anonymize' => 'anonymize',
'backup_general_role_assignments' => 'role_assignments',
@ -616,12 +558,63 @@ abstract class backup_controller_dbops extends backup_dbops {
'backup_general_filters' => 'filters',
'backup_general_comments' => 'comments',
'backup_general_badges' => 'badges',
'backup_general_calendarevents' => 'calendarevents',
'backup_general_userscompletion' => 'userscompletion',
'backup_general_logs' => 'logs',
'backup_general_histories' => 'grade_histories',
'backup_general_questionbank' => 'questionbank',
'backup_general_groups' => 'groups'
'backup_general_groups' => 'groups',
'backup_general_competencies' => 'competencies'
);
self::apply_admin_config_defaults($controller, $settings, true);
break;
case backup::MODE_IMPORT:
// Load the import defaults
$settings = array(
'backup_import_activities' => 'activities',
'backup_import_blocks' => 'blocks',
'backup_import_filters' => 'filters',
'backup_import_calendarevents' => 'calendarevents',
'backup_import_questionbank' => 'questionbank',
'backup_import_groups' => 'groups',
'backup_import_competencies' => 'competencies'
);
self::apply_admin_config_defaults($controller, $settings, true);
break;
case backup::MODE_AUTOMATED:
// Load the automated defaults.
$settings = array(
'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_calendarevents' => 'calendarevents',
'backup_auto_userscompletion' => 'userscompletion',
'backup_auto_logs' => 'logs',
'backup_auto_histories' => 'grade_histories',
'backup_auto_questionbank' => 'questionbank',
'backup_auto_groups' => 'groups',
'backup_auto_competencies' => 'competencies'
);
self::apply_admin_config_defaults($controller, $settings, false);
break;
default:
// Nothing to do for other modes (HUB...). Some day we
// can define defaults (admin UI...) for them if we want to
}
}
/**
* Sets the controller settings default values from the admin config.
*
* @param backup_controller $controller
* @param array $settings a map from admin config names to setting names (Config name => Setting name)
* @param boolean $uselocks whether "locked" admin settings should be honoured
*/
private static function apply_admin_config_defaults(backup_controller $controller, array $settings, $uselocks) {
$plan = $controller->get_plan();
foreach ($settings as $config=>$settingname) {
$value = get_config('backup', $config);
@ -632,7 +625,7 @@ abstract class backup_controller_dbops extends backup_dbops {
$controller->log('Could not find a value for the config ' . $config, BACKUP::LOG_DEBUG);
continue;
}
$locked = (get_config('backup', $config.'_locked') == true);
$locked = $uselocks && (get_config('backup', $config.'_locked') == true);
if ($plan->setting_exists($settingname)) {
$setting = $plan->get_setting($settingname);
if ($setting->get_value() != $value || 1==1) {

View File

@ -87,7 +87,9 @@ $string['configgeneralactivities'] = 'Sets the default for including activities
$string['configgeneralbadges'] = 'Sets the default for including badges in a backup.';
$string['configgeneralanonymize'] = 'If enabled all information pertaining to users will be anonymised by default.';
$string['configgeneralblocks'] = 'Sets the default for including blocks in a backup.';
$string['configgeneralcalendarevents'] = 'Sets the default for including calendar events in a backup.';
$string['configgeneralcomments'] = 'Sets the default for including comments in a backup.';
$string['configgeneralcompetencies'] = 'Sets the default for including competencies in a backup.';
$string['configgeneralfilters'] = 'Sets the default for including filters in a backup.';
$string['configgeneralhistories'] = 'Sets the default for including user history within a backup.';
$string['configgenerallogs'] = 'If enabled logs will be included in backups by default.';
@ -138,7 +140,9 @@ $string['generalanonymize'] = 'Anonymise information';
$string['generalbackdefaults'] = 'General backup defaults';
$string['generalbadges'] = 'Include badges';
$string['generalblocks'] = 'Include blocks';
$string['generalcalendarevents'] = 'Include calendar events';
$string['generalcomments'] = 'Include comments';
$string['generalcompetencies'] = 'Include competencies';
$string['generalfilters'] = 'Include filters';
$string['generalhistories'] = 'Include histories';
$string['generalgradehistories'] = 'Include histories';
@ -167,6 +171,7 @@ $string['importcurrentstage2'] = 'Schema settings';
$string['importcurrentstage4'] = 'Confirmation and review';
$string['importcurrentstage8'] = 'Perform import';
$string['importcurrentstage16'] = 'Complete';
$string['importsettings'] = 'General import settings';
$string['importsuccess'] = 'Import complete. Click continue to return to the course.';
$string['includeactivities'] = 'Include:';
$string['includeditems'] = 'Included items:';

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2016091500.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2016091500.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.