diff --git a/lang/en/repository.php b/lang/en/repository.php index babe63652e0..49050f045da 100644 --- a/lang/en/repository.php +++ b/lang/en/repository.php @@ -88,6 +88,7 @@ $string['entername'] = 'Please enter folder name'; $string['enternewname'] = 'Please enter the new file name'; $string['error'] = 'An unknown error occurred!'; $string['errornotyourfile'] = 'You cannot pick file which is not added by your'; +$string['erroruniquename'] = 'Repository instance name should be unique'; $string['existingrepository'] = 'This repository already exists'; $string['federatedsearch'] = 'Federated search'; $string['filename'] = 'Filename'; diff --git a/repository/filesystem/lib.php b/repository/filesystem/lib.php index 12ab6699803..da3e6ef5c5c 100644 --- a/repository/filesystem/lib.php +++ b/repository/filesystem/lib.php @@ -163,7 +163,7 @@ class repository_filesystem extends repository { } if (empty($choices)) { $mform->addElement('static', '', '', get_string('nosubdir', 'repository_filesystem', $path)); - $mform->addElement('hidden', 'fs_path', $fieldname, ''); + $mform->addElement('hidden', 'fs_path', ''); } else { $mform->addElement('select', 'fs_path', $fieldname, $choices); $mform->addElement('static', null, '', get_string('information','repository_filesystem', $path)); @@ -189,4 +189,10 @@ class repository_filesystem extends repository { return false; } } + public static function instance_form_validation($mform, $data, $errors) { + if (empty($data['fs_path'])) { + $errors['fs_path'] = get_string('invalidadminsettingname', 'error', 'fs_path'); + } + return $errors; + } } diff --git a/repository/lib.php b/repository/lib.php index 453e0679c44..eb2109653f7 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -1533,6 +1533,10 @@ abstract class repository { return array(); } + public static function instance_form_validation($mform, $data, $errors) { + return $errors; + } + public function get_short_filename($str, $maxlength) { if (strlen($str) >= $maxlength) { return trim(substr($str, 0, $maxlength)).'...'; @@ -1633,13 +1637,22 @@ final class repository_instance_form extends moodleform { public function validation($data) { global $DB; - $errors = array(); + $plugin = $this->_customdata['plugin']; + $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 { + $errors = $instance->instance_form_validation($this, $data, $errors); + } + $sql = "SELECT count('x') FROM {repository_instances} i, {repository} r WHERE r.type=:plugin AND r.id=i.typeid AND i.name=:name"; if ($DB->count_records_sql($sql, array('name' => $data['name'], 'plugin' => $data['plugin'])) > 1) { - $errors = array('name' => get_string('err_uniquename', 'repository')); + $errors['name'] = get_string('erroruniquename', 'repository'); } return $errors;