MDL-54973 message: Taking care of support and noreply users on search
authorDavid Monllao <davidm@moodle.com>
Wed, 17 Aug 2016 04:41:48 +0000 (12:41 +0800)
committerDavid Monllao <davidm@moodle.com>
Wed, 17 Aug 2016 04:41:48 +0000 (12:41 +0800)
message/classes/search/base_message.php
message/classes/search/message_received.php
message/classes/search/message_sent.php

index 9267c7d..435bc54 100644 (file)
@@ -43,17 +43,6 @@ abstract class base_message extends \core_search\base {
      */
     protected static $levels = [CONTEXT_USER];
 
-    /**
-     * Returns recordset containing message records.
-     *
-     * @param int $modifiedfrom timestamp
-     * @return \moodle_recordset
-     */
-    public function get_recordset_by_timestamp($modifiedfrom = 0) {
-        global $DB;
-        return $DB->get_recordset_select('message_read', 'timecreated >= ?', array($modifiedfrom), 'timecreated ASC');
-    }
-
     /**
      * Returns the document associated with this message record.
      *
@@ -135,4 +124,4 @@ abstract class base_message extends \core_search\base {
         return $users;
     }
 
-}
\ No newline at end of file
+}
index eaf9d00..f57dc9f 100644 (file)
@@ -35,6 +35,22 @@ defined('MOODLE_INTERNAL') || die();
  */
 class message_received extends base_message {
 
+    /**
+     * Returns recordset containing message records.
+     *
+     * @param int $modifiedfrom timestamp
+     * @return \moodle_recordset
+     */
+    public function get_recordset_by_timestamp($modifiedfrom = 0) {
+        global $DB;
+
+        // We don't want to index messages received from noreply and support users.
+        $params = array('modifiedfrom' => $modifiedfrom, 'noreplyuser' => \core_user::NOREPLY_USER,
+            'supportuser' => \core_user::SUPPORT_USER);
+        return $DB->get_recordset_select('message_read', 'timecreated >= :modifiedfrom AND
+            useridto != :noreplyuser AND useridto != :supportuser', $params, 'timecreated ASC');
+    }
+
     /**
      * Returns the document associated with this message record.
      *
@@ -64,8 +80,8 @@ class message_received extends base_message {
             return \core_search\manager::ACCESS_DELETED;
         }
 
-        $userfrom = $DB->get_record('user', array('id' => $message->useridfrom));
-        $userto = $DB->get_record('user', array('id' => $message->useridto));
+        $userfrom = \core_user::get_user($message->useridfrom, 'id, deleted');
+        $userto = \core_user::get_user($message->useridto, 'id, deleted');
 
         if (!$userfrom || !$userto || $userfrom->deleted || $userto->deleted) {
             return \core_search\manager::ACCESS_DELETED;
@@ -82,4 +98,4 @@ class message_received extends base_message {
         return \core_search\manager::ACCESS_GRANTED;
     }
 
-}
\ No newline at end of file
+}
index b92e459..f0ab8d3 100644 (file)
@@ -34,6 +34,22 @@ defined('MOODLE_INTERNAL') || die();
  */
 class message_sent extends base_message {
 
+    /**
+     * Returns recordset containing message records.
+     *
+     * @param int $modifiedfrom timestamp
+     * @return \moodle_recordset
+     */
+    public function get_recordset_by_timestamp($modifiedfrom = 0) {
+        global $DB;
+
+        // We don't want to index messages sent by noreply and support users.
+        $params = array('modifiedfrom' => $modifiedfrom, 'noreplyuser' => \core_user::NOREPLY_USER,
+            'supportuser' => \core_user::SUPPORT_USER);
+        return $DB->get_recordset_select('message_read', 'timecreated >= :modifiedfrom AND
+            useridfrom != :noreplyuser AND useridfrom != :supportuser', $params, 'timecreated ASC');
+    }
+
     /**
      * Returns the document associated with this message record.
      *
@@ -63,8 +79,8 @@ class message_sent extends base_message {
             return \core_search\manager::ACCESS_DELETED;
         }
 
-        $userfrom = $DB->get_record('user', array('id' => $message->useridfrom));
-        $userto = $DB->get_record('user', array('id' => $message->useridto));
+        $userfrom = \core_user::get_user($message->useridfrom, 'id, deleted');
+        $userto = \core_user::get_user($message->useridto, 'id, deleted');
 
         if (!$userfrom || !$userto || $userfrom->deleted || $userto->deleted) {
             return \core_search\manager::ACCESS_DELETED;
@@ -81,4 +97,4 @@ class message_sent extends base_message {
         return \core_search\manager::ACCESS_GRANTED;
     }
 
-}
\ No newline at end of file
+}