MDL-55209 coursecat: Should be able to remove category idnumber

Users should be able to remove an idnumber from a category, before this
change when trying to delete an idnumber users would be told it already
existed.

This change also stops 0 from being allowed multiple times as an idnumber.
This commit is contained in:
Neill Magill 2016-10-31 15:45:00 +00:00
parent c10bfee49f
commit bd305a3973

View File

@ -361,15 +361,13 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
$newcategory->name = $data->name;
// Validate and set idnumber.
if (!empty($data->idnumber)) {
if (isset($data->idnumber)) {
if (core_text::strlen($data->idnumber) > 100) {
throw new moodle_exception('idnumbertoolong');
}
if ($DB->record_exists('course_categories', array('idnumber' => $data->idnumber))) {
if (strval($data->idnumber) !== '' && $DB->record_exists('course_categories', array('idnumber' => $data->idnumber))) {
throw new moodle_exception('categoryidnumbertaken');
}
}
if (isset($data->idnumber)) {
$newcategory->idnumber = $data->idnumber;
}
@ -484,11 +482,11 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
$newcategory->name = $data->name;
}
if (isset($data->idnumber) && $data->idnumber != $this->idnumber) {
if (isset($data->idnumber) && $data->idnumber !== $this->idnumber) {
if (core_text::strlen($data->idnumber) > 100) {
throw new moodle_exception('idnumbertoolong');
}
if ($DB->record_exists('course_categories', array('idnumber' => $data->idnumber))) {
if (strval($data->idnumber) !== '' && $DB->record_exists('course_categories', array('idnumber' => $data->idnumber))) {
throw new moodle_exception('categoryidnumbertaken');
}
$newcategory->idnumber = $data->idnumber;