Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-55209

removing idnumber from a category leads to an exception

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1, 3.1.1
    • Fix Version/s: 3.1.4
    • Component/s: Administration
    • Labels:
    • Testing Instructions:
      Hide
      1. Create some categories:
        Category name ID Number
        Cat 1  
        Cat 2 0
        Cat 3 00
      2. From the course management page edit Cat 2
      3. Delete the value of the 'Category ID number' field and save
      4. The category management page should display with no errors, the category should no longer display an idnumber.
      5. Edit it again, and try to give it a new idnumber "00"
        1. You should not be able to make this change
      Show
      Create some categories: Category name ID Number Cat 1   Cat 2 0 Cat 3 00 From the course management page edit Cat 2 Delete the value of the 'Category ID number' field and save The category management page should display with no errors, the category should no longer display an idnumber. Edit it again, and try to give it a new idnumber " 00 " You should not be able to make this change
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_31_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      1. edit a category, assign a idnumber to a category and save
      2. edit category again, remove idnumber and save

      expected behaviour: idnumber will be removed
      current behaviour: an exception is thrown

      Debug info:
      Error code: categoryidnumbertaken
       
      Stack trace:
          line 492 of /lib/coursecatlib.php: moodle_exception thrown
          line 106 of /course/editcategory.php: call to coursecat->update()
      

      possible solution:
      I checked the code in coursecatlib.php, there is a different behaviour when handling the idnumber in create() and update():

      snippet from create(), line 364:

              // Validate and set idnumber.
              if (!empty($data->idnumber)) {
                  if (core_text::strlen($data->idnumber) > 100) {
                      throw new moodle_exception('idnumbertoolong');
                  }
                  if ($DB->record_exists('course_categories', array('idnumber' => $data->idnumber))) {
                      throw new moodle_exception('categoryidnumbertaken');
                  }
              }
              if (isset($data->idnumber)) {
                  $newcategory->idnumber = $data->idnumber;
              }
      

      snippet from update(), line 487:

              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))) {
                      throw new moodle_exception('categoryidnumbertaken');
                  }
                  $newcategory->idnumber = $data->idnumber;
              } 
      

      I think the code from create() should also be used in update(). At the moment, there is nor checked if idnumber is empty.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Jan/17