php - Symfony3.3, Doctrine2. EventSubscriber, on update not executed -


i have subscriber located in appbundle\doctrinelisteners body of this

namespace appbundle\doctrinelisteners;  use doctrine\common\eventsubscriber; use doctrine\orm\event\onflusheventargs; use appbundle\entity\bing\keywordreport; use doctrine\orm\events;  /**  * listener used on update fielt create history  */ class keywordsubscriber implements eventsubscriber {     public function onflush(onflusheventargs $args)     {         throw new \exception("error processing request", 1); //for testing           $em  = $args->getentitymanager();         $uow = $em->getunitofwork();          foreach ($uow->getscheduledentityupdates() $updated) {             if ($updated instanceof keywordreport) {                 //do work             }         }          $uow->computechangesets();     }      public function getsubscribedevents()     {         return [events::onflush => ['onflush', 10], events::preupdate];     } } 

i'm using autoconfigure introduced in symfony 3.3

service.yml

services:     # default configuration services in *this* file     _defaults:         # automatically injects dependencies in services         autowire: true         # automatically registers services commands, event subscribers, etc.         autoconfigure: true         # means cannot fetch services directly container via $container->get()         # if need this, can override setting on individual services         public: false 

in entity have in annotation * @orm\entitylisteners({"appbundle\doctrinelisteners\keywordsubscriber"}) why not executed?

as @yanneugoné noted in comment – eventsubscribes , doctrine entitylisteners different things. eventlisteners in symfony have registered manually:

namespace appbundle\doctrinelisteners;  use doctrine\orm\event\onflusheventargs; use appbundle\entity\bing\keywordreport;  class keywordlistener {     public function onflush(onflusheventargs $eventargs)     {         $em = $eventargs->getentitymanager();         $uow = $em->getunitofwork();          foreach ($uow->getscheduledentityinsertions() $entity) {             // … action         }          foreach ($uow->getscheduledentityupdates() $entity) {             // … action         }          foreach ($uow->getscheduledentitydeletions() $entity) {             // … action         }          foreach ($uow->getscheduledcollectiondeletions() $col) {             // … action         }          foreach ($uow->getscheduledcollectionupdates() $col) {             // … action         }     } } 
#services.yml services:     # …      appbundle\doctrinelisteners\keywordlistener:         tags:             - { name: doctrine.event_listener, event: onflush } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -