mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
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.
This commit is contained in:
parent
8c067bb86d
commit
34eb2faa0d
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user