]> git.mjollnir.org Git - moodle.git/commitdiff
Fixes to unenrolling students, and unenrol_student() and remove_teacher()
authormartin <martin>
Sun, 22 Sep 2002 14:33:21 +0000 (14:33 +0000)
committermartin <martin>
Sun, 22 Sep 2002 14:33:21 +0000 (14:33 +0000)
now remove forum_subscriptions correctly

admin/cron.php
course/unenrol.php
lib/moodlelib.php

index 6cba97393f8c106a7edf50513ed67db119650e90..d6c9ba241607f6ac13261f74e598b25eede83223 100644 (file)
                                              lastaccess < '$cutofftime' AND
                                              u.id = s.user GROUP BY u.id")) {
             foreach ($users as $user) {
-                if (delete_records("user_students", "user", $user->id)) {
-
-                    // Delete other things ... this should be modular than it is right now:
-                    delete_records("forum_subscriptions", "user", $user->id);
-
+                if (unenrol_student($user->id)) {
                     echo "Deleted student enrolment for $user->firstname $user->lastname ($user->id)\n";
                 }
             }
index 2e4af9fea16f0f6b585973e36e9b5af229bdebc8..d5ce56600ade9f73f895e162a742fddad9979015 100644 (file)
@@ -30,9 +30,6 @@
             error("An error occurred while trying to unenrol you.");
         }
 
-        // remove some other things
-        delete_records("forum_subscriptions", "user", $user->id);
-
         add_to_log($course->id, "course", "unenrol", "view.php?id=$course->id", "$user->id");
 
         if ($user->id == $USER->id) {
index 10658146dbbf7fc4b305901c3abb8bddb0188937..ddda05e6a207db3dbcf05713e66231414ec283c0 100644 (file)
@@ -1045,9 +1045,16 @@ function remove_teacher($user, $course=0) {
     global $db;
 
     if ($course) {
+        /// First delete any crucial stuff that might still send mail
+        if ($forums = get_records("forum", "course", $course)) {
+            foreach ($forums as $forum) {
+                $db->Execute("DELETE FROM forum_subscriptions WHERE forum = '$forum->id' AND user = '$user'");
+            }
+        }
         return $db->Execute("DELETE FROM user_teachers WHERE user = '$user' AND course = '$course'");
     } else {
-        return $db->Execute("DELETE FROM user_teachers WHERE user = '$user'");
+        delete_records("forum_subscriptions", "user", $user);
+        return delete_records("user_teachers", "user", $user);
     }
 }
 
@@ -1070,9 +1077,17 @@ function unenrol_student($user, $course=0) {
     global $db;
 
     if ($course) {
+        /// First delete any crucial stuff that might still send mail
+        if ($forums = get_records("forum", "course", $course)) {
+            foreach ($forums as $forum) {
+                $db->Execute("DELETE FROM forum_subscriptions WHERE forum = '$forum->id' AND user = '$user'");
+            }
+        }
         return $db->Execute("DELETE FROM user_students WHERE user = '$user' AND course = '$course'");
+
     } else {
-        return $db->Execute("DELETE FROM user_students WHERE user = '$user'");
+        delete_records("forum_subscriptions", "user", $user);
+        return delete_records("user_students", "user", $user);
     }
 }