From 5e2f308b91908f1745c40fe272f40e2bd58977ea Mon Sep 17 00:00:00 2001 From: skodak <skodak> Date: Tue, 17 Feb 2009 16:50:36 +0000 Subject: [PATCH] MDL-18293 exception and DML cleanup --- admin/auth_config.php | 4 +--- group/autogroup.php | 11 ++--------- group/delete.php | 4 +--- group/group.php | 8 ++------ group/grouping.php | 10 +++------- group/overview.php | 8 ++------ lang/en_utf8/error.php | 1 - lib/moodlelib.php | 38 +++++++++++++++++++------------------- 8 files changed, 30 insertions(+), 54 deletions(-) diff --git a/admin/auth_config.php b/admin/auth_config.php index b38b3593cf..0ceca51e79 100644 --- a/admin/auth_config.php +++ b/admin/auth_config.php @@ -32,9 +32,7 @@ if ($frm = data_submitted() and confirm_sesskey()) { if (preg_match('/^lockconfig_(.+?)$/', $name, $matches)) { $plugin = "auth/$auth"; $name = $matches[1]; - if (!set_config($name, $value, $plugin)) { - print_error("cannotsaveconfig", 'error', '', (object)array('name'=>$name, 'value'=>$value, 'plugin'=>$plugin)); - } + set_config($name, $value, $plugin); } } redirect($returnurl); diff --git a/group/autogroup.php b/group/autogroup.php index 427c60fffd..6a74cc8459 100644 --- a/group/autogroup.php +++ b/group/autogroup.php @@ -190,10 +190,7 @@ if ($editform->is_cancelled()) { $grouping = new object(); $grouping->courseid = $COURSE->id; $grouping->name = $groupingname; - if (!$grouping->id = groups_create_grouping($grouping)) { - $error = 'Can not create grouping'; //should not happen - $failed = true; - } + $grouping->id = groups_create_grouping($grouping); $createdgrouping = $grouping->id; } else { $grouping = groups_get_grouping($data->grouping); @@ -210,11 +207,7 @@ if ($editform->is_cancelled()) { $newgroup = new object(); $newgroup->courseid = $data->courseid; $newgroup->name = $group['name']; - if (!$groupid = groups_create_group($newgroup)) { - $error = 'Can not create group!'; // should not happen - $failed = true; - break; - } + $groupid = groups_create_group($newgroup); $createdgroups[] = $groupid; foreach($group['members'] as $user) { groups_add_member($groupid, $user->id); diff --git a/group/delete.php b/group/delete.php index 8589380635..4307c22798 100644 --- a/group/delete.php +++ b/group/delete.php @@ -49,9 +49,7 @@ if ($confirm && data_submitted()) { } $DB->begin_sql(); foreach($groupidarray as $groupid) { - if (!groups_delete_group($groupid)) { - print_error('erroreditgroup', 'group', $returnurl); - } + groups_delete_group($groupid); } $DB->commit_sql(); redirect($returnurl); diff --git a/group/group.php b/group/group.php index 9fe6753ae7..0c12317f12 100644 --- a/group/group.php +++ b/group/group.php @@ -83,13 +83,9 @@ if ($editform->is_cancelled()) { } elseif ($data = $editform->get_data()) { if ($data->id) { - if (!groups_update_group($data, $editform)) { - print_error('cannotupdategroup'); - } + groups_update_group($data, $editform); } else { - if (!$id = groups_create_group($data, $editform)) { - print_error('cannotcreategroup'); - } + $id = groups_create_group($data, $editform); $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id; } diff --git a/group/grouping.php b/group/grouping.php index 7be2c8c1d1..41d7da2ed8 100644 --- a/group/grouping.php +++ b/group/grouping.php @@ -78,21 +78,17 @@ if ($editform->is_cancelled()) { $success = true; if ($data->id) { - if (!groups_update_grouping($data)) { - print_error('cannotupdategroup'); - } + groups_update_grouping($data); } else { - if (!groups_create_grouping($data)) { - print_error('cannotcreategroup'); - } + groups_create_grouping($data); } redirect($returnurl); } -$strgroupings = get_string('groupings', 'group'); +$strgroupings = get_string('groupings', 'group'); $strparticipants = get_string('participants'); if ($id) { diff --git a/group/overview.php b/group/overview.php index 6a88c67da5..9750031d24 100644 --- a/group/overview.php +++ b/group/overview.php @@ -43,9 +43,7 @@ if (empty($CFG->enablegroupings)) { $members = array(-1 => array()); //groups not in a grouping $groupingid = 0; } else { - if (!$groupings = $DB->get_records('groupings', array('courseid'=>$courseid), 'name')) { - $groupings = array(); - } + $groupings = $DB->get_records('groupings', array('courseid'=>$courseid), 'name'); $members = array(); foreach ($groupings as $grouping) { $members[$grouping->id] = array(); @@ -54,9 +52,7 @@ if (empty($CFG->enablegroupings)) { } // Get all groups -if (!$groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name')) { - $groups = array(); -} +$groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name'); $params = array('courseid'=>$courseid); if ($groupid) { diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index f4625b2d97..08f05ac950 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -114,7 +114,6 @@ $string['cannotsaveblock'] = 'Error saving block configuration'; $string['cannotsavefile'] = 'Cannot save the file \"$a\"'; $string['cannotsaveagreement'] = 'Could not save your agreement'; $string['cannotsavecomment'] = 'Cannot save comment'; -$string['cannotsaveconfig'] = 'Problem saving config \"$a->name\" as \"$a->value\" for plugin \"$a->plugin\"'; $string['cannotsavedata'] = 'Cannot save data'; $string['cannotsavefile'] = 'Cannot save the file \"$a\"!'; $string['cannotsavemd5file'] = 'Cannot save md5 file'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index fe16067cea..3df314d062 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -674,7 +674,7 @@ function html_is_blank($string) { * @param string $value the value to set (without magic quotes) * @param string $plugin (optional) the plugin scope * @uses $CFG - * @return bool + * @return bool true or exception */ function set_config($name, $value, $plugin=NULL) { global $CFG, $DB; @@ -690,39 +690,39 @@ function set_config($name, $value, $plugin=NULL) { } if ($DB->get_field('config', 'name', array('name'=>$name))) { - if ($value===null) { - return $DB->delete_records('config', array('name'=>$name)); + if ($value === null) { + $DB->delete_records('config', array('name'=>$name)); } else { - return $DB->set_field('config', 'value', $value, array('name'=>$name)); + $DB->set_field('config', 'value', $value, array('name'=>$name)); } } else { - if ($value===null) { - return true; + if ($value !== null) { + $config = new object(); + $config->name = $name; + $config->value = $value; + $DB->insert_record('config', $config, false); } - $config = new object(); - $config->name = $name; - $config->value = $value; - return $DB->insert_record('config', $config, false); } } else { // plugin scope if ($id = $DB->get_field('config_plugins', 'id', array('name'=>$name, 'plugin'=>$plugin))) { if ($value===null) { - return $DB->delete_records('config_plugins', array('name'=>$name, 'plugin'=>$plugin)); + $DB->delete_records('config_plugins', array('name'=>$name, 'plugin'=>$plugin)); } else { - return $DB->set_field('config_plugins', 'value', $value, array('id'=>$id)); + $DB->set_field('config_plugins', 'value', $value, array('id'=>$id)); } } else { - if ($value===null) { - return true; + if ($value !== null) { + $config = new object(); + $config->plugin = $plugin; + $config->name = $name; + $config->value = $value; + $DB->insert_record('config_plugins', $config, false); } - $config = new object(); - $config->plugin = $plugin; - $config->name = $name; - $config->value = $value; - return $DB->insert_record('config_plugins', $config, false); } } + + return true; } /** -- 2.39.5