Skip to content

Commit 2acfa37

Browse files
committed
Fix typo and duplicate SQL statements, smaller DB field cleanup, more specific PDO exceptions.
1 parent 6351dc3 commit 2acfa37

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

src/DB.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ public static function insertRequest(Update $update)
549549
$shipping_query_id = $shipping_query->getId();
550550
} elseif (($pre_checkout_query = $update->getPreCheckoutQuery()) && self::insertPreCheckoutQueryRequest($pre_checkout_query)) {
551551
$pre_checkout_query_id = $pre_checkout_query->getId();
552-
} elseif (($poll = $update->getPoll()) && self::insertPoll($poll)) {
552+
} elseif (($poll = $update->getPoll()) && self::insertPollRequest($poll)) {
553553
$poll_id = $poll->getId();
554554
} else {
555555
return false;
@@ -844,7 +844,7 @@ public static function insertPollRequest(Poll $poll)
844844

845845
$sth->bindValue(':id', $poll->getId());
846846
$sth->bindValue(':question', $poll->getQuestion());
847-
$sth->bindValue(':options', self::entitiesArrayToJson($poll->getOptions(), null));
847+
$sth->bindValue(':options', self::entitiesArrayToJson($poll->getOptions()));
848848
$sth->bindValue(':is_closed', $poll->getIsClosed());
849849
$sth->bindValue(':created_at', self::getTimestamp());
850850

@@ -922,20 +922,20 @@ public static function insertMessageRequest(Message $message)
922922
(
923923
`id`, `user_id`, `chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
924924
`forward_signature`, `forward_sender_name`, `forward_date`,
925-
`reply_to_chat`, `reply_to_message`, `media_group_id`, `text`, `entities`, `audio`, `document`,
926-
`animation`, `game`, `photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
925+
`reply_to_chat`, `reply_to_message`, `edit_date`, `media_group_id`, `author_signature`, `text`, `entities`, `caption_entities`,
926+
`audio`, `document`, `animation`, `game`, `photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
927927
`location`, `venue`, `poll`, `new_chat_members`, `left_chat_member`,
928-
`new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
929-
`supergroup_chat_created`, `channel_chat_created`, `migrate_from_chat_id`, `migrate_to_chat_id`,
928+
`new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
929+
`supergroup_chat_created`, `channel_chat_created`, `migrate_to_chat_id`, `migrate_from_chat_id`,
930930
`pinned_message`, `invoice`, `successful_payment`, `connected_website`, `passport_data`
931931
) VALUES (
932932
:message_id, :user_id, :chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
933933
:forward_signature, :forward_sender_name, :forward_date,
934-
:reply_to_chat, :reply_to_message, :media_group_id, :text, :entities, :audio, :document,
935-
:animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
934+
:reply_to_chat, :reply_to_message, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities,
935+
:audio, :document, :animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
936936
:location, :venue, :poll, :new_chat_members, :left_chat_member,
937937
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
938-
:supergroup_chat_created, :channel_chat_created, :migrate_from_chat_id, :migrate_to_chat_id,
938+
:supergroup_chat_created, :channel_chat_created, :migrate_to_chat_id, :migrate_from_chat_id,
939939
:pinned_message, :invoice, :successful_payment, :connected_website, :passport_data
940940
)
941941
');
@@ -977,13 +977,13 @@ public static function insertMessageRequest(Message $message)
977977
$sth->bindValue(':media_group_id', $message->getMediaGroupId());
978978
$sth->bindValue(':author_signature', $message->getAuthorSignature());
979979
$sth->bindValue(':text', $message->getText());
980-
$sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities(), null));
981-
$sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities(), null));
980+
$sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities()));
981+
$sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities()));
982982
$sth->bindValue(':audio', $message->getAudio());
983983
$sth->bindValue(':document', $message->getDocument());
984984
$sth->bindValue(':animation', $message->getAnimation());
985985
$sth->bindValue(':game', $message->getGame());
986-
$sth->bindValue(':photo', self::entitiesArrayToJson($message->getPhoto(), null));
986+
$sth->bindValue(':photo', self::entitiesArrayToJson($message->getPhoto()));
987987
$sth->bindValue(':sticker', $message->getSticker());
988988
$sth->bindValue(':video', $message->getVideo());
989989
$sth->bindValue(':voice', $message->getVoice());
@@ -996,13 +996,13 @@ public static function insertMessageRequest(Message $message)
996996
$sth->bindValue(':new_chat_members', $new_chat_members_ids);
997997
$sth->bindValue(':left_chat_member', $left_chat_member_id);
998998
$sth->bindValue(':new_chat_title', $message->getNewChatTitle());
999-
$sth->bindValue(':new_chat_photo', self::entitiesArrayToJson($message->getNewChatPhoto(), null));
999+
$sth->bindValue(':new_chat_photo', self::entitiesArrayToJson($message->getNewChatPhoto()));
10001000
$sth->bindValue(':delete_chat_photo', $message->getDeleteChatPhoto());
10011001
$sth->bindValue(':group_chat_created', $message->getGroupChatCreated());
10021002
$sth->bindValue(':supergroup_chat_created', $message->getSupergroupChatCreated());
10031003
$sth->bindValue(':channel_chat_created', $message->getChannelChatCreated());
1004-
$sth->bindValue(':migrate_from_chat_id', $message->getMigrateFromChatId());
10051004
$sth->bindValue(':migrate_to_chat_id', $message->getMigrateToChatId());
1005+
$sth->bindValue(':migrate_from_chat_id', $message->getMigrateFromChatId());
10061006
$sth->bindValue(':pinned_message', $message->getPinnedMessage());
10071007
$sth->bindValue(':invoice', $message->getInvoice());
10081008
$sth->bindValue(':successful_payment', $message->getSuccessfulPayment());
@@ -1059,7 +1059,7 @@ public static function insertEditedMessageRequest(Message $edited_message)
10591059
$sth->bindValue(':user_id', $user_id);
10601060
$sth->bindValue(':edit_date', $edit_date);
10611061
$sth->bindValue(':text', $edited_message->getText());
1062-
$sth->bindValue(':entities', self::entitiesArrayToJson($edited_message->getEntities(), null));
1062+
$sth->bindValue(':entities', self::entitiesArrayToJson($edited_message->getEntities()));
10631063
$sth->bindValue(':caption', $edited_message->getCaption());
10641064

10651065
return $sth->execute();
@@ -1216,7 +1216,7 @@ public static function getTelegramRequestCount($chat_id = null, $inline_message_
12161216
$sth->execute();
12171217

12181218
return $sth->fetch();
1219-
} catch (Exception $e) {
1219+
} catch (PDOException $e) {
12201220
throw new TelegramException($e->getMessage());
12211221
}
12221222
}
@@ -1252,7 +1252,7 @@ public static function insertTelegramRequest($method, $data)
12521252
$sth->bindValue(':created_at', self::getTimestamp());
12531253

12541254
return $sth->execute();
1255-
} catch (Exception $e) {
1255+
} catch (PDOException $e) {
12561256
throw new TelegramException($e->getMessage());
12571257
}
12581258
}
@@ -1295,7 +1295,7 @@ public static function update($table, array $fields_values, array $where_fields_
12951295
$sql .= count($where) > 0 ? ' WHERE ' . implode(' AND ', $where) : '';
12961296

12971297
return self::$pdo->prepare($sql)->execute($tokens);
1298-
} catch (Exception $e) {
1298+
} catch (PDOException $e) {
12991299
throw new TelegramException($e->getMessage());
13001300
}
13011301
}

structure.sql

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` (
6767
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
6868
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
6969

70-
CREATE TABLE IF NOT EXISTS `poll` (
71-
`id` bigint UNSIGNED COMMENT 'Unique poll identifier',
72-
`question` char(255) NOT NULL COMMENT 'Poll question',
73-
`options` text NOT NULL COMMENT 'List of poll options',
74-
`is_closed` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll is closed',
75-
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
76-
77-
PRIMARY KEY (`id`)
78-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
79-
8070
CREATE TABLE IF NOT EXISTS `message` (
8171
`chat_id` bigint COMMENT 'Unique chat identifier',
8272
`id` bigint UNSIGNED COMMENT 'Unique message identifier',
@@ -110,7 +100,6 @@ CREATE TABLE IF NOT EXISTS `message` (
110100
`location` TEXT COMMENT 'Location object. Message is a shared location, information about the location',
111101
`venue` TEXT COMMENT 'Venue object. Message is a Venue, information about the Venue',
112102
`poll` TEXT COMMENT 'Poll object. Message is a native poll, information about the poll',
113-
`caption` TEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption',
114103
`new_chat_members` TEXT COMMENT 'List of unique user identifiers, new member(s) were added to the group, information about them (one of these members may be the bot itself)',
115104
`left_chat_member` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, a member was removed from the group, information about them (this member may be the bot itself)',
116105
`new_chat_title` CHAR(255) DEFAULT NULL COMMENT 'A chat title was changed to this value',

0 commit comments

Comments
 (0)