function login_history_last_login in Login History 8
Same name and namespace in other branches
- 6 login_history.module \login_history_last_login()
- 7 login_history.module \login_history_last_login()
Provide data about the last login for a user.
Parameters
\Drupal\Core\Session\AccountInterface|null $account: An optional user to get the last login for.
Return value
object|false An object containing information about the last login or FALSE if no result is found.
Deprecated
in login_history:8.x-1.1 and is removed from login_history:8.x-2.0. There is no replacement. Implement your own DB query instead.
See also
https://www.drupal.org/project/login_history/issues/3185870
File
- ./
login_history.module, line 51 - Records a history of the site's user logins.
Code
function login_history_last_login(AccountInterface $account = NULL) {
if (!$account) {
$account = \Drupal::currentUser();
}
if ($account
->isAnonymous()) {
return FALSE;
}
return \Drupal::database()
->select('login_history', 'lh')
->fields('lh', [
'login',
'hostname',
'one_time',
'user_agent',
])
->condition('uid', $account
->id())
->orderBy('login', 'DESC')
->range(0, 1)
->execute()
->fetch();
}