11<?php
22
33namespace JMS \JobQueueBundle \Entity \Listener ;
4- use Doctrine \ORM \Event \LifecycleEventArgs ;
4+ use Doctrine \Common \Util \ClassUtils ;
5+ use Doctrine \DBAL \Exception ;
6+ use Doctrine \DBAL \Schema \SchemaException ;
7+ use Doctrine \ORM \Tools \Event \GenerateSchemaEventArgs ;
8+ use Doctrine \Persistence \Event \LifecycleEventArgs ;
9+ use Doctrine \Persistence \Mapping \MappingException ;
510use JMS \JobQueueBundle \Entity \Job ;
611use Doctrine \Persistence \ManagerRegistry ;
712
@@ -27,55 +32,65 @@ public function __construct(ManagerRegistry $registry)
2732 $ this ->ref ->setAccessible (true );
2833 }
2934
30- public function postLoad (\ Doctrine \ ORM \ Event \ LifecycleEventArgs $ event )
35+ public function postLoad (LifecycleEventArgs $ event ): void
3136 {
32- $ entity = $ event ->getEntity ();
33- if ( ! $ entity instanceof \ JMS \ JobQueueBundle \ Entity \ Job) {
37+ $ entity = $ event ->getObject ();
38+ if ( ! $ entity instanceof Job) {
3439 return ;
3540 }
3641
3742 $ this ->ref ->setValue ($ entity , new PersistentRelatedEntitiesCollection ($ this ->registry , $ entity ));
3843 }
3944
40- public function preRemove (LifecycleEventArgs $ event )
45+ /**
46+ * @throws Exception
47+ */
48+ public function preRemove (LifecycleEventArgs $ event ): void
4149 {
42- $ entity = $ event ->getEntity ();
50+ $ entity = $ event ->getObject ();
4351 if ( ! $ entity instanceof Job) {
4452 return ;
4553 }
4654
47- $ con = $ event ->getEntityManager ()->getConnection ();
48- $ con ->executeUpdate ("DELETE FROM jms_job_related_entities WHERE job_id = :id " , array (
55+ $ con = $ event ->getObjectManager ()->getConnection ();
56+ $ con ->executeStatement ("DELETE FROM jms_job_related_entities WHERE job_id = :id " , array (
4957 'id ' => $ entity ->getId (),
5058 ));
5159 }
5260
53- public function postPersist (\Doctrine \ORM \Event \LifecycleEventArgs $ event )
61+ /**
62+ * @throws Exception
63+ */
64+ public function postPersist (LifecycleEventArgs $ event ): void
5465 {
55- $ entity = $ event ->getEntity ();
56- if ( ! $ entity instanceof \ JMS \ JobQueueBundle \ Entity \ Job) {
66+ $ entity = $ event ->getObject ();
67+ if ( ! $ entity instanceof Job) {
5768 return ;
5869 }
5970
60- $ con = $ event ->getEntityManager ()->getConnection ();
71+ $ con = $ event ->getObjectManager ()->getConnection ();
6172 foreach ($ this ->ref ->getValue ($ entity ) as $ relatedEntity ) {
62- $ relClass = \ Doctrine \ Common \ Util \ ClassUtils::getClass ($ relatedEntity );
73+ $ relClass = ClassUtils::getClass ($ relatedEntity );
6374 $ relId = $ this ->registry ->getManagerForClass ($ relClass )->getMetadataFactory ()->getMetadataFor ($ relClass )->getIdentifierValues ($ relatedEntity );
6475 asort ($ relId );
6576
6677 if ( ! $ relId ) {
6778 throw new \RuntimeException ('The identifier for the related entity " ' .$ relClass .'" was empty. ' );
6879 }
6980
70- $ con ->executeUpdate ("INSERT INTO jms_job_related_entities (job_id, related_class, related_id) VALUES (:jobId, :relClass, :relId) " , array (
81+ $ con ->executeStatement ("INSERT INTO jms_job_related_entities (job_id, related_class, related_id) VALUES (:jobId, :relClass, :relId) " , array (
7182 'jobId ' => $ entity ->getId (),
7283 'relClass ' => $ relClass ,
7384 'relId ' => json_encode ($ relId ),
7485 ));
7586 }
7687 }
7788
78- public function postGenerateSchema (\Doctrine \ORM \Tools \Event \GenerateSchemaEventArgs $ event )
89+ /**
90+ * @throws SchemaException
91+ * @throws MappingException
92+ */
93+ public function postGenerateSchema (GenerateSchemaEventArgs $ event ): void
7994 {
8095 $ schema = $ event ->getSchema ();
8196
0 commit comments