Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-41256 course: improved debugging on course creation

  • Loading branch information...
commit 9930e4267cd26cd0ec1d697a10db0a55d3e3a704 1 parent 838d78a
@mackensen mackensen authored
View
4 course/externallib.php
@@ -721,7 +721,7 @@ public static function update_courses($courses) {
if (array_key_exists('shortname', $course) && ($oldcourse->shortname != $course['shortname'])) {
require_capability('moodle/course:changeshortname', $context);
if ($DB->record_exists('course', array('shortname' => $course['shortname']))) {
- throw new moodle_exception('shortnametaken');
+ throw new moodle_exception('shortnametaken', '', '', $course['shortname']);
}
}
@@ -729,7 +729,7 @@ public static function update_courses($courses) {
if (array_key_exists('idnumber', $course) && ($oldcourse->idnumber != $course['idnumber'])) {
require_capability('moodle/course:changeidnumber', $context);
if ($DB->record_exists('course', array('idnumber' => $course['idnumber']))) {
- throw new moodle_exception('idnumbertaken');
+ throw new moodle_exception('courseidnumbertaken', '', '', $course['idnumber']);
}
}
View
8 course/lib.php
@@ -2234,17 +2234,17 @@ function create_course($data, $editoroptions = NULL) {
//check the categoryid - must be given for all new courses
$category = $DB->get_record('course_categories', array('id'=>$data->category), '*', MUST_EXIST);
- //check if the shortname already exist
+ // Check if the shortname already exists.
if (!empty($data->shortname)) {
if ($DB->record_exists('course', array('shortname' => $data->shortname))) {
- throw new moodle_exception('shortnametaken');
+ throw new moodle_exception('shortnametaken', '', '', $data->shortname);
}
}
- //check if the id number already exist
+ // Check if the idnumber already exists.
if (!empty($data->idnumber)) {
if ($DB->record_exists('course', array('idnumber' => $data->idnumber))) {
- throw new moodle_exception('idnumbertaken');
+ throw new moodle_exception('courseidnumbertaken', '', '', $data->idnumber);
}
}
View
17 course/tests/courselib_test.php
@@ -602,6 +602,23 @@ public function test_create_course() {
// Ensure blocks have been associated to the course.
$blockcount = $DB->count_records('block_instances', array('parentcontextid' => $context->id));
$this->assertGreaterThan(0, $blockcount);
+
+ // Ensure that the shortname isn't duplicated.
+ try {
+ $created = create_course($course);
+ } catch (moodle_exception $e) {
+ $message = $e->getMessage();
+ }
+ $this->assertEquals($message, get_string('shortnametaken', 'error', $course->shortname));
+
+ // Ensure that the idnumber isn't duplicated.
+ $course->shortname .= '1';
+ try {
+ $created = create_course($course);
+ } catch (moodle_exception $e) {
+ $message = $e->getMessage();
+ }
+ $this->assertEquals($message, get_string('courseidnumbertaken', 'error', $course->idnumber));
}
public function test_create_course_with_generator() {
View
5 lang/en/error.php
@@ -177,6 +177,7 @@
$string['courseformatnotfound'] = 'The course format \'{$a}\' doesn\'t exist or is not recognized';
$string['coursegroupunknown'] = 'Course corresponding to group {$a} not specified';
$string['courseidnotfound'] = 'Course id doesn\'t exist';
+$string['courseidnumbertaken'] = 'ID number is already used for another course ({$a})';
$string['coursemisconf'] = 'Course is misconfigured';
$string['courserequestdisabled'] = 'Sorry, but course requests have been disabled by the administrator.';
$string['csvcolumnduplicates'] = 'Duplicate columns detected';
@@ -267,7 +268,7 @@
$string['hackdetected'] = 'Hack attack detected!';
$string['hashpoolproblem'] = 'Incorrect pool file content {$a}.';
$string['headersent'] = 'Headers already sent';
-$string['idnumbertaken'] = 'ID number is already used for another course';
+$string['idnumbertaken'] = 'This ID number is already in use';
$string['idnumbertoolong'] = 'ID number is too long';
$string['importformatnotimplement'] = 'Sorry, importing this format is not yet implemented!';
$string['incorrectext'] = 'File has an incorrect extension';
@@ -469,7 +470,7 @@
$string['sessionerroruser2'] = 'A server error that affects your login session was detected. Please login again or restart your browser.';
$string['sessionipnomatch'] = 'Sorry, but your IP number seems to have changed from when you first logged in. This security feature prevents crackers stealing your identity while logged in to this site. Normal users should not be seeing this message - please ask the site administrator for help.';
$string['sessionipnomatch2'] = 'Sorry, but your IP number seems to have changed from when you first logged in. This security feature prevents crackers stealing your identity while logged in to this site. You may see this error if you use wireless networks or if you are roaming between different networks. Please ask the site administrator for more help.<br /><br />If you want to continue please press F5 key to refresh this page.';
-$string['shortnametaken'] = 'Short name is already used for another course';
+$string['shortnametaken'] = 'Short name is already used for another course ({$a})';
$string['scheduledbackupsdisabled'] = 'Scheduled backups have been disabled by the server admin';
$string['socksnotsupported'] = 'SOCKS5 proxy is not supported in PHP4';
$string['spellcheckernotconf'] = 'Spellchecker not configured';
Please sign in to comment.
Something went wrong with that request. Please try again.