Merge branch 'MDL-48089-master' of git://github.com/danpoltawski/moodle
authorDavid Monllao <davidm@moodle.com>
Wed, 20 Apr 2016 04:24:07 +0000 (12:24 +0800)
committerDavid Monllao <davidm@moodle.com>
Wed, 20 Apr 2016 04:24:07 +0000 (12:24 +0800)
mod/forum/classes/observer.php

index cc43934..adfb432 100644 (file)
@@ -41,8 +41,11 @@ class mod_forum_observer {
         // Get user enrolment info from event.
         $cp = (object)$event->other['userenrolment'];
         if ($cp->lastenrol) {
-            $params = array('userid' => $cp->userid, 'courseid' => $cp->courseid);
-            $forumselect = "IN (SELECT f.id FROM {forum} f WHERE f.course = :courseid)";
+            if (!$forums = $DB->get_records('forum', array('course' => $cp->courseid), '', 'id')) {
+                return;
+            }
+            list($forumselect, $params) = $DB->get_in_or_equal(array_keys($forums), SQL_PARAMS_NAMED);
+            $params['userid'] = $cp->userid;
 
             $DB->delete_records_select('forum_digests', 'userid = :userid AND forum '.$forumselect, $params);
             $DB->delete_records_select('forum_subscriptions', 'userid = :userid AND forum '.$forumselect, $params);