I try to use the onFlush event in the Doctrine to save a new object, but when I try to save it, it leads to an infinite loop. Here is what I do in Listener:
$countusers = $em->getRepository('DankeForumBundle:NotificationUser')->countNotificationsByDeal($entity);
if ($countusers > 0) {
$notification = new NotificationAction();
$notification->setDeal($entity);
$notification->setDatepost(new \DateTime());
$notification->setNotificationtype(NotificationAction::TYPE_TOP_DEAL);
$em->persist($notification);
$uow->computeChangeSet($em->getClassmetadata('Danke\ForumBundle\Entity\NotificationAction'), $notification);
}
I know that I get a loop when I fill in the onFlush event, but I do not! I just figured out a new set of changes, as it says in the documentation.
Can someone tell me where the problem is?
EDIT: Maybe it is interesting that I am sure it worked a few days ago, but I can’t change anything (which, as I know, cannot be true;)) ...
source
share