mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 05:54:19 +02:00
MDL-18293 exception and DML cleanup
This commit is contained in:
parent
b25263ffa1
commit
5e2f308b91
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user