MDL-36941 core: convert existing api to use new table structure

Also deprecated the following functions -

1. message_move_userfrom_unread2read - It is not necessary
   for us to mark a message as read on user deletion.
2. message_get_blocked_users - Horrible logic used to
   determine if a user is blocked via reference on some
   randomly chosen 'isblocked' variable.
3. message_get_contacts - The same as above. This can be
   done in a much nicer way.
4. message_mark_message_read - We want two functions to do
   this to avoid confusing messages and notifications.
5. message_can_delete_message - This assumed the variable
   $message contained the 'useridto' property, which
   was present in the old table structure. We do not want
   future usages where a query is done on the new table
   and is simply passed as this won't contain this property.
6. message_delete_message - Same as above.
This commit is contained in:
Mark Nelson 2018-01-04 15:01:37 +08:00
parent 4cd439887a
commit 883ce42127
29 changed files with 1714 additions and 1096 deletions

View file

@ -145,9 +145,15 @@ abstract class base_message extends \core_search\base {
$userfield) {
global $DB;
if ($userfield == 'useridto') {
$userfield = 'mcm.userid';
} else {
$userfield = 'm.useridfrom';
}
// Set up basic query.
$where = $userfield . ' != :noreplyuser AND ' . $userfield .
' != :supportuser AND timecreated >= :modifiedfrom';
' != :supportuser AND m.timecreated >= :modifiedfrom';
$params = [
'noreplyuser' => \core_user::NOREPLY_USER,
'supportuser' => \core_user::SUPPORT_USER,
@ -179,6 +185,15 @@ abstract class base_message extends \core_search\base {
throw new \coding_exception('Unexpected contextlevel: ' . $context->contextlevel);
}
return $DB->get_recordset_select('message_read', $where, $params, 'timeread ASC');
$sql = "SELECT m.*, mcm.userid as useridto
FROM {messages} m
INNER JOIN {message_conversations} mc
ON m.conversationid = mc.id
INNER JOIN {message_conversation_members} mcm
ON mcm.conversationid = mc.id
WHERE mcm.userid != m.useridfrom
AND $where
ORDER BY m.timecreated ASC";
return $DB->get_recordset_sql($sql, $params);
}
}