Moodle
  1. Moodle
  2. MDL-9937

End of session enrol/database enrollments not removed

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8
    • Fix Version/s: 2.0
    • Component/s: Enrolments
    • Labels:
      None
    • Database:
      Any
    • Affected Branches:
      MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Rank:
      29455

      Description

      If there are no remaining course enrollments for a particular role, the enrol/database logic will not terminate enrollments for the most recently ended class(es).

      Take the end of the semester for example. Assume a block schedule without overlapping terms. On the last day of the semester, a large group of students are enrolled in various courses. The semester ends, and all enrollments are removed in the external database table, leaving no enrollments for the student role. Since a query on the external database reveals no enrollments for that role, the current logic simply skips to the next role. The code should, however, still purge any remaining enrollments for that role.

      In enrol/database/enrol.php, v 1.37 line 208 and following, the if conditional is the culprit:
      208 if ( $rs->RecordCount() == 0 )

      { // no courses! outta here... 209 return true; 210 }

      This conditional should probably be inverted and surround the subsequent while loop, closing before.
      354 rs_close($rs); //Close the main course recordset

      The begin_sql() call will need to be moved up in this solution. E.g.

      begin_sql();
      if ( $rs->RecordCount() != 0 ) { // only fetch if courses found....
      $extcourses = array();
      while ($extcourse_obj = rs_fetch_next_record($rs))

      { // there are more course records ... etc ... }

      // end while course records
      }
      rs_close($rs); //Close the main course recordset

      Please verify this code... I haven't tested it enough to move it to our production server yet.

        Activity

        Hide
        Clinton Graham added a comment -

        Note that the "$extcourses = array();" line should also be moved outside of the condition:

        begin_sql();
        $extcourses = array();
        if ( $rs->RecordCount() != 0 ) { // only fetch if courses found....
        while ($extcourse_obj = rs_fetch_next_record($rs))

        { // there are more course records ... etc ... }

        // end while course records
        }
        rs_close($rs); //Close the main course recordset

        Show
        Clinton Graham added a comment - Note that the "$extcourses = array();" line should also be moved outside of the condition: begin_sql(); $extcourses = array(); if ( $rs->RecordCount() != 0 ) { // only fetch if courses found.... while ($extcourse_obj = rs_fetch_next_record($rs)) { // there are more course records ... etc ... } // end while course records } rs_close($rs); //Close the main course recordset
        Hide
        Yu Zhang added a comment -

        sorry one of my fixes is for MDL-9337 made a typo in commit so it will end up here.

        Show
        Yu Zhang added a comment - sorry one of my fixes is for MDL-9337 made a typo in commit so it will end up here.
        Hide
        Petr Škoda added a comment -

        This should be finally fixed in 2.0, thanks for the report.

        Show
        Petr Škoda added a comment - This should be finally fixed in 2.0, thanks for the report.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: