-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix attach entity listener when reset class metadata factory #10786
Fix attach entity listener when reset class metadata factory #10786
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this suspicious at first, but this does not seem to break any tests so…
@@ -56,7 +56,5 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event) | |||
$metadata->addEntityListener($listener['event'], $listener['class'], $listener['method']); | |||
} | |||
} | |||
|
|||
unset($this->entityListeners[$metadata->name]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this listener, what it does is attach entity listeners as soon as class metadata is loaded. After that, it considers its job done forever, hence the unset (to save memory I guess).
tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
Thanks @vuongxuongminh ! |
When resetting entity manager via registry, if we use
Doctrine\ORM\Tools\AttachEntityListenersListener
to add entity event listeners, it can not be reattached because it delete listener after add on the first time then we will lose all entity listeners after reset entity manager.Symfony entity listener example:
and console command execution:
Expect
It work!
should be printed twice but only once.