diff --git a/database/2024_06_02_194809_base_sixty_four_encode_pms_in_db.php b/database/2024_06_02_194809_base_sixty_four_encode_pms_in_db.php new file mode 100644 index 0000000..7d130c9 --- /dev/null +++ b/database/2024_06_02_194809_base_sixty_four_encode_pms_in_db.php @@ -0,0 +1,14 @@ +execute('UPDATE msz_messages SET msg_title = TO_BASE64(msg_title), msg_body = TO_BASE64(msg_body)'); + $conn->execute(' + ALTER TABLE `msz_messages` + CHANGE COLUMN `msg_title` `msg_title` TINYBLOB NOT NULL AFTER `msg_reply_to`, + CHANGE COLUMN `msg_body` `msg_body` BLOB NOT NULL AFTER `msg_title`; + '); + } +} diff --git a/src/Messages/MessagesDatabase.php b/src/Messages/MessagesDatabase.php index cdf8646..78d4c14 100644 --- a/src/Messages/MessagesDatabase.php +++ b/src/Messages/MessagesDatabase.php @@ -104,7 +104,7 @@ class MessagesDatabase { $hasPagination = $pagination !== null; $args = 0; - $query = 'SELECT msg_id, msg_owner_id, msg_author_id, msg_recipient_id, msg_reply_to, msg_title, msg_body, msg_parser, UNIX_TIMESTAMP(msg_created), UNIX_TIMESTAMP(msg_sent), UNIX_TIMESTAMP(msg_read), UNIX_TIMESTAMP(msg_deleted) FROM msz_messages'; + $query = 'SELECT msg_id, msg_owner_id, msg_author_id, msg_recipient_id, msg_reply_to, FROM_BASE64(msg_title), FROM_BASE64(msg_body), msg_parser, UNIX_TIMESTAMP(msg_created), UNIX_TIMESTAMP(msg_sent), UNIX_TIMESTAMP(msg_read), UNIX_TIMESTAMP(msg_deleted) FROM msz_messages'; if($hasOwnerInfo) { ++$args; $query .= ' WHERE msg_owner_id = ?'; @@ -162,7 +162,7 @@ class MessagesDatabase { bool $useReplyTo = false ): MessageInfo { $stmt = $this->cache->get(sprintf( - 'SELECT msg_id, msg_owner_id, msg_author_id, msg_recipient_id, msg_reply_to, msg_title, msg_body, msg_parser, UNIX_TIMESTAMP(msg_created), UNIX_TIMESTAMP(msg_sent), UNIX_TIMESTAMP(msg_read), UNIX_TIMESTAMP(msg_deleted) FROM msz_messages WHERE msg_id = %s AND msg_owner_id = ?', + 'SELECT msg_id, msg_owner_id, msg_author_id, msg_recipient_id, msg_reply_to, FROM_BASE64(msg_title), FROM_BASE64(msg_body), msg_parser, UNIX_TIMESTAMP(msg_created), UNIX_TIMESTAMP(msg_sent), UNIX_TIMESTAMP(msg_read), UNIX_TIMESTAMP(msg_deleted) FROM msz_messages WHERE msg_id = %s AND msg_owner_id = ?', !$useReplyTo || $messageInfoOrId instanceof MessageInfo ? '?' : '(SELECT msg_reply_to FROM msz_messages WHERE msg_id = ?)' )); @@ -192,7 +192,7 @@ class MessagesDatabase { DateTime|int|null $sentAt = null, DateTime|int|null $readAt = null ): MessageInfo { - $stmt = $this->cache->get('INSERT INTO msz_messages (msg_id, msg_owner_id, msg_author_id, msg_recipient_id, msg_reply_to, msg_title, msg_body, msg_parser, msg_sent, msg_read) VALUES (?, ?, ?, ?, ?, ?, ?, ?, FROM_UNIXTIME(?), FROM_UNIXTIME(?))'); + $stmt = $this->cache->get('INSERT INTO msz_messages (msg_id, msg_owner_id, msg_author_id, msg_recipient_id, msg_reply_to, msg_title, msg_body, msg_parser, msg_sent, msg_read) VALUES (?, ?, ?, ?, ?, TO_BASE64(?), TO_BASE64(?), ?, FROM_UNIXTIME(?), FROM_UNIXTIME(?))'); $stmt->addParameter(1, $messageId); $stmt->addParameter(2, $ownerInfo instanceof UserInfo ? $ownerInfo->getId() : $ownerInfo); $stmt->addParameter(3, $authorInfo instanceof UserInfo ? $authorInfo->getId() : $authorInfo); @@ -233,12 +233,12 @@ class MessagesDatabase { } if($title !== null) { - $setQuery[] = 'msg_title = ?'; + $setQuery[] = 'msg_title = TO_BASE64(?)'; $setValues[] = $title; } if($body !== null) { - $setQuery[] = 'msg_body = ?'; + $setQuery[] = 'msg_body = TO_BASE64(?)'; $setValues[] = $body; }