From 366c19fabdd58bbc96fc657d1cd7b8267c3fbcf1 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 11 Sep 2011 19:35:56 +0200 Subject: [PATCH] MDL-28488 backup - conditionaly apply defaults based on mode Some modes of backup cannot be preloaded with general backup settings because they may conflict with the definitions required/set by the mode (for example, import backups are, by definition, without users always, so we cannot apply one default in the opposite direction). So, after the patch, current general_backup setting will be only applied to general backups, import/hub modes won't be using any default and automated backup defaults should be loaded here (TODO) --- backup/controller/backup_controller.class.php | 2 +- .../util/dbops/backup_controller_dbops.class.php | 30 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/backup/controller/backup_controller.class.php b/backup/controller/backup_controller.class.php index cd054815134..1bab62be627 100644 --- a/backup/controller/backup_controller.class.php +++ b/backup/controller/backup_controller.class.php @@ -339,7 +339,7 @@ class backup_controller extends backup implements loggable { protected function apply_defaults() { $this->log('applying plan defaults', backup::LOG_DEBUG); - backup_controller_dbops::apply_general_config_defaults($this); + backup_controller_dbops::apply_config_defaults($this); $this->set_status(backup::STATUS_CONFIGURED); } } diff --git a/backup/util/dbops/backup_controller_dbops.class.php b/backup/util/dbops/backup_controller_dbops.class.php index d760871869b..cd89d82f55f 100644 --- a/backup/util/dbops/backup_controller_dbops.class.php +++ b/backup/util/dbops/backup_controller_dbops.class.php @@ -402,11 +402,39 @@ 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 + * + * @param backup_controller $controller + */ + public static function apply_config_defaults(backup_controller $controller) { + // Based on the mode of the backup (general, automated, import, hub...) + // decide the action to perform to get defaults loaded + $mode = $controller->get_mode(); + + switch ($mode) { + case backup::MODE_GENERAL: + // Load the general defaults + self::apply_general_config_defaults($controller); + break; + case backup::MODE_AUTOMATED: + // TODO: Move the loading from automatic stuff to here + 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 backup config. * * @param backup_controller $controller */ - public static function apply_general_config_defaults(backup_controller $controller) { + private static function apply_general_config_defaults(backup_controller $controller) { $settings = array( // Config name => Setting name 'backup_general_users' => 'users', -- 2.11.4.GIT