Commit 1e887c8f authored by no-nevis's avatar no-nevis Committed by GitHub

Fix #513 - Properly saving Chat IDs

parent e522050a
...@@ -327,9 +327,9 @@ class DB ...@@ -327,9 +327,9 @@ class DB
(:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :edited_message_id) (:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :edited_message_id)
'); ');
$sth->bindParam(':id', $id, PDO::PARAM_INT); $sth->bindParam(':id', $id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT); $sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
$sth->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, PDO::PARAM_INT); $sth->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, PDO::PARAM_INT);
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT); $sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT);
...@@ -367,19 +367,20 @@ class DB ...@@ -367,19 +367,20 @@ class DB
INSERT INTO `' . TB_USER . '` INSERT INTO `' . TB_USER . '`
(`id`, `username`, `first_name`, `last_name`, `created_at`, `updated_at`) (`id`, `username`, `first_name`, `last_name`, `created_at`, `updated_at`)
VALUES VALUES
(:id, :username, :first_name, :last_name, :date, :date) (:id, :username, :first_name, :last_name, :created_at, :updated_at)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
`username` = :username, `username` = VALUES(`username`),
`first_name` = :first_name, `first_name` = VALUES(`first_name`),
`last_name` = :last_name, `last_name` = VALUES(`last_name`),
`updated_at` = :date `updated_at` = VALUES(`updated_at`)
'); ');
$sth->bindParam(':id', $user_id, PDO::PARAM_INT); $sth->bindParam(':id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':username', $username, PDO::PARAM_STR, 255); $sth->bindParam(':username', $username, PDO::PARAM_STR, 255);
$sth->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255); $sth->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255);
$sth->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255); $sth->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255);
$sth->bindParam(':date', $date, PDO::PARAM_STR); $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
$sth->bindParam(':updated_at', $date, PDO::PARAM_STR);
$status = $sth->execute(); $status = $sth->execute();
} catch (PDOException $e) { } catch (PDOException $e) {
...@@ -397,8 +398,8 @@ class DB ...@@ -397,8 +398,8 @@ class DB
(:user_id, :chat_id) (:user_id, :chat_id)
'); ');
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$status = $sth->execute(); $status = $sth->execute();
} catch (PDOException $e) { } catch (PDOException $e) {
...@@ -436,30 +437,31 @@ class DB ...@@ -436,30 +437,31 @@ class DB
INSERT IGNORE INTO `' . TB_CHAT . '` INSERT IGNORE INTO `' . TB_CHAT . '`
(`id`, `type`, `title`, `username`, `all_members_are_administrators`, `created_at` ,`updated_at`, `old_id`) (`id`, `type`, `title`, `username`, `all_members_are_administrators`, `created_at` ,`updated_at`, `old_id`)
VALUES VALUES
(:id, :type, :title, :username, :all_members_are_administrators, :date, :date, :oldid) (:id, :type, :title, :username, :all_members_are_administrators, :created_at, :updated_at, :oldid)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
`type` = :type, `type` = VALUES(`type`),
`title` = :title, `title` = VALUES(`title`),
`username` = :username, `username` = VALUES(`username`),
`all_members_are_administrators` = :all_members_are_administrators, `all_members_are_administrators` = VALUES(`all_members_are_administrators`),
`updated_at` = :date `updated_at` = VALUES(`updated_at`)
'); ');
if ($migrate_to_chat_id) { if ($migrate_to_chat_id) {
$chat_type = 'supergroup'; $chat_type = 'supergroup';
$sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_INT); $sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_STR);
$sth->bindParam(':oldid', $chat_id, PDO::PARAM_INT); $sth->bindParam(':oldid', $chat_id, PDO::PARAM_STR);
} else { } else {
$sth->bindParam(':id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_INT); $sth->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_STR);
} }
$sth->bindParam(':type', $chat_type, PDO::PARAM_INT); $sth->bindParam(':type', $chat_type, PDO::PARAM_INT);
$sth->bindParam(':title', $chat_title, PDO::PARAM_STR, 255); $sth->bindParam(':title', $chat_title, PDO::PARAM_STR, 255);
$sth->bindParam(':username', $chat_username, PDO::PARAM_STR, 255); $sth->bindParam(':username', $chat_username, PDO::PARAM_STR, 255);
$sth->bindParam(':all_members_are_administrators', $chat_all_members_are_administrators, PDO::PARAM_INT); $sth->bindParam(':all_members_are_administrators', $chat_all_members_are_administrators, PDO::PARAM_INT);
$sth->bindParam(':date', $date, PDO::PARAM_STR); $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
$sth->bindParam(':updated_at', $date, PDO::PARAM_STR);
return $sth->execute(); return $sth->execute();
} catch (PDOException $e) { } catch (PDOException $e) {
...@@ -615,7 +617,7 @@ class DB ...@@ -615,7 +617,7 @@ class DB
$offset = $inline_query->getOffset(); $offset = $inline_query->getOffset();
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT); $sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR); $sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':query', $query, PDO::PARAM_STR); $sth->bindParam(':query', $query, PDO::PARAM_STR);
$sth->bindParam(':param_offset', $offset, PDO::PARAM_STR); $sth->bindParam(':param_offset', $offset, PDO::PARAM_STR);
...@@ -663,7 +665,7 @@ class DB ...@@ -663,7 +665,7 @@ class DB
$query = $chosen_inline_result->getQuery(); $query = $chosen_inline_result->getQuery();
$sth->bindParam(':result_id', $result_id, PDO::PARAM_STR); $sth->bindParam(':result_id', $result_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR); $sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR); $sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth->bindParam(':query', $query, PDO::PARAM_STR); $sth->bindParam(':query', $query, PDO::PARAM_STR);
...@@ -732,9 +734,9 @@ class DB ...@@ -732,9 +734,9 @@ class DB
$data = $callback_query->getData(); $data = $callback_query->getData();
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT); $sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR); $sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth->bindParam(':data', $data, PDO::PARAM_STR); $sth->bindParam(':data', $data, PDO::PARAM_STR);
$sth->bindParam(':created_at', $date, PDO::PARAM_STR); $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
...@@ -866,9 +868,9 @@ class DB ...@@ -866,9 +868,9 @@ class DB
$migrate_to_chat_id = $message->getMigrateToChatId(); $migrate_to_chat_id = $message->getMigrateToChatId();
$pinned_message = $message->getPinnedMessage(); $pinned_message = $message->getPinnedMessage();
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $from_id, PDO::PARAM_STR);
$sth->bindParam(':date', $date, PDO::PARAM_STR); $sth->bindParam(':date', $date, PDO::PARAM_STR);
$sth->bindParam(':forward_from', $forward_from, PDO::PARAM_INT); $sth->bindParam(':forward_from', $forward_from, PDO::PARAM_INT);
$sth->bindParam(':forward_from_chat', $forward_from_chat, PDO::PARAM_INT); $sth->bindParam(':forward_from_chat', $forward_from_chat, PDO::PARAM_INT);
...@@ -948,7 +950,7 @@ class DB ...@@ -948,7 +950,7 @@ class DB
INSERT IGNORE INTO `' . TB_EDITED_MESSAGE . '` INSERT IGNORE INTO `' . TB_EDITED_MESSAGE . '`
(`chat_id`, `message_id`, `user_id`, `edit_date`, `text`, `entities`, `caption`) (`chat_id`, `message_id`, `user_id`, `edit_date`, `text`, `entities`, `caption`)
VALUES VALUES
(:chat_id, :message_id, :user_id, :date, :text, :entities, :caption) (:chat_id, :message_id, :user_id, :edit_date, :text, :entities, :caption)
'); ');
$message_id = $edited_message->getMessageId(); $message_id = $edited_message->getMessageId();
...@@ -962,10 +964,10 @@ class DB ...@@ -962,10 +964,10 @@ class DB
$text = $edited_message->getText(); $text = $edited_message->getText();
$caption = $edited_message->getCaption(); $caption = $edited_message->getCaption();
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $from_id, PDO::PARAM_STR);
$sth->bindParam(':date', $edit_date, PDO::PARAM_STR); $sth->bindParam(':edit_date', $edit_date, PDO::PARAM_STR);
$sth->bindParam(':text', $text, PDO::PARAM_STR); $sth->bindParam(':text', $text, PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, PDO::PARAM_STR); $sth->bindParam(':entities', $entities, PDO::PARAM_STR);
$sth->bindParam(':caption', $caption, PDO::PARAM_STR); $sth->bindParam(':caption', $caption, PDO::PARAM_STR);
...@@ -1100,18 +1102,20 @@ class DB ...@@ -1100,18 +1102,20 @@ class DB
try { try {
$sth = self::$pdo->prepare('SELECT $sth = self::$pdo->prepare('SELECT
(SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :date) as LIMIT_PER_SEC_ALL, (SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :created_at_1) as LIMIT_PER_SEC_ALL,
(SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE ((`chat_id` = :chat_id AND `inline_message_id` IS NULL) OR (`inline_message_id` = :inline_message_id AND `chat_id` IS NULL)) AND `created_at` >= :date) as LIMIT_PER_SEC, (SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :created_at_2 AND ((`chat_id` = :chat_id_1 AND `inline_message_id` IS NULL) OR (`inline_message_id` = :inline_message_id AND `chat_id` IS NULL))) as LIMIT_PER_SEC,
(SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `chat_id` = :chat_id AND `created_at` >= :date_minute) as LIMIT_PER_MINUTE (SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :created_at_minute AND `chat_id` = :chat_id_2) as LIMIT_PER_MINUTE
'); ');
$date = self::getTimestamp(); $date = self::getTimestamp();
$date_minute = self::getTimestamp(strtotime('-1 minute')); $date_minute = self::getTimestamp(strtotime('-1 minute'));
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_STR); $sth->bindParam(':chat_id_1', $chat_id, \PDO::PARAM_STR);
$sth->bindParam(':chat_id_2', $chat_id, \PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR); $sth->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR);
$sth->bindParam(':date', $date, \PDO::PARAM_STR); $sth->bindParam(':created_at_1', $date, \PDO::PARAM_STR);
$sth->bindParam(':date_minute', $date_minute, \PDO::PARAM_STR); $sth->bindParam(':created_at_2', $date, \PDO::PARAM_STR);
$sth->bindParam(':created_at_minute', $date_minute, \PDO::PARAM_STR);
$sth->execute(); $sth->execute();
...@@ -1145,7 +1149,7 @@ class DB ...@@ -1145,7 +1149,7 @@ class DB
`method`, `chat_id`, `inline_message_id`, `created_at` `method`, `chat_id`, `inline_message_id`, `created_at`
) )
VALUES ( VALUES (
:method, :chat_id, :inline_message_id, :date :method, :chat_id, :inline_message_id, :created_at
); );
'); ');
...@@ -1154,7 +1158,7 @@ class DB ...@@ -1154,7 +1158,7 @@ class DB
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_STR); $sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR); $sth->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR);
$sth->bindParam(':method', $method, \PDO::PARAM_STR); $sth->bindParam(':method', $method, \PDO::PARAM_STR);
$sth->bindParam(':date', $created_at, \PDO::PARAM_STR); $sth->bindParam(':created_at', $created_at, \PDO::PARAM_STR);
return $sth->execute(); return $sth->execute();
} catch (\Exception $e) { } catch (\Exception $e) {
......
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