Permalink
Browse files

MDL-25418 glossary - fixed and improved duplicate entries buggy queries

  • Loading branch information...
1 parent 9c5cafd commit 3e7d386625452589d059716139e043302ad8c6a2 @stronk7 stronk7 committed Dec 1, 2010
Showing with 10 additions and 10 deletions.
  1. +10 −10 mod/glossary/edit_form.php
View
@@ -107,21 +107,21 @@ function validation($data, $files) {
}
}
if (!$glossary->allowduplicatedentries) {
- if ($dupentries = $DB->get_records('glossary_entries', array('LOWER(concept)'=>moodle_strtolower($data['concept'])))) {
- foreach ($dupentries as $curentry) {
- if ($glossary->id == $curentry->glossaryid) {
- if ($curentry->id != $id) {
- $errors['concept'] = get_string('errconceptalreadyexists', 'glossary');
- break;
- }
- }
- }
+ if ($DB->record_exists_select('glossary_entries',
+ 'glossaryid = :glossaryid AND LOWER(concept) = :concept AND id != :id', array(
+ 'glossaryid' => $glossary->id,
+ 'concept' => moodle_strtolower($data['concept']),
+ 'id' => $id))) {
+ $errors['concept'] = get_string('errconceptalreadyexists', 'glossary');
}
}
} else {
if (!$glossary->allowduplicatedentries) {
- if ($dupentries = $DB->get_record('glossary_entries', array('LOWER(concept)'=>moodle_strtolower($data['concept']), 'glossaryid'=>$glossary->id))) {
+ if ($DB->record_exists_select('glossary_entries',
+ 'glossaryid = :glossaryid AND LOWER(concept) = :concept', array(
+ 'glossaryid' => $glossary->id,
+ 'concept' => moodle_strtolower($data['concept'])))) {
$errors['concept'] = get_string('errconceptalreadyexists', 'glossary');
}
}

0 comments on commit 3e7d386

Please sign in to comment.