Commit bd305a39 authored by Neill Magill's avatar Neill Magill
Browse files

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.
parent c10bfee4
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment