Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Stop messing with the UOW (it's kind of hacking), just flush it again:</p> <p><strong>Config</strong></p> <pre><code>services: bill.listener: class: MyCompany\CompanyBundle\EventListener\BillListener arguments: ["@pdf_service"] tags : - { name: doctrine.event_subscriber, connection: default } </code></pre> <p><strong>Listener</strong></p> <pre><code>&lt;?php namespace MyCompany\CompanyBundle\EventListener; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Doctrine\Common\EventSubscriber; use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\Event\PostFlushEventArgs; use MyCompany\CompanyBundle\Service\MyPDFService; use MyCompany\CompanyBundle\Entity\Bill; class BillListener implements EventSubscriber { protected $pdfs; protected $bills; public function __construct(MyPDFService $pdfs) { $this-&gt;pdfs = $pdfs; } public function getSubscribedEvents() { return [ 'onFlush', 'postFlush' ]; } public function onFlush(OnFlushEventArgs $event) { $this-&gt;bills = []; /* @var $em \Doctrine\ORM\EntityManager */ $em = $event-&gt;getEntityManager(); /* @var $uow \Doctrine\ORM\UnitOfWork */ $uow = $em-&gt;getUnitOfWork(); foreach ($uow-&gt;getScheduledEntityInsertions() as $entity) { if ($entity instanceof Bill) { $this-&gt;bills[] = $entity; } } } public function postFlush(PostFlushEventArgs $event) { if (!empty($this-&gt;bills)) { /* @var $em \Doctrine\ORM\EntityManager */ $em = $event-&gt;getEntityManager(); foreach ($this-&gt;bills as $bill) { /* @var $bill \MyCompany\CompanyBundle\Entity\Bill */ $this-&gt;pdfs-&gt;generateFor($bill); $em-&gt;persist($bill); } $em-&gt;flush(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload