private function migrate_message($conversationid, $message) {
        global $DB;

        // Create the object we will be inserting into the database.
        $tabledata = new \stdClass();
        $tabledata->useridfrom = $message->useridfrom;
        $tabledata->conversationid = $conversationid;
        $tabledata->subject = $message->subject;
        $tabledata->fullmessage = $message->fullmessage;
        $tabledata->fullmessageformat = $message->fullmessageformat ?? FORMAT_MOODLE;
        $tabledata->fullmessagehtml = $message->fullmessagehtml;
        $tabledata->smallmessage = $message->smallmessage;
        $tabledata->timecreated = $message->timecreated;

        $messageid = $DB->insert_record('messages', $tabledata);

        // Check if we need to mark this message as deleted for the user from.
        if ($message->timeuserfromdeleted) {
            $mua = new \stdClass();
            $mua->userid = $message->useridfrom;
            $mua->messageid = $messageid;
            $mua->action = \core_message\api::MESSAGE_ACTION_DELETED;
            $mua->timecreated = $message->timeuserfromdeleted;

            $DB->insert_record('message_user_actions', $mua);
        }

        // Check if we need to mark this message as deleted for the user to.
        if ($message->timeusertodeleted and ($message->useridfrom != $message->useridto)) {
            $mua = new \stdClass();
            $mua->userid = $message->useridto;
            $mua->messageid = $messageid;
            $mua->action = \core_message\api::MESSAGE_ACTION_DELETED;
            $mua->timecreated = $message->timeusertodeleted;

            $DB->insert_record('message_user_actions', $mua);
        }

        // Check if we need to mark this message as read for the user to (it is always read by the user from).
        // Note - we do an isset() check here because this column only exists in the 'message_read' table.
        if (isset($message->timeread)) {
            $mua = new \stdClass();
            $mua->userid = $message->useridto;
            $mua->messageid = $messageid;
            $mua->action = \core_message\api::MESSAGE_ACTION_READ;
            $mua->timecreated = $message->timeread;

            $DB->insert_record('message_user_actions', $mua);
        }
    }