diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 5877da94b..0d62f412b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -548,7 +548,7 @@ class UnitOfWork implements PropertyChangedListener $class = $this->em->getClassMetadata(get_class($entity)); } - $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::preFlush); + $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::preFlush) & ~ListenersInvoker::INVOKE_MANAGER; if ($invoke !== ListenersInvoker::INVOKE_NONE) { $this->listenersInvoker->invoke($class, Events::preFlush, $entity, new PreFlushEventArgs($this->em), $invoke); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php new file mode 100644 index 000000000..dfdb207fc --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php @@ -0,0 +1,63 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2692Foo'), + )); + } catch(\Exception $e) { + return; + } + $this->_em->clear(); + } + + public function testIsListenerCalledOnlyOnceOnPreFlush() + { + $listener = $this->getMock('Doctrine\Tests\ORM\Functional\Ticket\DDC2692Listener', array('preFlush')); + $listener->expects($this->once())->method('preFlush'); + + $this->_em->getEventManager()->addEventSubscriber($listener); + + $this->_em->persist(new DDC2692Foo); + $this->_em->persist(new DDC2692Foo); + + $this->_em->flush(); + $this->_em->clear(); + } +} +/** + * @Entity @Table(name="ddc_2692_foo") + */ +class DDC2692Foo +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} + +class DDC2692Listener implements EventSubscriber { + + public function getSubscribedEvents() { + return array(\Doctrine\ORM\Events::preFlush); + } + + public function preFlush(PreFlushEventArgs $args) { + } +} + +