Skip to content

Fix empty date for User and Chat entities #738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Fixed
- Entity relations and wrong types for payments.
- Allow empty string for `switch_inline_query` and `switch_inline_query_current_chat` (InlineKeyboardButton).
- Fix empty date entry for User and Chat entities, using the current timestamp instead.
### Security

## [0.51.0] - 2017-12-05
Expand Down
14 changes: 6 additions & 8 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,13 @@ public static function selectMessages($limit = null)
/**
* Convert from unix timestamp to timestamp
*
* @param int $time Unix timestamp (if null, current timestamp is used)
* @param int $time Unix timestamp (if empty, current timestamp is used)
*
* @return string
*/
protected static function getTimestamp($time = null)
{
if ($time === null) {
$time = time();
}

return date('Y-m-d H:i:s', $time);
return date('Y-m-d H:i:s', $time ?: time());
}

/**
Expand Down Expand Up @@ -362,7 +358,7 @@ public static function insertTelegramUpdate(
* @return bool If the insert was successful
* @throws TelegramException
*/
public static function insertUser(User $user, $date, Chat $chat = null)
public static function insertUser(User $user, $date = null, Chat $chat = null)
{
if (!self::isDbConnected()) {
return false;
Expand All @@ -389,6 +385,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
$sth->bindValue(':first_name', $user->getFirstName());
$sth->bindValue(':last_name', $user->getLastName());
$sth->bindValue(':language_code', $user->getLanguageCode());
$date = $date ?: self::getTimestamp();
$sth->bindValue(':created_at', $date);
$sth->bindValue(':updated_at', $date);

Expand Down Expand Up @@ -429,7 +426,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
* @return bool If the insert was successful
* @throws TelegramException
*/
public static function insertChat(Chat $chat, $date, $migrate_to_chat_id = null)
public static function insertChat(Chat $chat, $date = null, $migrate_to_chat_id = null)
{
if (!self::isDbConnected()) {
return false;
Expand Down Expand Up @@ -466,6 +463,7 @@ public static function insertChat(Chat $chat, $date, $migrate_to_chat_id = null)
$sth->bindValue(':title', $chat->getTitle());
$sth->bindValue(':username', $chat->getUsername());
$sth->bindValue(':all_members_are_administrators', $chat->getAllMembersAreAdministrators(), PDO::PARAM_INT);
$date = $date ?: self::getTimestamp();
$sth->bindValue(':created_at', $date);
$sth->bindValue(':updated_at', $date);

Expand Down