Skip to content

Commit 46a6cad

Browse files
committed
Add missing database columns and methods.
1 parent ec49055 commit 46a6cad

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

src/DB.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,15 @@ public static function insertChat(Chat $chat, $date = null, $migrate_to_chat_id
439439
try {
440440
$sth = self::$pdo->prepare('
441441
INSERT IGNORE INTO `' . TB_CHAT . '`
442-
(`id`, `type`, `title`, `username`, `all_members_are_administrators`, `created_at` ,`updated_at`, `old_id`)
442+
(`id`, `type`, `title`, `username`, `first_name`, `last_name`, `all_members_are_administrators`, `created_at` ,`updated_at`, `old_id`)
443443
VALUES
444-
(:id, :type, :title, :username, :all_members_are_administrators, :created_at, :updated_at, :old_id)
444+
(:id, :type, :title, :username, :first_name, :last_name, :all_members_are_administrators, :created_at, :updated_at, :old_id)
445445
ON DUPLICATE KEY UPDATE
446446
`type` = VALUES(`type`),
447447
`title` = VALUES(`title`),
448448
`username` = VALUES(`username`),
449+
`first_name` = VALUES(`first_name`),
450+
`last_name` = VALUES(`last_name`),
449451
`all_members_are_administrators` = VALUES(`all_members_are_administrators`),
450452
`updated_at` = VALUES(`updated_at`)
451453
');
@@ -466,6 +468,8 @@ public static function insertChat(Chat $chat, $date = null, $migrate_to_chat_id
466468
$sth->bindValue(':type', $chat_type);
467469
$sth->bindValue(':title', $chat->getTitle());
468470
$sth->bindValue(':username', $chat->getUsername());
471+
$sth->bindValue(':first_name', $chat->getFirstName());
472+
$sth->bindValue(':last_name', $chat->getLastName());
469473
$sth->bindValue(':all_members_are_administrators', $chat->getAllMembersAreAdministrators(), PDO::PARAM_INT);
470474
$date = $date ?: self::getTimestamp();
471475
$sth->bindValue(':created_at', $date);
@@ -709,9 +713,9 @@ public static function insertCallbackQueryRequest(CallbackQuery $callback_query)
709713
try {
710714
$sth = self::$pdo->prepare('
711715
INSERT IGNORE INTO `' . TB_CALLBACK_QUERY . '`
712-
(`id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `data`, `created_at`)
716+
(`id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `chat_instance`, `data`, `game_short_name`, `created_at`)
713717
VALUES
714-
(:id, :user_id, :chat_id, :message_id, :inline_message_id, :data, :created_at)
718+
(:id, :user_id, :chat_id, :message_id, :inline_message_id, :chat_instance, :data, :game_short_name, :created_at)
715719
');
716720

717721
$date = self::getTimestamp();
@@ -750,7 +754,9 @@ public static function insertCallbackQueryRequest(CallbackQuery $callback_query)
750754
$sth->bindValue(':chat_id', $chat_id);
751755
$sth->bindValue(':message_id', $message_id);
752756
$sth->bindValue(':inline_message_id', $callback_query->getInlineMessageId());
757+
$sth->bindValue(':chat_instance', $callback_query->getChatInstance());
753758
$sth->bindValue(':data', $callback_query->getData());
759+
$sth->bindValue(':game_short_name', $callback_query->getGameShortName());
754760
$sth->bindValue(':created_at', $date);
755761

756762
return $sth->execute();
@@ -828,20 +834,20 @@ public static function insertMessageRequest(Message $message)
828834
INSERT IGNORE INTO `' . TB_MESSAGE . '`
829835
(
830836
`id`, `user_id`, `chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
831-
`forward_date`, `reply_to_chat`, `reply_to_message`, `media_group_id`, `text`, `entities`, `audio`, `document`,
837+
`forward_signature`, `forward_date`, `reply_to_chat`, `reply_to_message`, `edit_date`, `media_group_id`, `author_signature`, `text`, `entities`, `caption_entities`, `audio`, `document`,
832838
`animation`, `game`, `photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
833839
`location`, `venue`, `new_chat_members`, `left_chat_member`,
834840
`new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
835841
`supergroup_chat_created`, `channel_chat_created`,
836-
`migrate_from_chat_id`, `migrate_to_chat_id`, `pinned_message`, `connected_website`
842+
`migrate_from_chat_id`, `migrate_to_chat_id`, `pinned_message`, `invoice`, `successful_payment`, `connected_website`
837843
) VALUES (
838844
:message_id, :user_id, :chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
839-
:forward_date, :reply_to_chat, :reply_to_message, :media_group_id, :text, :entities, :audio, :document,
845+
:forward_signature, :forward_date, :reply_to_chat, :reply_to_message, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities, :audio, :document,
840846
:animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
841847
:location, :venue, :new_chat_members, :left_chat_member,
842848
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
843849
:supergroup_chat_created, :channel_chat_created,
844-
:migrate_from_chat_id, :migrate_to_chat_id, :pinned_message, :connected_website
850+
:migrate_from_chat_id, :migrate_to_chat_id, :pinned_message, :invoice, :successful_payment, :connected_website
845851
)
846852
');
847853

@@ -867,6 +873,7 @@ public static function insertMessageRequest(Message $message)
867873
$sth->bindValue(':forward_from', $forward_from);
868874
$sth->bindValue(':forward_from_chat', $forward_from_chat);
869875
$sth->bindValue(':forward_from_message_id', $message->getForwardFromMessageId());
876+
$sth->bindValue(':forward_signature', $message->getForwardSignature());
870877
$sth->bindValue(':forward_date', $forward_date);
871878

872879
$reply_to_chat_id = null;
@@ -876,14 +883,17 @@ public static function insertMessageRequest(Message $message)
876883
$sth->bindValue(':reply_to_chat', $reply_to_chat_id);
877884
$sth->bindValue(':reply_to_message', $reply_to_message_id);
878885

886+
$sth->bindValue(':edit_date', $message->getEditDate());
879887
$sth->bindValue(':media_group_id', $message->getMediaGroupId());
888+
$sth->bindValue(':author_signature', $message->getAuthorSignature());
880889
$sth->bindValue(':text', $message->getText());
881-
$sth->bindValue(':entities', $t = self::entitiesArrayToJson($message->getEntities(), null));
890+
$sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities(), null));
891+
$sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities(), null));
882892
$sth->bindValue(':audio', $message->getAudio());
883893
$sth->bindValue(':document', $message->getDocument());
884894
$sth->bindValue(':animation', $message->getAnimation());
885895
$sth->bindValue(':game', $message->getGame());
886-
$sth->bindValue(':photo', $t = self::entitiesArrayToJson($message->getPhoto(), null));
896+
$sth->bindValue(':photo', self::entitiesArrayToJson($message->getPhoto(), null));
887897
$sth->bindValue(':sticker', $message->getSticker());
888898
$sth->bindValue(':video', $message->getVideo());
889899
$sth->bindValue(':voice', $message->getVoice());
@@ -895,14 +905,16 @@ public static function insertMessageRequest(Message $message)
895905
$sth->bindValue(':new_chat_members', $new_chat_members_ids);
896906
$sth->bindValue(':left_chat_member', $left_chat_member_id);
897907
$sth->bindValue(':new_chat_title', $message->getNewChatTitle());
898-
$sth->bindValue(':new_chat_photo', $t = self::entitiesArrayToJson($message->getNewChatPhoto(), null));
908+
$sth->bindValue(':new_chat_photo', self::entitiesArrayToJson($message->getNewChatPhoto(), null));
899909
$sth->bindValue(':delete_chat_photo', $message->getDeleteChatPhoto());
900910
$sth->bindValue(':group_chat_created', $message->getGroupChatCreated());
901911
$sth->bindValue(':supergroup_chat_created', $message->getSupergroupChatCreated());
902912
$sth->bindValue(':channel_chat_created', $message->getChannelChatCreated());
903913
$sth->bindValue(':migrate_from_chat_id', $message->getMigrateFromChatId());
904914
$sth->bindValue(':migrate_to_chat_id', $message->getMigrateToChatId());
905915
$sth->bindValue(':pinned_message', $message->getPinnedMessage());
916+
$sth->bindValue(':invoice', $message->getInvoice());
917+
$sth->bindValue(':successful_payment', $message->getSuccessfulPayment());
906918
$sth->bindValue(':connected_website', $message->getConnectedWebsite());
907919

908920
return $sth->execute();

src/Entities/CallbackQuery.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @method User getFrom() Sender
2222
* @method Message getMessage() Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old
2323
* @method string getInlineMessageId() Optional. Identifier of the message sent via the bot in inline mode, that originated the query
24+
* @method string getChatInstance() Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
2425
* @method string getData() Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field
2526
* @method string getGameShortName() Optional. Short name of a Game to be returned, serves as the unique identifier for the game
2627
*/

structure.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ CREATE TABLE IF NOT EXISTS `chat` (
1717
`type` ENUM('private', 'group', 'supergroup', 'channel') NOT NULL COMMENT 'Chat type, either private, group, supergroup or channel',
1818
`title` CHAR(255) DEFAULT '' COMMENT 'Chat (group) title, is null if chat type is private',
1919
`username` CHAR(255) DEFAULT NULL COMMENT 'Username, for private chats, supergroups and channels if available',
20+
`first_name` CHAR(255) DEFAULT NULL COMMENT 'First name of the other party in a private chat',
21+
`last_name` CHAR(255) DEFAULT NULL COMMENT 'Last name of the other party in a private chat',
2022
`all_members_are_administrators` tinyint(1) DEFAULT 0 COMMENT 'True if a all members of this group are admins',
2123
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
2224
`updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',
@@ -73,12 +75,16 @@ CREATE TABLE IF NOT EXISTS `message` (
7375
`forward_from` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, sender of the original message',
7476
`forward_from_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier, chat the original message belongs to',
7577
`forward_from_message_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier of the original message in the channel',
78+
`forward_signature` TEXT COMMENT 'For messages forwarded from channels, signature of the post author if present',
7679
`forward_date` timestamp NULL DEFAULT NULL COMMENT 'date the original message was sent in timestamp format',
7780
`reply_to_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
7881
`reply_to_message` bigint UNSIGNED DEFAULT NULL COMMENT 'Message that this message is reply to',
82+
`edit_date` bigint UNSIGNED DEFAULT NULL COMMENT 'Optional. Date the message was last edited in Unix time',
7983
`media_group_id` TEXT COMMENT 'The unique identifier of a media message group this message belongs to',
84+
`author_signature` TEXT COMMENT 'Signature of the post author for messages in channels',
8085
`text` TEXT COMMENT 'For text messages, the actual UTF-8 text of the message max message length 4096 char utf8mb4',
8186
`entities` TEXT COMMENT 'For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text',
87+
`caption_entities` TEXT COMMENT 'For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption',
8288
`audio` TEXT COMMENT 'Audio object. Message is an audio file, information about the file',
8389
`document` TEXT COMMENT 'Document object. Message is a general file, information about the file',
8490
`animation` TEXT COMMENT 'Optional. Message is an animation, information about the animation',
@@ -103,6 +109,8 @@ CREATE TABLE IF NOT EXISTS `message` (
103109
`migrate_to_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate to chat identifier. The group has been migrated to a supergroup with the specified identifier',
104110
`migrate_from_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate from chat identifier. The supergroup has been migrated from a group with the specified identifier',
105111
`pinned_message` TEXT NULL COMMENT 'Message object. Specified message was pinned',
112+
`invoice` TEXT NULL COMMENT 'Message is an invoice for a payment, information about the invoice',
113+
`successful_payment` TEXT NULL COMMENT 'Message is a service message about a successful payment, information about the payment',
106114
`connected_website` TEXT NULL COMMENT 'The domain name of the website on which the user has logged in.',
107115

108116
PRIMARY KEY (`chat_id`, `id`),
@@ -130,7 +138,9 @@ CREATE TABLE IF NOT EXISTS `callback_query` (
130138
`chat_id` bigint NULL COMMENT 'Unique chat identifier',
131139
`message_id` bigint UNSIGNED COMMENT 'Unique message identifier',
132140
`inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the message sent via the bot in inline mode, that originated the query',
141+
`chat_instance` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent',
133142
`data` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Data associated with the callback button',
143+
`game_short_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Short name of a Game to be returned, serves as the unique identifier for the game',
134144
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
135145

136146
PRIMARY KEY (`id`),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1+
ALTER TABLE `chat` ADD COLUMN `first_name` CHAR(255) DEFAULT NULL COMMENT 'First name of the other party in a private chat' AFTER `username`;
2+
ALTER TABLE `chat` ADD COLUMN `last_name` CHAR(255) DEFAULT NULL COMMENT 'Last name of the other party in a private chat' AFTER `first_name`;
13
ALTER TABLE `message` ADD COLUMN `animation` TEXT NULL COMMENT 'Optional. Message is an animation, information about the animation' AFTER `document`;
4+
ALTER TABLE `message` ADD COLUMN `forward_signature` TEXT COMMENT 'For messages forwarded from channels, signature of the post author if present' AFTER `forward_from_message_id`;
5+
ALTER TABLE `message` ADD COLUMN `edit_date` bigint UNSIGNED DEFAULT NULL COMMENT 'Optional. Date the message was last edited in Unix time' AFTER `reply_to_message`;
6+
ALTER TABLE `message` ADD COLUMN `author_signature` TEXT COMMENT 'Signature of the post author for messages in channels' AFTER `media_group_id`;
7+
ALTER TABLE `message` ADD COLUMN `caption_entities` TEXT COMMENT 'For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption';
8+
ALTER TABLE `message` ADD COLUMN `invoice` TEXT NULL COMMENT 'Message is an invoice for a payment, information about the invoice' AFTER `pinned_message`;
9+
ALTER TABLE `message` ADD COLUMN `successful_payment` TEXT NULL COMMENT 'Message is a service message about a successful payment, information about the payment' AFTER `invoice`;
10+
ALTER TABLE `callback_query` ADD COLUMN `chat_instance` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent' AFTER `inline_message_id`;
11+
ALTER TABLE `callback_query` ADD COLUMN `game_short_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Short name of a Game to be returned, serves as the unique identifier for the game' AFTER `data`;

0 commit comments

Comments
 (0)