Merge branch 'MDL-41256-master' of https://github.com/mackensen/moodle

This commit is contained in:
Dan Poltawski 2013-09-03 10:51:27 +08:00
commit c6569641e7
4 changed files with 26 additions and 8 deletions

View File

@ -721,7 +721,7 @@ class core_course_external extends external_api {
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 @@ class core_course_external extends external_api {
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 File

@ -2260,17 +2260,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 File

@ -602,6 +602,23 @@ class core_course_courselib_testcase extends advanced_testcase {
// 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 File

@ -177,6 +177,7 @@ $string['coursedoesnotbelongtocategory'] = 'The course doesn\'t belong to this c
$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['guestsarenotallowed'] = 'The guest user is not allowed to do this';
$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['sessionerroruser'] = 'Your session has timed out. Please login again.'
$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';