Permalink
Browse files

MDL-39667 repository: Correct check for uniqueness of the name

  • Loading branch information...
1 parent f6735ae commit d35705102c406f6696a2e85354e35e50143c7516 @FMCorz FMCorz committed May 13, 2013
Showing with 5 additions and 0 deletions.
  1. +5 −0 repository/lib.php
View
@@ -2684,6 +2684,7 @@ public function validation($data, $files) {
$instance = (isset($this->_customdata['instance'])
&& is_subclass_of($this->_customdata['instance'], 'repository'))
? $this->_customdata['instance'] : null;
+
if (!$instance) {
$errors = repository::static_function($plugin, 'instance_form_validation', $this, $data, $errors);
} else {
@@ -2694,6 +2695,10 @@ public function validation($data, $files) {
FROM {repository_instances} i, {repository} r
WHERE r.type=:plugin AND r.id=i.typeid AND i.name=:name AND i.contextid=:contextid";
$params = array('name' => $data['name'], 'plugin' => $this->plugin, 'contextid' => $this->contextid);
+ if ($instance) {
+ $sql .= ' AND i.id != :instanceid';
+ $params['instanceid'] = $instance->id;
+ }
if ($DB->count_records_sql($sql, $params) > 0) {
$errors['name'] = get_string('erroruniquename', 'repository');
}

0 comments on commit d357051

Please sign in to comment.