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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 2.3.1
    • Fix Version/s: None
    • Component/s: Enrolments
    • Labels:
    • Affected Branches:
      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

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

                Dates

                Created:
                Updated:
                Resolved: