Permalink
Browse files

MDL-33528 fix create_categories warnings + default parent parameter

  • Loading branch information...
mouneyrac committed Jun 5, 2012
1 parent 4db0616 commit 9615b623c6218bf0226acaebe7b5f188928d06fc
Showing with 15 additions and 13 deletions.
  1. +15 −13 course/externallib.php
View
@@ -1188,7 +1188,9 @@ public static function create_categories_parameters() {
array(
'name' => new external_value(PARAM_TEXT, 'new category name'),
'parent' => new external_value(PARAM_INT,
- 'the parent category id inside which the new category will be created'),
+ 'the parent category id inside which the new category will be created
+ - set to 0 for a root category',
+ VALUE_DEFAULT, 0),
'idnumber' => new external_value(PARAM_RAW,
'the new category idnumber', VALUE_OPTIONAL),
'description' => new external_value(PARAM_RAW,
@@ -1232,17 +1234,6 @@ public static function create_categories($categories) {
self::validate_context($context);
require_capability('moodle/category:manage', $context);
- // Check id number.
- if (!empty($category['idnumber'])) { // Same as in course/editcategory_form.php .
- if (textlib::strlen($category['idnumber'])>100) {
- throw new moodle_exception('idnumbertoolong');
- }
- if ($existing = $DB->get_record('course_categories', array('idnumber' => $category['idnumber']))) {
- if ($existing->id) {
- throw new moodle_exception('idnumbertaken');
- }
- }
- }
// Check name.
if (textlib::strlen($category['name'])>255) {
throw new moodle_exception('categorytoolong');
@@ -1251,7 +1242,6 @@ public static function create_categories($categories) {
$newcategory = new stdClass();
$newcategory->name = $category['name'];
$newcategory->parent = $category['parent'];
- $newcategory->idnumber = $category['idnumber'];
$newcategory->sortorder = 999; // Same as in the course/editcategory.php .
// Format the description.
if (!empty($category['description'])) {
@@ -1261,6 +1251,18 @@ public static function create_categories($categories) {
if (isset($category['theme']) and !empty($CFG->allowcategorythemes)) {
$newcategory->theme = $category['theme'];
}
+ // Check id number.
+ if (!empty($category['idnumber'])) { // Same as in course/editcategory_form.php .
+ if (textlib::strlen($category['idnumber'])>100) {
+ throw new moodle_exception('idnumbertoolong');
+ }
+ if ($existing = $DB->get_record('course_categories', array('idnumber' => $category['idnumber']))) {
+ if ($existing->id) {
+ throw new moodle_exception('idnumbertaken');
+ }
+ }
+ $newcategory->idnumber = $category['idnumber'];
+ }
$newcategory = create_course_category($newcategory);
// Populate special fields.

0 comments on commit 9615b62

Please sign in to comment.