Commit 193f5d40 authored by Marina Glancy's avatar Marina Glancy Committed by David Monllaó
Browse files

MDL-46705 admin: Validate unique shortname for frontpage course

parent 685aa0b7
......@@ -3969,12 +3969,13 @@ class admin_setting_sitesettext extends admin_setting_configtext {
* @return mixed true or message string
*/
public function validate($data) {
global $DB;
global $DB, $SITE;
$cleaned = clean_param($data, PARAM_TEXT);
if ($cleaned === '') {
return get_string('required');
}
if ($this->name ==='shortname' && $DB->record_exists('course', array('shortname' => $data))) {
if ($this->name ==='shortname' &&
$DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data, $SITE->id))) {
return get_string('shortnametaken', 'error', $data);
}
if ("$data" == "$cleaned") { // implicit conversion to string is needed to do exact comparison
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment