]> git.mjollnir.org Git - moodle.git/commitdiff
ORPHAN_USER_LASTACCESS_PROBLEM . MDL-11604
authorstronk7 <stronk7>
Fri, 5 Oct 2007 22:27:55 +0000 (22:27 +0000)
committerstronk7 <stronk7>
Fri, 5 Oct 2007 22:27:55 +0000 (22:27 +0000)
admin/cron.php

index a3e7a8b6ae0a5199ee21ff49027646f2622b7ce3..6cba62bc96935d7eb2ac5dc8369a91191d123828 100644 (file)
                 }
             }
             rs_close($rs);
+        /// Execute the same query again, looking for remaining records and deleting them
+        /// if the user hasn't moodle/course:view in the CONTEXT_COURSE context (orphan records)
+            $rs = get_recordset_sql ("SELECT id, userid, courseid
+                                        FROM {$CFG->prefix}user_lastaccess
+                                       WHERE courseid != ".SITEID."
+                                         AND timeaccess < $cuttime ");
+            while ($assign = rs_fetch_next_record($rs)) {
+                if ($context = get_context_instance(CONTEXT_COURSE, $assign->courseid)) {
+                    if (!has_capability('moodle/course:view', $context, $assign->userid)) {
+                        delete_records('user_lastaccess', 'userid', $assign->userid, 'courseid', $assign->courseid);
+                        mtrace("Deleted orphan user_lastaccess for user $assign->userid from course $assign->courseid");
+                    }
+                }
+            }
+            rs_close($rs);
         }
         flush();