Merge pull request #5339 from christianbeeznest/fixes-updates19

Internal: Update logout tracking for user sessions
pull/5340/head
christianbeeznest 8 months ago committed by GitHub
commit d3ec821d30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 34
      src/CoreBundle/Repository/TrackELoginRepository.php

@ -36,32 +36,14 @@ class TrackELoginRepository extends ServiceEntityRepository
public function updateLastLoginLogoutDate(int $userId, DateTime $logoutDate): void
{
$query = $this->createQueryBuilder('t')
->select('t.loginId')
->where('t.user = :userId')
->andWhere('t.logoutDate IS NULL')
->setParameter('userId', $userId)
->orderBy('t.loginDate', 'DESC')
->setMaxResults(1)
->getQuery()
;
try {
$lastLoginId = $query->getSingleScalarResult();
} catch (NoResultException|NonUniqueResultException) {
$lastLoginId = 0;
}
if ($lastLoginId) {
$qb = $this->createQueryBuilder('t')
->update()
->set('t.logoutDate', ':logoutDate')
->where('t.loginId = :loginId')
->setParameter('loginId', $lastLoginId)
->setParameter('logoutDate', $logoutDate)
;
$qb->getQuery()->execute();
$lastLoginRecord = $this->findOneBy(
['user' => $userId, 'logoutDate' => null],
['loginDate' => 'DESC']
);
if ($lastLoginRecord !== null) {
$lastLoginRecord->setLogoutDate($logoutDate);
$this->_em->flush();
}
}
}

Loading…
Cancel
Save