mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-20665 fixed error from postgres on validating duplicate category name when entering new category
This commit is contained in:
parent
8319260833
commit
79c995bc3d
@ -33,10 +33,19 @@ class category_form extends moodleform {
|
||||
|
||||
$data = (object)$data;
|
||||
|
||||
$category = $DB->get_record('user_info_category', array('id'=>$data->id));
|
||||
$duplicate = $DB->record_exists('user_info_category', array('name'=>$data->name));
|
||||
|
||||
/// Check the name is unique
|
||||
if ($category and ($category->name !== $data->name) and ($DB->record_exists('user_info_category', array('name'=>$data->name)))) {
|
||||
if (!empty($data->id)) { // we are editing an existing record
|
||||
$olddata = get_record('user_info_category', 'id', $data->id);
|
||||
// name has changed, new name in use, new name in use by another record
|
||||
$dupfound = (($olddata->name !== $data->name) && $duplicate && ($data->id != $duplicate->id));
|
||||
}
|
||||
else { // new profile category
|
||||
$dupfound = $duplicate;
|
||||
}
|
||||
|
||||
if ($dupfound ) {
|
||||
$errors['name'] = get_string('profilecategorynamenotunique', 'admin');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user