From fd14eb5c401c729d2ffa34f94870001f6f453279 Mon Sep 17 00:00:00 2001 From: Daniel Kosinski Date: Thu, 26 Feb 2015 21:42:53 +0100 Subject: [PATCH] MDL-46705 admin: Check if course with same shortname already exists --- lib/adminlib.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/adminlib.php b/lib/adminlib.php index 37da3db1b7e..c0c44656e44 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3947,10 +3947,14 @@ class admin_setting_sitesettext extends admin_setting_configtext { * @return mixed true or message string */ public function validate($data) { + global $DB; $cleaned = clean_param($data, PARAM_TEXT); if ($cleaned === '') { return get_string('required'); } + if ($this->name ==='shortname' && $DB->record_exists('course', array('shortname' => $data))) { + return get_string('shortnametaken', 'error', $data); + } if ("$data" == "$cleaned") { // implicit conversion to string is needed to do exact comparison return true; } else {