private function migrate_data($userid, $otheruserid) {
        global $DB;

        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,
                [
                    $userid,
                    $otheruserid
                ]
            );
            $conversationid = $conversation->id;
        }

        // First, get the rows from the 'message' table.
        $select = "(useridfrom = ? AND useridto = ?) OR (useridfrom = ? AND useridto = ?)";
        $params = [$userid, $otheruserid, $otheruserid, $userid];
        $messages = $DB->get_recordset_select('message', $select, $params, 'id ASC');
        foreach ($messages as $message) {
            if ($message->notification) {
                $this->migrate_notification($message, false);
            } else {
                $this->migrate_message($conversationid, $message);
            }
        }
        $messages->close();

        // Ok, all done, delete the records from the 'message' table.
        $DB->delete_records_select('message', $select, $params);

        // Now, get the rows from the 'message_read' table.
        $messages = $DB->get_recordset_select('message_read', $select, $params, 'id ASC');
        foreach ($messages as $message) {
            if ($message->notification) {
                $this->migrate_notification($message, true);
            } else {
                $this->migrate_message($conversationid, $message);
            }
        }
        $messages->close();

        // Ok, all done, delete the records from the 'message_read' table.
        $DB->delete_records_select('message_read', $select, $params);
    }