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

bug in cohort_update_cohort with component as NULL line 75

    XMLWordPrintable

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 = ''; }

      Attachments

        Activity

          People

            skodak Petr Skoda
            azrael Stephen
            Sam Hemelryk Sam Hemelryk
            Ankit Agarwal Ankit Agarwal
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Raquel Ortega, Sara Arjona (@sarjona), Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              12/Mar/12