From 34eb2faa0dc48c738367a297950e87f69c64b857 Mon Sep 17 00:00:00 2001 From: Tobias Reischmann Date: Thu, 12 Oct 2017 15:32:15 +0200 Subject: [PATCH] MDL-27886 backup: Decision if a setting is fixed based on level Previously, when a during backup/restore the "Schema"-stage is loaded, some settings are fixed if they are LOCKED_BY_HIERARCHY. However, user data fields of activities can be locked, when the section they are contained in has user data set to false. When this setting is changed on the same screen, the fixed setting of the activity can not be "unfixed" by javascript. This patch adds a settings-level to the call of is_changeable. With this only those dependency_settings are considered, which belong to parent settings, which are not changeable on the current stage. --- backup/util/ui/backup_ui_setting.class.php | 23 ++++++++++++++++------ backup/util/ui/base_moodleform.class.php | 13 +++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/backup/util/ui/backup_ui_setting.class.php b/backup/util/ui/backup_ui_setting.class.php index 327f35085a6..f23291956ba 100644 --- a/backup/util/ui/backup_ui_setting.class.php +++ b/backup/util/ui/backup_ui_setting.class.php @@ -307,10 +307,12 @@ abstract class backup_setting_ui extends base_setting_ui { * 2. The setting is locked but only by settings that are of the same level (same page) * * Condition 2 is really why we have this function - * + * @param int $level Optional, if provided only depedency_settings below or equal to this level are considered, + * when checking if the ui_setting is changeable. Although dependencies might cause a lock on this setting, + * they could be changeable in the same view. * @return bool */ - public function is_changeable() { + public function is_changeable($level = null) { if ($this->setting->get_status() === backup_setting::NOT_LOCKED) { // Its not locked so its chanegable. return true; @@ -319,6 +321,9 @@ abstract class backup_setting_ui extends base_setting_ui { return false; } else if ($this->setting->has_dependencies_on_settings()) { foreach ($this->setting->get_settings_depended_on() as $dependency) { + if ($level && $dependency->get_setting()->get_level() >= $level) { + continue; + } if ($dependency->is_locked() && $dependency->get_setting()->get_level() !== $this->setting->get_level()) { // Its not changeable because one or more dependancies arn't changeable. return false; @@ -456,13 +461,16 @@ class backup_setting_ui_checkbox extends backup_setting_ui { /** * Returns true if the setting is changeable + * @param int $level Optional, if provided only depedency_settings below or equal to this level are considered, + * when checking if the ui_setting is changeable. Although dependencies might cause a lock on this setting, + * they could be changeable in the same view. * @return bool */ - public function is_changeable() { + public function is_changeable($level = null) { if ($this->changeable === false) { return false; } else { - return parent::is_changeable(); + return parent::is_changeable($level); } } @@ -635,13 +643,16 @@ class backup_setting_ui_select extends backup_setting_ui { /** * Returns true if the setting is changeable, false otherwise * + * @param int $level Optional, if provided only depedency_settings below or equal to this level are considered, + * when checking if the ui_setting is changeable. Although dependencies might cause a lock on this setting, + * they could be changeable in the same view. * @return bool */ - public function is_changeable() { + public function is_changeable($level = null) { if (count($this->values) == 1) { return false; } else { - return parent::is_changeable(); + return parent::is_changeable($level); } } diff --git a/backup/util/ui/base_moodleform.class.php b/backup/util/ui/base_moodleform.class.php index b5c8159df1e..5beded57129 100644 --- a/backup/util/ui/base_moodleform.class.php +++ b/backup/util/ui/base_moodleform.class.php @@ -183,11 +183,22 @@ abstract class base_moodleform extends moodleform { public function add_settings(array $settingstasks) { global $OUTPUT; + // Determine highest setting level, which is displayed in this stage. This is relevant for considering only + // locks of dependency settings for parent settings, which are not displayed in this stage. + $highestlevel = backup_setting::ACTIVITY_LEVEL; + foreach ($settingstasks as $st) { + list($setting, $task) = $st; + if ($setting->get_level() < $highestlevel) { + $highestlevel = $setting->get_level(); + } + } + $defaults = array(); foreach ($settingstasks as $st) { list($setting, $task) = $st; // If the setting cant be changed or isn't visible then add it as a fixed setting. - if (!$setting->get_ui()->is_changeable() || $setting->get_visibility() != backup_setting::VISIBLE) { + if (!$setting->get_ui()->is_changeable($highestlevel) || + $setting->get_visibility() != backup_setting::VISIBLE) { $this->add_fixed_setting($setting, $task); continue; }