Skip to content

Commit 7a44511

Browse files
authoredJan 7, 2018
Merge pull request #738 from noplanman/737-fix_date_updates
Fix empty date for User and Chat entities
2 parents 6357e95 + 0ab9095 commit 7a44511

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
1111
### Fixed
1212
- Entity relations and wrong types for payments.
1313
- Allow empty string for `switch_inline_query` and `switch_inline_query_current_chat` (InlineKeyboardButton).
14+
- Fix empty date entry for User and Chat entities, using the current timestamp instead.
1415
### Security
1516

1617
## [0.51.0] - 2017-12-05

‎src/DB.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,13 @@ public static function selectMessages($limit = null)
260260
/**
261261
* Convert from unix timestamp to timestamp
262262
*
263-
* @param int $time Unix timestamp (if null, current timestamp is used)
263+
* @param int $time Unix timestamp (if empty, current timestamp is used)
264264
*
265265
* @return string
266266
*/
267267
protected static function getTimestamp($time = null)
268268
{
269-
if ($time === null) {
270-
$time = time();
271-
}
272-
273-
return date('Y-m-d H:i:s', $time);
269+
return date('Y-m-d H:i:s', $time ?: time());
274270
}
275271

276272
/**
@@ -362,7 +358,7 @@ public static function insertTelegramUpdate(
362358
* @return bool If the insert was successful
363359
* @throws TelegramException
364360
*/
365-
public static function insertUser(User $user, $date, Chat $chat = null)
361+
public static function insertUser(User $user, $date = null, Chat $chat = null)
366362
{
367363
if (!self::isDbConnected()) {
368364
return false;
@@ -389,6 +385,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
389385
$sth->bindValue(':first_name', $user->getFirstName());
390386
$sth->bindValue(':last_name', $user->getLastName());
391387
$sth->bindValue(':language_code', $user->getLanguageCode());
388+
$date = $date ?: self::getTimestamp();
392389
$sth->bindValue(':created_at', $date);
393390
$sth->bindValue(':updated_at', $date);
394391

@@ -429,7 +426,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
429426
* @return bool If the insert was successful
430427
* @throws TelegramException
431428
*/
432-
public static function insertChat(Chat $chat, $date, $migrate_to_chat_id = null)
429+
public static function insertChat(Chat $chat, $date = null, $migrate_to_chat_id = null)
433430
{
434431
if (!self::isDbConnected()) {
435432
return false;
@@ -466,6 +463,7 @@ public static function insertChat(Chat $chat, $date, $migrate_to_chat_id = null)
466463
$sth->bindValue(':title', $chat->getTitle());
467464
$sth->bindValue(':username', $chat->getUsername());
468465
$sth->bindValue(':all_members_are_administrators', $chat->getAllMembersAreAdministrators(), PDO::PARAM_INT);
466+
$date = $date ?: self::getTimestamp();
469467
$sth->bindValue(':created_at', $date);
470468
$sth->bindValue(':updated_at', $date);
471469

0 commit comments

Comments
 (0)