Symfony Event Listener, Debug bar doesn't work

Viewed 205

I have this EventListener class who update the user activity in database:

App\EventListener\ControllerListener:
    tags:
        - { name: kernel.event_listener, event: kernel.controller }

<?php

namespace App\EventListener;

use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\Security\Core\Security;

class ControllerListener
{
    private $security;
    private $em;

    public function __construct(Security $security, EntityManagerInterface $entityManager)
    {
        $this->security = $security;
        $this->em = $entityManager;

    }

    public function onKernelController(ControllerEvent $event)
    {
        $user = $this->security->getUser();
        $em = $this->em;

        if ($user) {
            $user->setLastSeenDate(new \DateTime());
            $em->persist($user);
            $em->flush();
        }
    }
}

The query is OK and update the user inside the database, but the debug bar is broken after that:

enter image description here

An error occurred while loading the web debug toolbar

If I remove the query inside ControllerListener class, the debug bar work again.

How to fix this issue please?

1 Answers

Solved with a dependency update:

composer update

php bin/console cache:warmup

Related