Unverified Commit 7a44511d authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #738 from noplanman/737-fix_date_updates

Fix empty date for User and Chat entities
parents 6357e95a 0ab9095c
...@@ -11,6 +11,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -11,6 +11,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Fixed ### Fixed
- Entity relations and wrong types for payments. - Entity relations and wrong types for payments.
- Allow empty string for `switch_inline_query` and `switch_inline_query_current_chat` (InlineKeyboardButton). - 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 ### Security
## [0.51.0] - 2017-12-05 ## [0.51.0] - 2017-12-05
......
...@@ -260,17 +260,13 @@ class DB ...@@ -260,17 +260,13 @@ class DB
/** /**
* Convert from unix timestamp to timestamp * 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 * @return string
*/ */
protected static function getTimestamp($time = null) protected static function getTimestamp($time = null)
{ {
if ($time === null) { return date('Y-m-d H:i:s', $time ?: time());
$time = time();
}
return date('Y-m-d H:i:s', $time);
} }
/** /**
...@@ -362,7 +358,7 @@ class DB ...@@ -362,7 +358,7 @@ class DB
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @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()) { if (!self::isDbConnected()) {
return false; return false;
...@@ -389,6 +385,7 @@ class DB ...@@ -389,6 +385,7 @@ class DB
$sth->bindValue(':first_name', $user->getFirstName()); $sth->bindValue(':first_name', $user->getFirstName());
$sth->bindValue(':last_name', $user->getLastName()); $sth->bindValue(':last_name', $user->getLastName());
$sth->bindValue(':language_code', $user->getLanguageCode()); $sth->bindValue(':language_code', $user->getLanguageCode());
$date = $date ?: self::getTimestamp();
$sth->bindValue(':created_at', $date); $sth->bindValue(':created_at', $date);
$sth->bindValue(':updated_at', $date); $sth->bindValue(':updated_at', $date);
...@@ -429,7 +426,7 @@ class DB ...@@ -429,7 +426,7 @@ class DB
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @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()) { if (!self::isDbConnected()) {
return false; return false;
...@@ -466,6 +463,7 @@ class DB ...@@ -466,6 +463,7 @@ class DB
$sth->bindValue(':title', $chat->getTitle()); $sth->bindValue(':title', $chat->getTitle());
$sth->bindValue(':username', $chat->getUsername()); $sth->bindValue(':username', $chat->getUsername());
$sth->bindValue(':all_members_are_administrators', $chat->getAllMembersAreAdministrators(), PDO::PARAM_INT); $sth->bindValue(':all_members_are_administrators', $chat->getAllMembersAreAdministrators(), PDO::PARAM_INT);
$date = $date ?: self::getTimestamp();
$sth->bindValue(':created_at', $date); $sth->bindValue(':created_at', $date);
$sth->bindValue(':updated_at', $date); $sth->bindValue(':updated_at', $date);
......
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