Tidy up insertCallbackQueryRequest method.

parent f5da3658
...@@ -607,22 +607,18 @@ class DB ...@@ -607,22 +607,18 @@ class DB
} }
try { try {
$mysql_query = 'INSERT IGNORE INTO `' . TB_CALLBACK_QUERY . '` $sth = self::$pdo->prepare(
( 'INSERT IGNORE INTO `' . TB_CALLBACK_QUERY . '`
`id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `data`, `created_at` (`id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `data`, `created_at`)
) VALUES
VALUES ( (:callback_query_id, :user_id, :chat_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);
$date = self::getTimestamp(time());
$date = self::getTimestamp();
$callback_query_id = $callback_query->getId(); $callback_query_id = $callback_query->getId();
$from = $callback_query->getFrom(); $from = $callback_query->getFrom();
$user_id = null; $user_id = null;
if (is_object($from)) { if ($from instanceof User) {
$user_id = $from->getId(); $user_id = $from->getId();
self::insertUser($from, $date); self::insertUser($from, $date);
} }
...@@ -630,15 +626,19 @@ class DB ...@@ -630,15 +626,19 @@ class DB
$message = $callback_query->getMessage(); $message = $callback_query->getMessage();
$chat_id = null; $chat_id = null;
$message_id = null; $message_id = null;
if ($message) { if ($message instanceof Message) {
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId(); $message_id = $message->getMessageId();
$sth = self::$pdo->prepare('SELECT * FROM `' . TB_MESSAGE . '` $is_message = self::$pdo->query('
WHERE `id` = ' . $message_id . ' AND `chat_id` = ' . $chat_id . ' LIMIT 1'); SELECT *
$sth->execute(); FROM `' . TB_MESSAGE . '`
WHERE `id` = ' . $message_id . '
AND `chat_id` = ' . $chat_id . '
LIMIT 1
')->rowCount();
if ($sth->rowCount() > 0) { if ($is_message) {
self::insertEditedMessageRequest($message); self::insertEditedMessageRequest($message);
} else { } else {
self::insertMessageRequest($message); self::insertMessageRequest($message);
...@@ -648,15 +648,15 @@ class DB ...@@ -648,15 +648,15 @@ class DB
$inline_message_id = $callback_query->getInlineMessageId(); $inline_message_id = $callback_query->getInlineMessageId();
$data = $callback_query->getData(); $data = $callback_query->getData();
$sth_insert_callback_query->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT); $sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':user_id', $user_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR); $sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth_insert_callback_query->bindParam(':data', $data, PDO::PARAM_STR); $sth->bindParam(':data', $data, PDO::PARAM_STR);
$sth_insert_callback_query->bindParam(':created_at', $date, PDO::PARAM_STR); $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
return $sth_insert_callback_query->execute(); return $sth->execute();
} catch (PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
......
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