"MDL-23326, fixed undefined index in repository conf form, added validation function to repository plugin"
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user