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

cron() function in enrollib.php does not update expired enrolments

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • None
    • 2.3.1
    • Enrolments
    • MOODLE_23_STABLE

      I noticed that enrolments with enrolment periods set do not actually get removed once the period has passed. I think the reason this happens is because the cron() function in enrollib.php doesn't actually do anything.

      I'm using version 2.2.3, but it seems this function still does nothing in the newer versions of the code I've seen.

      Below is the code I'm using to remove expired enrolments:

      public function cron() {
      global $DB;

      // Unenrol course enrolments whose enrolment periods have passed
      $sql = "SELECT e.*, ue.userid
      FROM

      {enrol}

      e
      JOIN

      {user_enrolments}

      ue ON (ue.enrolid = e.id)
      WHERE ue.timeend < curdate() and ue.timeend != 0";

      $rs = $DB->get_recordset_sql($sql);
      foreach ($rs as $instance)

      { $this->unenrol_user($instance, $instance->userid); }

      $rs->close();
      }

            skodak Petr Skoda
            jmorello Jeff Morello
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.