From 68bd2b313265af0c0b143caaf4e3e76102bf9377 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 ec96ece61ce..8c5751eeec1 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -4001,10 +4001,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 {