Merge pull request #11174 from MrPetovan/bug/11169-last_used-null

Handle null value for last_used fields in TrustedBrowsers and AppSpecificPassword
This commit is contained in:
Philipp 2022-01-23 08:56:44 +01:00 committed by GitHub
commit b55c5d4d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 11 deletions

View File

@ -107,12 +107,12 @@ class Trusted extends BaseSettings
$trustedBrowserDisplay = array_map(function (TwoFactor\Model\TrustedBrowser $trustedBrowser) use ($parser) { $trustedBrowserDisplay = array_map(function (TwoFactor\Model\TrustedBrowser $trustedBrowser) use ($parser) {
$dates = [ $dates = [
'created_ago' => Temporal::getRelativeDate($trustedBrowser->created), 'created_ago' => Temporal::getRelativeDate($trustedBrowser->created),
'created_utc' => DateTimeFormat::utc($trustedBrowser->created, 'c'), 'created_utc' => DateTimeFormat::utc($trustedBrowser->created, 'c'),
'created_local' => DateTimeFormat::local($trustedBrowser->created, 'r'), 'created_local' => DateTimeFormat::local($trustedBrowser->created, 'r'),
'last_used_ago' => Temporal::getRelativeDate($trustedBrowser->last_used), 'last_used_ago' => Temporal::getRelativeDate($trustedBrowser->last_used),
'last_used_utc' => DateTimeFormat::utc($trustedBrowser->last_used, 'c'), 'last_used_utc' => $trustedBrowser->last_used ? DateTimeFormat::utc($trustedBrowser->last_used, 'c') : '',
'last_used_local' => DateTimeFormat::local($trustedBrowser->last_used, 'r'), 'last_used_local' => $trustedBrowser->last_used ? DateTimeFormat::local($trustedBrowser->last_used, 'r') : '',
]; ];
$result = $parser->parse($trustedBrowser->user_agent); $result = $parser->parse($trustedBrowser->user_agent);

View File

@ -86,11 +86,9 @@ class AppSpecificPassword
$appSpecificPasswords = DBA::toArray($appSpecificPasswordsStmt); $appSpecificPasswords = DBA::toArray($appSpecificPasswordsStmt);
array_walk($appSpecificPasswords, function (&$value) { array_walk($appSpecificPasswords, function (&$value) {
$last_used = $value['last_used'] ?? DBA::NULL_DATETIME; $value['ago'] = Temporal::getRelativeDate($value['last_used']);
$value['utc'] = $value['last_used'] ? DateTimeFormat::utc($value['last_used'], 'c') : '';
$value['ago'] = Temporal::getRelativeDate($last_used); $value['local'] = $value['last_used'] ? DateTimeFormat::local($value['last_used'], 'r') : '';
$value['utc'] = DateTimeFormat::utc($last_used, 'c');
$value['local'] = DateTimeFormat::local($last_used, 'r');
}); });
return $appSpecificPasswords; return $appSpecificPasswords;