MDL-17942 fixed some incorrect uses of exceptions and typos

This commit is contained in:
skodak 2009-01-17 23:24:31 +00:00
parent ac173d3ebe
commit 19a4a32e53
3 changed files with 8 additions and 18 deletions

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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!');
}