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 79c995bc3d80fc29b36ae83d4acae0f57469eff1 1 parent 8319260
Jenny Gray jennymgray authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 user/profile/index_category_form.php
13 user/profile/index_category_form.php
View
@@ -33,10 +33,19 @@ function validation($data, $files) {
$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');
}
Please sign in to comment.
Something went wrong with that request. Please try again.