Commit c166bb21 authored by MBoretto's avatar MBoretto

fixed integrity violation

parent 1c1801a9
...@@ -239,6 +239,33 @@ class DB ...@@ -239,6 +239,33 @@ class DB
$new_chat_photo = $message->getNewChatPhoto(); $new_chat_photo = $message->getNewChatPhoto();
$left_chat_participant = $message->getLeftChatParticipant(); $left_chat_participant = $message->getLeftChatParticipant();
try {
//chats table
$sth2 = self::$pdo->prepare('INSERT INTO `'.TB_CHATS.'`
(`id`, `type`, `title`, `created_at` ,`updated_at`)
VALUES (:id, :type, :title, :date, :date)
ON DUPLICATE KEY UPDATE `title`=:title, `updated_at`=:date');
$chat_title = $chat->getTitle();
$type = $chat->getType();
$sth2->bindParam(':id', $chat_id, \PDO::PARAM_INT);
$sth2->bindParam(':type', $type, \PDO::PARAM_INT);
$sth2->bindParam(':title', $chat_title, \PDO::PARAM_STR, 255);
$sth2->bindParam(':date', $date, \PDO::PARAM_STR);
$status = $sth2->execute();
} catch (PDOException $e) {
throw new TelegramException($e->getMessage());
}
//insert user and the relation with the chat //insert user and the relation with the chat
self::insertUser($from, $date, $chat); self::insertUser($from, $date, $chat);
...@@ -266,23 +293,8 @@ class DB ...@@ -266,23 +293,8 @@ class DB
$left_chat_participant = ''; $left_chat_participant = '';
} }
try {
//chats table
$sth2 = self::$pdo->prepare('INSERT INTO `'.TB_CHATS.'`
(`id`, `type`, `title`, `created_at` ,`updated_at`)
VALUES (:id, :type, :title, :date, :date)
ON DUPLICATE KEY UPDATE `title`=:title, `updated_at`=:date');
$chat_title = $chat->getTitle();
$type = $chat->getType();
$sth2->bindParam(':id', $chat_id, \PDO::PARAM_INT);
$sth2->bindParam(':type', $type, \PDO::PARAM_INT);
$sth2->bindParam(':title', $chat_title, \PDO::PARAM_STR, 255);
$sth2->bindParam(':date', $date, \PDO::PARAM_STR);
$status = $sth2->execute();
try {
//Messages Table //Messages Table
$sth = self::$pdo->prepare('INSERT IGNORE INTO `'.TB_MESSAGES.'` $sth = self::$pdo->prepare('INSERT IGNORE INTO `'.TB_MESSAGES.'`
( (
......
...@@ -41,7 +41,7 @@ CREATE TABLE `users` ( ...@@ -41,7 +41,7 @@ CREATE TABLE `users` (
CREATE TABLE `chats` ( CREATE TABLE `chats` (
`id` bigint NOT NULL DEFAULT '0' COMMENT 'Unique user or chat identifier', `id` bigint NOT NULL DEFAULT '0' COMMENT 'Unique user or chat identifier',
`type` CHAR(10) DEFAULT '' COMMENT 'chat type private groupe or channel', `type` CHAR(10) DEFAULT '' COMMENT 'chat type private group, supergroup or channel',
`title` CHAR(255) DEFAULT '' COMMENT 'chat title null if case of single chat with the bot', `title` CHAR(255) DEFAULT '' COMMENT 'chat title null if case of single chat with the bot',
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Entry date creation', `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Entry date creation',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Entry date update', `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Entry date update',
......
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