From d5223f18e4b4e19cfa366324ede1b9319da436a6 Mon Sep 17 00:00:00 2001 From: Mikhail Solovev Date: Tue, 28 May 2024 01:00:07 +0300 Subject: [PATCH 1/2] FastFix to Critical Error. DB.php didn't work because old deprecated methods --- src/DB.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/DB.php b/src/DB.php index 487ea7ff..9bf2c4c9 100644 --- a/src/DB.php +++ b/src/DB.php @@ -1273,15 +1273,21 @@ public static function insertMessageRequest(Message $message): bool } // Insert the forwarded message user in users table - $forward_date = $message->getForwardDate() ? self::getTimestamp($message->getForwardDate()) : null; + $forward_date = $message->getForwardDate() ? self::getTimestamp($message->getForwardOrigin()->getDate()) : null; - if ($forward_from = $message->getForwardFrom()) { - self::insertUser($forward_from); - $forward_from = $forward_from->getId(); + $forward_origin = $message->getForwardOrigin(); + if($forward_origin instanceof MessageOriginUser){ + self::insertUser($forward_origin->getUser()); + $forward_from = $forward_origin->getUser()->getId(); } - if ($forward_from_chat = $message->getForwardFromChat()) { - self::insertChat($forward_from_chat); - $forward_from_chat = $forward_from_chat->getId(); + if($forward_origin instanceof MessageOriginChat){ + self::insertChat($forward_origin->getChat()); + $forward_from_chat = $forward_origin->getChat()->getId(); + } + if($forward_origin instanceof MessageOriginChannel){ + self::insertChat($forward_origin->getChat()); + $forward_from_chat = $forward_origin->getChat()->getId(); + } $via_bot_id = null; From 73250c24be35541ce4250d921a5bfae395aa2c94 Mon Sep 17 00:00:00 2001 From: Tii Date: Tue, 28 May 2024 08:52:25 +0200 Subject: [PATCH 2/2] Fixed bugs and added missing cases --- src/DB.php | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/DB.php b/src/DB.php index 9bf2c4c9..dd10b870 100644 --- a/src/DB.php +++ b/src/DB.php @@ -21,6 +21,10 @@ use Longman\TelegramBot\Entities\ChosenInlineResult; use Longman\TelegramBot\Entities\InlineQuery; use Longman\TelegramBot\Entities\Message; +use Longman\TelegramBot\Entities\MessageOrigin\MessageOriginChannel; +use Longman\TelegramBot\Entities\MessageOrigin\MessageOriginChat; +use Longman\TelegramBot\Entities\MessageOrigin\MessageOriginHiddenUser; +use Longman\TelegramBot\Entities\MessageOrigin\MessageOriginUser; use Longman\TelegramBot\Entities\MessageReactionCountUpdated; use Longman\TelegramBot\Entities\MessageReactionUpdated; use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery; @@ -1273,21 +1277,31 @@ public static function insertMessageRequest(Message $message): bool } // Insert the forwarded message user in users table - $forward_date = $message->getForwardDate() ? self::getTimestamp($message->getForwardOrigin()->getDate()) : null; - - $forward_origin = $message->getForwardOrigin(); - if($forward_origin instanceof MessageOriginUser){ - self::insertUser($forward_origin->getUser()); - $forward_from = $forward_origin->getUser()->getId(); - } - if($forward_origin instanceof MessageOriginChat){ - self::insertChat($forward_origin->getChat()); - $forward_from_chat = $forward_origin->getChat()->getId(); - } - if($forward_origin instanceof MessageOriginChannel){ - self::insertChat($forward_origin->getChat()); - $forward_from_chat = $forward_origin->getChat()->getId(); - + $forward_from = null; + $forward_from_chat = null; + $forward_from_message_id = null; + $forward_signature = null; + $forward_sender_name = null; + $forward_date = null; + + if ($forward_origin = $message->getForwardOrigin()) { + $forward_date = self::getTimestamp($forward_origin->getDate()); + + if ($forward_origin instanceof MessageOriginUser) { + self::insertUser($forward_origin->getSenderUser()); + $forward_from = $forward_origin->getSenderUser()->getId(); + } elseif ($forward_origin instanceof MessageOriginHiddenUser) { + $forward_sender_name = $forward_origin->getSenderUserName(); + } elseif ($forward_origin instanceof MessageOriginChat) { + self::insertChat($forward_origin->getChat()); + $forward_from_chat = $forward_origin->getChat()->getId(); + $forward_signature = $forward_origin->getAuthorSignature(); + } elseif ($forward_origin instanceof MessageOriginChannel) { + self::insertChat($forward_origin->getChat()); + $forward_from_chat = $forward_origin->getChat()->getId(); + $forward_from_message_id = $forward_origin->getMessageId(); + $forward_signature = $forward_origin->getAuthorSignature(); + } } $via_bot_id = null; @@ -1365,9 +1379,9 @@ public static function insertMessageRequest(Message $message): bool $sth->bindValue(':date', $date); $sth->bindValue(':forward_from', $forward_from); $sth->bindValue(':forward_from_chat', $forward_from_chat); - $sth->bindValue(':forward_from_message_id', $message->getForwardFromMessageId()); - $sth->bindValue(':forward_signature', $message->getForwardSignature()); - $sth->bindValue(':forward_sender_name', $message->getForwardSenderName()); + $sth->bindValue(':forward_from_message_id', $forward_from_message_id); + $sth->bindValue(':forward_signature', $forward_signature); + $sth->bindValue(':forward_sender_name', $forward_sender_name); $sth->bindValue(':forward_date', $forward_date); $sth->bindValue(':is_topic_message', $message->getIsTopicMessage());