Skip to content

Commit

Permalink
MDL-18293 exception and DML cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Feb 17, 2009
1 parent b25263f commit 5e2f308
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 54 deletions.
4 changes: 1 addition & 3 deletions admin/auth_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
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);
Expand Down
11 changes: 2 additions & 9 deletions group/autogroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@
$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);
Expand All @@ -210,11 +207,7 @@
$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);
Expand Down
4 changes: 1 addition & 3 deletions group/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
}
$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);
Expand Down
8 changes: 2 additions & 6 deletions group/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@
} 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;
}

Expand Down
10 changes: 3 additions & 7 deletions group/grouping.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,17 @@
$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) {
Expand Down
8 changes: 2 additions & 6 deletions group/overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
$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();
Expand All @@ -54,9 +52,7 @@
}

// 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) {
Expand Down
1 change: 0 additions & 1 deletion lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
$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';
Expand Down
38 changes: 19 additions & 19 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 5e2f308

Please sign in to comment.