MDL-64715 message: add support for self conversations

Added new MESSAGE_CONVERSATION_TYPE_SELF type for self-conversations
and upgraded legacy self-conversations to the new type, removing
repeated members in the message_conversation_members table.
Besides, from now, a self-conversation will be created by default for
all the existing users.

All the self-conversations have been also starred and a default message
will be displayed always to explain how to use them.
This commit is contained in:
Sara Arjona
2019-04-15 20:17:54 +02:00
parent fcd7f0f982
commit 734b198fd3
33 changed files with 1449 additions and 281 deletions
+12 -1
View File
@@ -122,7 +122,18 @@ class migrate_message_data extends \core\task\adhoc_task {
private function migrate_data($userid, $otheruserid) {
global $DB;
if (!$conversationid = \core_message\api::get_conversation_between_users([$userid, $otheruserid])) {
if ($userid == $otheruserid) {
// Since 3.7, pending self-conversations should be migrated during the upgrading process so shouldn't be any
// self-conversations on the legacy tables. However, this extra-check has been added just in case.
$conversation = \core_message\api::get_self_conversation($userid);
if (empty($conversation)) {
$conversation = \core_message\api::create_conversation(
\core_message\api::MESSAGE_CONVERSATION_TYPE_SELF,
[$userid]
);
}
$conversationid = $conversation->id;
} else if (!$conversationid = \core_message\api::get_conversation_between_users([$userid, $otheruserid])) {
$conversation = \core_message\api::create_conversation(
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
[