Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-20665 fixed error from postgres on validating duplicate category …

…name when entering new category
  • Loading branch information...
commit 7bfea4b502e5ef17817fb50c97ffa60bd57e5cdc 1 parent c3c76e6
@jennymgray jennymgray authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 user/profile/index_category_form.php
View
13 user/profile/index_category_form.php
@@ -33,10 +33,19 @@ function validation($data, $files) {
$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');
}
Please sign in to comment.
Something went wrong with that request. Please try again.