I needed to persist additional entities when other entities are persisted or updated. Therefore I created a solution inspired from this post: https://stackoverflow.com/a/11054101/1526162.
config.yml:
services:
transaktion.chain:
class: Foo\BarBundle\Listener\Chain
transaktion.flush:
class: Foo\BarBundle\Listener\Flush
arguments: [ @doctrine.orm.entity_manager, @transaktion.chain ]
tags:
- { name: kernel.event_listener, event: kernel.response, method: onResponse, priority: 5 }
transaktion.listener:
class: Foo\BarBundle\Listener\TransaktionLogger
arguments: [ @transaktion.chain ]
tags:
- { name: doctrine.event_listener, event: postPersist }
- { name: doctrine.event_listener, event: postUpdate }
- { name: doctrine.event_listener, event: preRemove }
The postPersist, postUpdate and preRemove events are adding information to the Chain and at the end, the kernel.response starts the Flush and the needed additional entites are created. Everything works fine.
But, when I persist entites inside a Console Command it is not working. I think there is no kernel.response event. Is there an other useful event that is working with Controllers and in Console Commands?
Additional info: I am using Symfony 2.3