From 7bfea4b502e5ef17817fb50c97ffa60bd57e5cdc Mon Sep 17 00:00:00 2001 From: Jenny Gray Date: Wed, 4 Nov 2009 12:16:18 +0000 Subject: [PATCH] MDL-20665 fixed error from postgres on validating duplicate category name when entering new category --- user/profile/index_category_form.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/user/profile/index_category_form.php b/user/profile/index_category_form.php index 940e9a804ee..314ea917385 100644 --- a/user/profile/index_category_form.php +++ b/user/profile/index_category_form.php @@ -33,10 +33,19 @@ class category_form extends moodleform { $data = (object)$data; - $category = get_record('user_info_category', 'id', $data->id); + $duplicate = record_exists('user_info_category', 'name', $data->name); /// Check the name is unique - if ($category and ($category->name !== $data->name) and (record_exists('user_info_category', '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'); }