From 19a4a32e536956bac4294c86d465ae31d26b5659 Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 17 Jan 2009 23:24:31 +0000 Subject: [PATCH] MDL-17942 fixed some incorrect uses of exceptions and typos --- admin/roles/lib.php | 8 ++------ lib/accesslib.php | 14 ++++---------- lib/db/install.php | 4 ++-- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/admin/roles/lib.php b/admin/roles/lib.php index b4de6f2b67..8a9b6090e0 100644 --- a/admin/roles/lib.php +++ b/admin/roles/lib.php @@ -590,15 +590,11 @@ class define_role_table_advanced extends capability_table_with_risks { } else { $legacycap = ''; } - if (!$this->role->id = create_role($this->role->name, $this->role->shortname, $this->role->description, $legacycap)) { - throw new moodle_exception('errorcreatingrole'); - } + $this->role->id = create_role($this->role->name, $this->role->shortname, $this->role->description, $legacycap); $this->roleid = $this->role->id; // Needed to make the parent::save_changes(); call work. } else { // Updating role - if (!$DB->update_record('role', $this->role)) { - throw new moodle_exception('cannotupdaterole'); - } + $DB->update_record('role', $this->role); // Legacy type foreach($this->legacyroles as $type => $cap) { diff --git a/lib/accesslib.php b/lib/accesslib.php index 0f9bfaeda2..11fb043adf 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2594,15 +2594,13 @@ function get_local_override($roleid, $contextid, $capability) { * @param shortname - role short name * @param description - role description * @param legacy - optional legacy capability - * @return id or false + * @return id or dml_exception */ function create_role($name, $shortname, $description, $legacy='') { global $DB; // Get the system context. - if (!$context = get_context_instance(CONTEXT_SYSTEM)) { - return false; - } + $context = get_context_instance(CONTEXT_SYSTEM); // Insert the role record. $role = new object(); @@ -4562,16 +4560,12 @@ function get_default_contextlevels($roletype) { */ function set_role_contextlevels($roleid, array $contextlevels) { global $DB; - if (!$DB->delete_records('role_context_levels', array('roleid' => $roleid))) { - throw new moodle_exception('couldnotdeleterolecontextlevels', '', '', $roleid); - } + $DB->delete_records('role_context_levels', array('roleid' => $roleid)); $rcl = new stdClass; $rcl->roleid = $roleid; foreach ($contextlevels as $level) { $rcl->contextlevel = $level; - if (!$DB->insert_record('role_context_levels', $rcl, false, true)) { - throw new moodle_exception('couldnotdeleterolecontextlevels', '', '', $rcl); - } + $DB->insert_record('role_context_levels', $rcl, false, true); } } diff --git a/lib/db/install.php b/lib/db/install.php index 0b1bb7c885..e34b938a7a 100644 --- a/lib/db/install.php +++ b/lib/db/install.php @@ -9,7 +9,7 @@ function xmldb_main_install() { /// make sure system context exists $syscontext = get_context_instance(CONTEXT_SYSTEM); if ($syscontext->id != 1) { - throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected system context id created!'); + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected system context id created!'); } @@ -31,7 +31,7 @@ function xmldb_main_install() { $DB->insert_record('course', $newsite); $SITE = get_site(); if ($SITE->id != 1) { - throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected site course id created!'); + throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected site course id created!'); } -- 2.39.5