public static function insertChat(Chat $chat, $date, $migrate_to_chat_id = null)
{
if (!self::isDbConnected()) {
return false;
}
$chat_id = $chat->getId();
$chat_title = $chat->getTitle();
$chat_type = $chat->getType();
try {
$sth = self::$pdo->prepare('
INSERT INTO `' . TB_CHAT . '`
(`id`, `type`, `title`, `created_at` ,`updated_at`, `old_id`)
VALUES
(:id, :type, :title, :date, :date, :oldid)
ON DUPLICATE KEY UPDATE
`type` = :type,
`title` = :title,
`updated_at` = :date
');
if ($migrate_to_chat_id) {
$chat_type = 'supergroup';
$sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_INT);
$sth->bindParam(':oldid', $chat_id, PDO::PARAM_INT);
} else {
$sth->bindParam(':id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_INT);
}
$sth->bindParam(':type', $chat_type, PDO::PARAM_INT);
$sth->bindParam(':title', $chat_title, PDO::PARAM_STR, 255);
$sth->bindParam(':date', $date, PDO::PARAM_STR);
return $sth->execute();
} catch (PDOException $e) {
throw new TelegramException($e->getMessage());
}
}