]> git.mjollnir.org Git - moodle.git/commitdiff
Merged fixes for MDL-8785 from 1.8 to head
authormoodler <moodler>
Wed, 7 Mar 2007 04:56:07 +0000 (04:56 +0000)
committermoodler <moodler>
Wed, 7 Mar 2007 04:56:07 +0000 (04:56 +0000)
admin/cron.php
lib/accesslib.php

index 17cbf97abeee084979924821914c2cc8236a2cb7..334c6069c7e821cce70b7a99664dd2df1ebf6085 100644 (file)
 
         }
     }
-    mtrace("Finished blocks");
+    mtrace('Finished blocks');
 
     if (!empty($CFG->langcache)) {
         mtrace('Updating languages cache');
         get_list_of_languages();
     }
 
+    mtrace('Removing expired enrolments ...', '');     // See MDL-8785
+    $timenow = time();
+    if ($oldenrolments = get_records_select('role_assignments', "timeend > 0 AND timeend < '$timenow'")) {
+        mtrace(count($oldenrolments).' to delete');
+        foreach ($oldenrolments as $oldenrolment) {
+            if (role_unassign($oldenrolment->roleid, $oldenrolment->userid, 0, $oldenrolment->contextid)) {
+                mtrace("Deleted expired role assignment $oldenrolment->roleid for user $oldenrolment->userid from context $oldenrolment->contextid");
+            }
+        }
+        mtrace('Done');
+    } else {
+        mtrace('none found');
+    }
+
 
 /// Run all core cron jobs, but not every time since they aren't too important.
 /// These don't have a timer to reduce load, so we'll use a random number 
index fd93f26e3aa1a6a380d812caf2a4cfee349235be..dea67cde83eca8a92906d64b9d75b41204e5a26a 100755 (executable)
@@ -869,10 +869,6 @@ function load_user_capability($capability='', $context = NULL, $userid='') {
         $capsearch ="";
     }
 
-/// Set up SQL fragments for timestart, timeend etc
-    $now = time();
-    $timesql = "AND ((ra.timestart = 0 OR ra.timestart < $now) AND (ra.timeend = 0 OR ra.timeend > $now))";
-
 /// Then we use 1 giant SQL to bring out all relevant capabilities.
 /// The first part gets the capabilities of orginal role.
 /// The second part gets the capabilities of overriden roles.
@@ -894,7 +890,6 @@ function load_user_capability($capability='', $context = NULL, $userid='') {
                      $searchcontexts1
                      rc.contextid=$siteinstance->id
                      $capsearch
-                     $timesql
               GROUP BY
                      rc.capability, c1.id, c1.contextlevel * 100
                      HAVING
@@ -915,7 +910,6 @@ function load_user_capability($capability='', $context = NULL, $userid='') {
                      $searchcontexts1
                      rc.contextid != $siteinstance->id
                      $capsearch
-                     $timesql
                      AND cr.c2 = c1.id
               GROUP BY
                      rc.capability, c1.id, c2.id, c1.contextlevel * 100 + c2.contextlevel
@@ -967,7 +961,6 @@ function load_user_capability($capability='', $context = NULL, $userid='') {
                      $searchcontexts1
                      rc.contextid != $siteinstance->id
                      $capsearch
-                     $timesql
 
               GROUP BY
                      rc.capability, (c1.contextlevel * 100 + c2.contextlevel), c1.id, c2.id, rc.permission
@@ -2115,7 +2108,9 @@ function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $time
         $newra->userid = $userid;
         $newra->hidden = $hidden;
         $newra->enrol = $enrol;
-        $newra->timestart = $timestart;
+    /// Always round timestart downto 100 secs to help DBs to use their own caching algorithms 
+    /// by repeating queries with the same exact parameters in a 100 secs time window
+        $newra->timestart = round($timestart, -2);
         $newra->timeend = $timeend;
         $newra->timemodified = time();
         $newra->modifierid = empty($USER->id) ? 0 : $USER->id;
@@ -2127,7 +2122,9 @@ function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $time
         $newra->id = $ra->id;
         $newra->hidden = $hidden;
         $newra->enrol = $enrol;
-        $newra->timestart = $timestart;
+    /// Always round timestart downto 100 secs to help DBs to use their own caching algorithms 
+    /// by repeating queries with the same exact parameters in a 100 secs time window
+        $newra->timestart = round($timestart, -2);
         $newra->timeend = $timeend;
         $newra->timemodified = time();
         $newra->modifierid = empty($USER->id) ? 0 : $USER->id;