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

bug in cohort_update_cohort with component as NULL line 75

    Details

      Description

      Manually created cohorts (these cohorts have their component set to empty string '' and not NULL) can be updated via code to add members, or remove members.

      Yet when using the cohort_update_cohort function for a manually created cohort it takes empty string component values and sets to NULL. Null values are not allowed for this in the DB which produces an error.

      !!! Error writing to database !!!
      Default exception handler: Error writing to database Debug: Column 'component' cannot be null
      UPDATE mdl_cohort SET contextid = ?,name = ?,idnumber = ?,description = ?,descriptionformat = ?,component = ?,timecreated = ?,timemodified = ? WHERE id=?
      [array (
      0 => '1',
      1 => 'All_Laws_Students',
      2 => 'All_Laws_Students',
      3 => 'Created:2012-02-27-153626 and updated 2012-02-28-003204',
      4 => '1',
      5 => NULL,
      6 => '1330353386',
      7 => 1330385524,
      8 => '1250',
      )]

      • line 397 of \lib\dml\moodle_database.php: dml_write_exception thrown
      • line 999 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
      • line 1031 of \lib\dml\mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->update_record_raw()
      • line 78 of \cohort\lib.php: call to mysqli_native_moodle_database->update_record()
      • line 427 of \auth\ldap\cli\sync_cohorts.php: call to cohort_update_cohort()

      Code says (approx lines 74-76):
      if (isset($cohort->component) and empty($cohort->component))

      { $cohort->component = NULL; }

      This should instead be:
      if (isset($cohort->component) and empty($cohort->component))

      { $cohort->component = ''; }

      This will match with cohort_add_cohort which does (lines 50-52):
      if (empty($cohort->component)) { $cohort->component = ''; }

        Gliffy Diagrams

          Activity

          azrael Stephen created issue -
          skodak Petr Skoda made changes -
          Field Original Value New Value
          Fix Version/s STABLE backlog [ 10463 ]
          Labels triaged
          skodak Petr Skoda made changes -
          Status Open [ 1 ] Development in progress [ 3 ]
          skodak Petr Skoda made changes -
          Status Development in progress [ 3 ] Waiting for integration review [ 10010 ]
          Pull Master Diff URL https://github.com/skodak/moodle/compare/master...w09_MDL-31807_m23_cohort
          Pull Master Branch w09_MDL-31807_m23_cohort
          Pull 2.0 Diff URL https://github.com/skodak/moodle/compare/MOODLE_20_STABLE...w09_MDL-31807_m20_cohort
          Pull from Repository git://github.com/skodak/moodle.git
          Pull 2.0 Branch w09_MDL-31807_m20_cohort
          Fix Version/s 2.0.8 [ 11554 ]
          Fix Version/s 2.1.5 [ 11553 ]
          Fix Version/s 2.2.2 [ 11552 ]
          Fix Version/s 2.3 [ 10657 ]
          Fix Version/s STABLE backlog [ 10463 ]
          Testing Instructions for developers:
          1/ create cohort in web UI
          2/ fetch one cohort record with no component
          3/ do cohort_update_cohort($cohort)
          Pull 2.1 Branch w09_MDL-31807_m21_cohort
          Pull 2.2 Diff URL https://github.com/skodak/moodle/compare/MOODLE_22_STABLE...w09_MDL-31807_m22_cohort
          Pull 2.1 Diff URL https://github.com/skodak/moodle/compare/MOODLE_21_STABLE...w09_MDL-31807_m21_cohort
          Pull 2.2 Branch w09_MDL-31807_m22_cohort
          skodak Petr Skoda made changes -
          Status Waiting for integration review [ 10010 ] Reopened [ 4 ]
          samhemelryk Sam Hemelryk made changes -
          Currently in integration Yes [ 10041 ]
          samhemelryk Sam Hemelryk made changes -
          Status Waiting for integration review [ 10010 ] Integration review in progress [ 10004 ]
          Integrator samhemelryk
          samhemelryk Sam Hemelryk made changes -
          Status Integration review in progress [ 10004 ] Waiting for testing [ 10005 ]
          Fix Version/s 2.3 [ 10657 ]
          salvetore Michael de Raadt made changes -
          Tester ankit_frenz
          ankit_frenz Ankit Agarwal made changes -
          Status Waiting for testing [ 10005 ] Testing in progress [ 10011 ]
          ankit_frenz Ankit Agarwal made changes -
          Status Testing in progress [ 10011 ] Tested [ 10006 ]
          stronk7 Eloy Lafuente (stronk7) made changes -
          Status Tested [ 10006 ] Closed [ 6 ]
          Resolution Fixed [ 1 ]
          Currently in integration Yes [ 10041 ]
          Integration date 09/Mar/12

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                12/Mar/12