From: skodak Date: Sat, 2 Sep 2006 19:30:54 +0000 (+0000) Subject: added prune() to admin tree class to prevent errors in applying of backup defaults X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4672d9557d4c5f96c2911b0cac00ec7016cace26;p=moodle.git added prune() to admin tree class to prevent errors in applying of backup defaults --- diff --git a/admin/index.php b/admin/index.php index 4daa3d6d03..a458a9a88e 100644 --- a/admin/index.php +++ b/admin/index.php @@ -153,6 +153,7 @@ // Write default settings unconditionally (i.e. even if a setting is already set, overwrite it) // (this should only have any effect during initial install). $adminroot = admin_get_root(); + $adminroot->prune('backups'); // backup settings table not created yet apply_default_settings($adminroot); /// This is used to handle any settings that must exist in $CFG but which do not exist in diff --git a/lib/adminlib.php b/lib/adminlib.php index e7803527c7..f7c4514bf8 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -738,7 +738,18 @@ class part_of_admin_tree { trigger_error('Admin class does not implement method locate()', E_USER_WARNING); return; } - + + /** + * Removes named part_of_admin_tree. + * + * @param string $name The internal name of the part_of_admin_tree we want to remove. + * @return boolean success. + */ + function prune($name) { + trigger_error('Admin class does not implement method prune()', E_USER_WARNING); + return; + } + /** * Verifies current user's access to this part_of_admin_tree. * @@ -901,6 +912,31 @@ class admin_category extends parentable_part_of_admin_tree { return $return; } + /** + * Removes part_of_admin_tree object with internal name $name. + * + * @param string $name The internal name of the object we want to remove. + * @return boolean success + */ + function prune($name) { + + if ($this->name == $name) { + return false; //can not remove itself + } + + foreach($this->children as $precedence => $child) { + if ($child->name == $name) { + // found it! + unset($this->children[$precedence]); + return true; + } + if ($this->children[$precedence]->prune($name)) { + return true; + } + } + return false; + } + /** * Adds a part_of_admin_tree to a child or grandchild (or great-grandchild, and so forth) of this object. * @@ -1033,7 +1069,11 @@ class admin_externalpage extends part_of_admin_tree { $return = ($this->name == $name ? $this : NULL); return $return; } - + + function prune($name) { + return false; + } + /** * Determines if the current user has access to this external page based on $this->role. * @@ -1093,7 +1133,11 @@ class admin_settingpage extends part_of_admin_tree { $return = ($this->name == $name ? $this : NULL); return $return; } - + + function prune($name) { + return false; + } + // see admin_externalpage function admin_settingpage($name, $visiblename, $role = 'moodle/legacy:admin') { global $CFG; @@ -1427,11 +1471,7 @@ class admin_setting_courselist_frontpage extends admin_setting_configselect { if (count_records("course") > FRONTPAGECOURSELIMIT) { unset($choices[FRONTPAGECOURSELIST]); } - if ($loggedin) { - $defaults = FRONTPAGECOURSELIST.',,,'; - } else { - $defaults = FRONTPAGECATEGORYCOMBO.',,,'; - } + $defaults = FRONTPAGECOURSELIST.',,,'; parent::admin_setting_configselect($name, $visiblename, $description, $defaults, $choices); }