Add is_bot field to user DB table.

parent cc37bb94
...@@ -4,10 +4,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ...@@ -4,10 +4,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
Exclamation symbols (:exclamation:) note something of importance e.g. breaking changes. Click them to learn more. Exclamation symbols (:exclamation:) note something of importance e.g. breaking changes. Click them to learn more.
## [Unreleased] ## [Unreleased]
**Note:** After updating to this version, you will need to execute the [SQL migration script][unreleased-sql-migration] on your database.
### Added ### Added
- New entities, methods, update types and inline keyboard button for Payments (Bot API 3.0). - New entities, methods, update types and inline keyboard button for Payments (Bot API 3.0).
- Add new methods, fields and objects for working with stickers (Bot API 3.2). - Add new methods, fields and objects for working with stickers (Bot API 3.2).
- New fields for Chat, User and Message objects (Bot API 3.3). - New fields for Chat, User and Message objects (Bot API 3.3). `is_bot` added to `user` DB table.
### Changed ### Changed
- [:exclamation:][unreleased-correct-printerror] Corrected `ServerResponse->printError` method to print by default and return by setting `$return` parameter. - [:exclamation:][unreleased-correct-printerror] Corrected `ServerResponse->printError` method to print by default and return by setting `$return` parameter.
- Ensure command names are handled as lower case. - Ensure command names are handled as lower case.
...@@ -150,6 +151,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -150,6 +151,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Deprecated ### Deprecated
- Move `hideKeyboard` to `removeKeyboard`. - Move `hideKeyboard` to `removeKeyboard`.
[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/0.47.1-unreleased.sql
[unreleased-correct-printerror]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#correct-printerror [unreleased-correct-printerror]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#correct-printerror
[0.47.0-private-only-admin-commands]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#private-only-admin-commands [0.47.0-private-only-admin-commands]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#private-only-admin-commands
[0.46.0-bc-request-class-refactor]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#request-class-refactor [0.46.0-bc-request-class-refactor]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#request-class-refactor
......
...@@ -358,6 +358,7 @@ class DB ...@@ -358,6 +358,7 @@ class DB
} }
$user_id = $user->getId(); $user_id = $user->getId();
$is_bot = $user->getIsBot();
$username = $user->getUsername(); $username = $user->getUsername();
$first_name = $user->getFirstName(); $first_name = $user->getFirstName();
$last_name = $user->getLastName(); $last_name = $user->getLastName();
...@@ -366,10 +367,11 @@ class DB ...@@ -366,10 +367,11 @@ class DB
try { try {
$sth = self::$pdo->prepare(' $sth = self::$pdo->prepare('
INSERT INTO `' . TB_USER . '` INSERT INTO `' . TB_USER . '`
(`id`, `username`, `first_name`, `last_name`, `language_code`, `created_at`, `updated_at`) (`id`, `is_bot`, `username`, `first_name`, `last_name`, `language_code`, `created_at`, `updated_at`)
VALUES VALUES
(:id, :username, :first_name, :last_name, :language_code, :created_at, :updated_at) (:id, :is_bot,:username, :first_name, :last_name, :language_code, :created_at, :updated_at)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
`is_bot` = VALUES(`is_bot`),
`username` = VALUES(`username`), `username` = VALUES(`username`),
`first_name` = VALUES(`first_name`), `first_name` = VALUES(`first_name`),
`last_name` = VALUES(`last_name`), `last_name` = VALUES(`last_name`),
...@@ -378,6 +380,7 @@ class DB ...@@ -378,6 +380,7 @@ class DB
'); ');
$sth->bindParam(':id', $user_id, PDO::PARAM_STR); $sth->bindParam(':id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':is_bot', $is_bot, PDO::PARAM_INT);
$sth->bindParam(':username', $username, PDO::PARAM_STR, 255); $sth->bindParam(':username', $username, PDO::PARAM_STR, 255);
$sth->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255); $sth->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255);
$sth->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255); $sth->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255);
......
CREATE TABLE IF NOT EXISTS `user` ( CREATE TABLE IF NOT EXISTS `user` (
`id` bigint COMMENT 'Unique user identifier', `id` bigint COMMENT 'Unique user identifier',
`is_bot` tinyint(1) DEFAULT 0 COMMENT 'True if this user is a bot',
`first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User''s first name', `first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User''s first name',
`last_name` CHAR(255) DEFAULT NULL COMMENT 'User''s last name', `last_name` CHAR(255) DEFAULT NULL COMMENT 'User''s last name',
`username` CHAR(191) DEFAULT NULL COMMENT 'User''s username', `username` CHAR(191) DEFAULT NULL COMMENT 'User''s username',
......
ALTER TABLE `user` ADD COLUMN `is_bot` tinyint(1) DEFAULT 0 COMMENT 'True if this user is a bot' AFTER `id`;
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