Commit 5d17ad12 authored by Jack'lul's avatar Jack'lul

insert and reference message in database instead of inserting it with each callback query

parent 990485bf
...@@ -569,7 +569,7 @@ class DB ...@@ -569,7 +569,7 @@ class DB
$sth_insert_chosen_inline_result->bindParam(':result_id', $result_id, \PDO::PARAM_STR); $sth_insert_chosen_inline_result->bindParam(':result_id', $result_id, \PDO::PARAM_STR);
$sth_insert_chosen_inline_result->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth_insert_chosen_inline_result->bindParam(':user_id', $user_id, \PDO::PARAM_INT);
$sth_insert_chosen_inline_result->bindParam(':location', $location, \PDO::PARAM_INT); $sth_insert_chosen_inline_result->bindParam(':location', $location, \PDO::PARAM_INT);
$sth_insert_chosen_inline_result->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_INT); $sth_insert_chosen_inline_result->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR);
$sth_insert_chosen_inline_result->bindParam(':query', $query, \PDO::PARAM_STR); $sth_insert_chosen_inline_result->bindParam(':query', $query, \PDO::PARAM_STR);
$sth_insert_chosen_inline_result->bindParam(':created_at', $date, \PDO::PARAM_STR); $sth_insert_chosen_inline_result->bindParam(':created_at', $date, \PDO::PARAM_STR);
...@@ -596,10 +596,10 @@ class DB ...@@ -596,10 +596,10 @@ class DB
try { try {
$mysql_query = 'INSERT IGNORE INTO `' . TB_CALLBACK_QUERY . '` $mysql_query = 'INSERT IGNORE INTO `' . TB_CALLBACK_QUERY . '`
( (
`id`, `user_id`, `message`, `inline_message_id`, `data`, `created_at` `id`, `user_id`, `message_id`, `inline_message_id`, `data`, `created_at`
) )
VALUES ( VALUES (
:callback_query_id, :user_id, :message, :inline_message_id, :data, :created_at :callback_query_id, :user_id, :message_id, :inline_message_id, :data, :created_at
)'; )';
$sth_insert_callback_query = self::$pdo->prepare($mysql_query); $sth_insert_callback_query = self::$pdo->prepare($mysql_query);
...@@ -615,12 +615,18 @@ class DB ...@@ -615,12 +615,18 @@ class DB
} }
$message = $callback_query->getMessage(); $message = $callback_query->getMessage();
$message_id = null;
if ($message) {
$message_id = $callback_query->getMessage()->getMessageId();
self::insertMessageRequest($message);
}
$inline_message_id = $callback_query->getInlineMessageId(); $inline_message_id = $callback_query->getInlineMessageId();
$data = $callback_query->getData(); $data = $callback_query->getData();
$sth_insert_callback_query->bindParam(':callback_query_id', $callback_query_id, \PDO::PARAM_INT); $sth_insert_callback_query->bindParam(':callback_query_id', $callback_query_id, \PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth_insert_callback_query->bindParam(':user_id', $user_id, \PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':message', $message, \PDO::PARAM_STR); $sth_insert_callback_query->bindParam(':message_id', $message_id, \PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR); $sth_insert_callback_query->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR);
$sth_insert_callback_query->bindParam(':data', $data, \PDO::PARAM_STR); $sth_insert_callback_query->bindParam(':data', $data, \PDO::PARAM_STR);
$sth_insert_callback_query->bindParam(':created_at', $date, \PDO::PARAM_STR); $sth_insert_callback_query->bindParam(':created_at', $date, \PDO::PARAM_STR);
...@@ -681,7 +687,7 @@ class DB ...@@ -681,7 +687,7 @@ class DB
self::insertChat($forward_from_chat, $forward_date); self::insertChat($forward_from_chat, $forward_date);
$forward_from_chat = $forward_from_chat->getId(); $forward_from_chat = $forward_from_chat->getId();
} }
//New and left chat member //New and left chat member
if ($new_chat_member) { if ($new_chat_member) {
//Insert the new chat user //Insert the new chat user
......
...@@ -63,20 +63,6 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` ( ...@@ -63,20 +63,6 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` (
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `callback_query` (
`id` bigint UNSIGNED COMMENT 'Unique identifier for this query',
`user_id` bigint NULL COMMENT 'Unique user identifier',
`message` text NULL COMMENT 'Message with the callback button that originated the query',
`inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the message sent via the bot in inline mode, that originated the query',
`data` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Data associated with the callback button',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `message` ( CREATE TABLE IF NOT EXISTS `message` (
`chat_id` bigint COMMENT 'Unique chat identifier', `chat_id` bigint COMMENT 'Unique chat identifier',
`id` bigint UNSIGNED COMMENT 'Unique message identifier', `id` bigint UNSIGNED COMMENT 'Unique message identifier',
...@@ -132,6 +118,22 @@ CREATE TABLE IF NOT EXISTS `message` ( ...@@ -132,6 +118,22 @@ CREATE TABLE IF NOT EXISTS `message` (
FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`) FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `callback_query` (
`id` bigint UNSIGNED COMMENT 'Unique identifier for this query',
`user_id` bigint NULL COMMENT 'Unique user identifier',
`message_id` bigint UNSIGNED COMMENT 'Unique message identifier',
`inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the message sent via the bot in inline mode, that originated the query',
`data` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Data associated with the callback button',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `message_id` (`message_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`),
FOREIGN KEY (`user_id`, `message_id`) REFERENCES `message` (`chat_id`, `id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `edited_message` ( CREATE TABLE IF NOT EXISTS `edited_message` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry', `id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`chat_id` bigint COMMENT 'Unique chat identifier', `chat_id` bigint COMMENT 'Unique chat identifier',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment