Symfony2 postUpdate listener not working

2019-08-08 01:33发布

I'm getting the following error message,

Catchable fatal error: Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in

and don't know where to start in solving this. You can see my listener (shortened) below

    public function postUpdate(LifecycleEventArgs $args){
    $entity = $args->getEntity();

    $em = $args->getEntityManager();
    $args->getEntityManager()->clear();

    $securityContext = $this->container->get('security.context');
    $token = $securityContext->getToken();
    $userLoggedIn = $token->getUser();


    if ($entity instanceof Activity) {




    $em->flush();


    }
}

Has anyone got any suggestions?

Here's my services section from config

   activity.listener:
    class: My\Bundle\EventListener\ActivityListener
    arguments: ['@service_container']
    tags:
        - { name: doctrine.event_listener, event: prePersist }
        - { name: doctrine.event_listener, event: postPersist }
        - { name: doctrine.event_listener, event: postUpdate }

1条回答
疯言疯语
2楼-- · 2019-08-08 02:40

The problem is caused probably by the $em->flush() inside the postUpdate event handler which later will trigger the UnitOfWork::executeUpdates function call.

If that's the case then the only workaround I've found is the one I documented in a Doctrine bug report (although I don't regard this as a true Doctrine bug).

查看更多
登录 后发表回答