1

My postUpdate function fire only when the change is by a form submit, when the change comes by an update function as the following it wont fire. my post update function :

public function postUpdate(LifecycleEventArgs $args) {
    error_log('in post update');
}

the life event declaration :

custom.doctrine.listeer:
        class: Custom\CoreBundle\Listeners\CustomDoctrineListener
        tags:
            - { name: doctrine.event_listener, event: postUpdate, method: postUpdate }
            - { name: doctrine.event_listener, event: prePersist, method: prePersist }

the call that don't triggers the the life event :

public function setPrivate($id,$private){
  $qb=$this->createQueryBuilder('cc')
    ->update()
    ->set('cc.private',$private)
    ->where('cc.id='.$id);
  return $qb->getQuery()->getResult();
}

1 Answers1

0

Use the entity manager to trigger the lifecycle event rather than writing the update query yourself.

// get the entity manager as $em ($em = ...)
$cc = $em->getRepository('your:repository')->find($id);
$cc->setPrivate($private);

$em->flush();

Check out Doctrine Lifecycle Events

Jason Roman
  • 8,146
  • 10
  • 35
  • 40