Documents created by an EventSubscriber are not persisted
- Dominant language
- PHP
- Stars
- 181
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Description
In my EventSubscriber I am creating a new Document on the preUpdate or prePersist events.
``` php
public function prePersist(LifecycleEventArgs $args) {
$doc = new Document();
// initialization here ...
$args->getObjectManager()->persist($doc);
}
```
This Document is not persisted as the changesets are calculated before the event is fired. Moreover the inserts are flushed before that the update event is fired, so there isn't a simple solution, as all the pre- events should be fired during the changesets calculation.
Solving this issue obviously involves an important refactoring of the UnifOfWork and maybe can cause some BC breaks.
A temporary fix for me can be to listen for the `preFlush` event (that is fired before the changeset calculation), but this means that I will have to manually calculate the changesets and look for the instance of the Document I want to observe (see #531 ).
What I don't like about this is that this EventListener will be fired for every flush operation of the DocumentManager and it can slow down the entire application.
What do you think about?
Contributor guide
Research direction
Start by tracing the prePersist, preUpdate, preFlush, and changeset-calculation flow described in the issue, including the UnitOfWork and DocumentManager entry points. Review #531 and the comment discussion before proposing a solution; done means defining a supported lifecycle ordering that persists Documents created by subscribers without leaving existing flush behavior unresolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100