diff --git a/message/classes/search/base_message.php b/message/classes/search/base_message.php index 9267c7d7561..435bc545cab 100644 --- a/message/classes/search/base_message.php +++ b/message/classes/search/base_message.php @@ -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 +} diff --git a/message/classes/search/message_received.php b/message/classes/search/message_received.php index eaf9d002e25..f57dc9fe248 100644 --- a/message/classes/search/message_received.php +++ b/message/classes/search/message_received.php @@ -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 +} diff --git a/message/classes/search/message_sent.php b/message/classes/search/message_sent.php index b92e459b633..f0ab8d3ba8a 100644 --- a/message/classes/search/message_sent.php +++ b/message/classes/search/message_sent.php @@ -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 +}