@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\EventListener;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Entity\User;
use Database;
use Database;
use Doctrine\DBAL\Cache\ArrayStatement;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@ -35,7 +36,7 @@ class LogoutListener
}
}
/**
/**
* @return RedirectResponse|null
* @return null| RedirectResponse
*/
*/
public function onSymfonyComponentSecurityHttpEventLogoutEvent(LogoutEvent $event)
public function onSymfonyComponentSecurityHttpEventLogoutEvent(LogoutEvent $event)
{
{
@ -50,18 +51,20 @@ class LogoutListener
$chat->setUserStatus(0);
$chat->setUserStatus(0);
}*/
}*/
$token = $this->storage->getToken();
$token = $this->storage->getToken();
/** @var null|User $user */
$user = $token->getUser();
$user = $token->getUser();
if ($user instanceof User) {
if ($user instanceof User) {
$userId = $token->getUser() ->getId();
$userId = $user ->getId();
$table = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$table = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = "SELECT login_id, login_date
$sql = "SELECT login_id, login_date
FROM $table
FROM { $table}
WHERE login_user_id = $userId
WHERE login_user_id = { $userId}
ORDER BY login_date DESC
ORDER BY login_date DESC
LIMIT 0,1";
LIMIT 0,1";
$loginId = null;
$loginId = null;
$connection = $this->em->getConnection();
$connection = $this->em->getConnection();
/** @var ArrayStatement $result */
$result = $connection->executeQuery($sql);
$result = $connection->executeQuery($sql);
if ($result->rowCount() > 0) {
if ($result->rowCount() > 0) {
$row = $result->fetchAssociative();
$row = $result->fetchAssociative();
@ -73,14 +76,14 @@ class LogoutListener
$loginAs = $this->checker->isGranted('ROLE_PREVIOUS_ADMIN');
$loginAs = $this->checker->isGranted('ROLE_PREVIOUS_ADMIN');
if (!$loginAs) {
if (!$loginAs) {
$current_date = api_get_utc_datetime();
$current_date = api_get_utc_datetime();
$sql = "UPDATE $table
$sql = "UPDATE { $table}
SET logout_date='".$current_date."'
SET logout_date='".$current_date."'
WHERE login_id='$loginId'";
WHERE login_id='{ $loginId} '";
$connection->executeQuery($sql);
$connection->executeQuery($sql);
}
}
$online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE);
$online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE);
$sql = 'DELETE FROM '.$online_table." WHERE login_user_id = $userId";
$sql = 'DELETE FROM '.$online_table." WHERE login_user_id = { $userId} ";
$connection->executeQuery($sql);
$connection->executeQuery($sql);
}
}