mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Doctrine Transaction and EventSubscriber #6203
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @NicolaPez on GitHub (Mar 20, 2019).
I'm writing here a support question because I don't find the solution around the web, sorry.
I'm writing a method in my Symfony 3 application for bulk user creation. The flux is uploading a csv file with all the necessary data.
I created a Service, into I write all the logic of this operation. This is my Service:
Also I wrote this EmailSubscriber, for sending an activation email each time the entity User is persisted:
And this is question:
The EventSubscriber catch the persisted event before the transaction commit. I want or persist all the row in my db, or response with violation and ask to User to modify his csv file.
Because this, one of the useCase can be some activation email sended but no persisting the User in DB, for example for some validate violation of one of the csv row.
I hope I was crearl, the case is a bit intricate.
@Ocramius commented on GitHub (Mar 20, 2019):
You probably want to hook into
postFlushinstead - that's when you know that the data was saved successfully.@NicolaPez commented on GitHub (Mar 20, 2019):
But with that Event I cant get each entity flushed, as lifecycle event permit, right?
So I don't know how resolve this issue.
@Ocramius commented on GitHub (Mar 20, 2019):
You'd collect the entities in
onFlush, then operate duringpostFlush.I don't think you should perform this sort of operations when tied to the ORM though, as it is hiding your business logic very deep in the EntityManager integration, which will be hard to understand/debug for future maintainers of your code (including yourself).
@NicolaPez commented on GitHub (Mar 20, 2019):
Ok, I'll try to think about this and improve my flux.
Your advice was useful. Thanks.