Commit e2c45622 authored by Jack'lul's avatar Jack'lul

constraint fix

parent 5d17ad12
......@@ -596,10 +596,10 @@ class DB
try {
$mysql_query = 'INSERT IGNORE INTO `' . TB_CALLBACK_QUERY . '`
(
`id`, `user_id`, `message_id`, `inline_message_id`, `data`, `created_at`
`id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `data`, `created_at`
)
VALUES (
:callback_query_id, :user_id, :message_id, :inline_message_id, :data, :created_at
:callback_query_id, :user_id, :chat_id, :message_id, :inline_message_id, :data, :created_at
)';
$sth_insert_callback_query = self::$pdo->prepare($mysql_query);
......@@ -615,8 +615,10 @@ class DB
}
$message = $callback_query->getMessage();
$chat_id = null;
$message_id = null;
if ($message) {
$chat_id = $callback_query->getMessage()->getChat()->getId();
$message_id = $callback_query->getMessage()->getMessageId();
self::insertMessageRequest($message);
}
......@@ -626,6 +628,7 @@ class DB
$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(':chat_id', $chat_id, \PDO::PARAM_INT);
$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(':data', $data, \PDO::PARAM_STR);
......
......@@ -121,6 +121,7 @@ CREATE TABLE IF NOT EXISTS `message` (
CREATE TABLE IF NOT EXISTS `callback_query` (
`id` bigint UNSIGNED COMMENT 'Unique identifier for this query',
`user_id` bigint NULL COMMENT 'Unique user identifier',
`chat_id` bigint NULL COMMENT 'Unique chat 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',
......@@ -128,10 +129,11 @@ CREATE TABLE IF NOT EXISTS `callback_query` (
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `chat_id` (`chat_id`),
KEY `message_id` (`message_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`),
FOREIGN KEY (`user_id`, `message_id`) REFERENCES `message` (`chat_id`, `id`)
FOREIGN KEY (`chat_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` (
......
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