From a853f15fc3938506616d136f4579b8cfb0847ecf Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Wed, 16 Sep 2015 14:38:52 +0800 Subject: [PATCH] MDL-46705 admin: Validate unique shortname for frontpage course --- lib/adminlib.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index c812b3b7ab1..debcc5f1e21 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -4001,12 +4001,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 -- 2.43.0