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

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

    XMLWordPrintable

Details

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

    Description

      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();
      }

      Attachments

        Issue Links

          Activity

            People

              skodak Petr Skoda
              jmorello Jeff Morello
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: