diff --git a/src/Listener/BaseMediaEventSubscriber.php b/src/Listener/BaseMediaEventSubscriber.php index a6362ada9..0942d3150 100644 --- a/src/Listener/BaseMediaEventSubscriber.php +++ b/src/Listener/BaseMediaEventSubscriber.php @@ -22,6 +22,7 @@ /** * @phpstan-template T of ObjectManager + * NEXT_MAJOR: do not implement EventSubscriber interface anymore */ abstract class BaseMediaEventSubscriber implements EventSubscriber { diff --git a/src/Listener/ODM/MediaEventSubscriber.php b/src/Listener/ODM/MediaEventSubscriber.php index d9de0eac4..de1a457e4 100644 --- a/src/Listener/ODM/MediaEventSubscriber.php +++ b/src/Listener/ODM/MediaEventSubscriber.php @@ -24,6 +24,9 @@ */ final class MediaEventSubscriber extends BaseMediaEventSubscriber { + /** + * NEXT_MAJOR: remove this method. + */ public function getSubscribedEvents(): array { return [ diff --git a/src/Listener/ORM/MediaEventSubscriber.php b/src/Listener/ORM/MediaEventSubscriber.php index b21050c1f..17053adb6 100644 --- a/src/Listener/ORM/MediaEventSubscriber.php +++ b/src/Listener/ORM/MediaEventSubscriber.php @@ -39,6 +39,9 @@ public function __construct( parent::__construct($pool); } + /** + * NEXT_MAJOR: remove this method. + */ public function getSubscribedEvents(): array { return [ diff --git a/src/Resources/config/doctrine_mongodb.php b/src/Resources/config/doctrine_mongodb.php index 21413b335..f81047c13 100644 --- a/src/Resources/config/doctrine_mongodb.php +++ b/src/Resources/config/doctrine_mongodb.php @@ -13,6 +13,7 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; +use Doctrine\ODM\MongoDB\Events; use Sonata\MediaBundle\Document\GalleryManager; use Sonata\MediaBundle\Document\MediaManager; use Sonata\MediaBundle\Generator\UuidGenerator; @@ -38,7 +39,24 @@ ->set('sonata.media.generator.default', UuidGenerator::class) ->set('sonata.media.doctrine.event_subscriber', MediaEventSubscriber::class) - ->tag('doctrine_mongodb.odm.event_subscriber') + ->tag('doctrine_mongodb.odm.event_listener', [ + 'event' => Events::prePersist, + ]) + ->tag('doctrine_mongodb.odm.event_listener', [ + 'event' => Events::preUpdate, + ]) + ->tag('doctrine_mongodb.odm.event_listener', [ + 'event' => Events::preRemove, + ]) + ->tag('doctrine_mongodb.odm.event_listener', [ + 'event' => Events::postUpdate, + ]) + ->tag('doctrine_mongodb.odm.event_listener', [ + 'event' => Events::postRemove, + ]) + ->tag('doctrine_mongodb.odm.event_listener', [ + 'event' => Events::postPersist, + ]) ->args([ service('sonata.media.pool'), ]); diff --git a/src/Resources/config/doctrine_orm.php b/src/Resources/config/doctrine_orm.php index f8f8ae163..dc154f632 100644 --- a/src/Resources/config/doctrine_orm.php +++ b/src/Resources/config/doctrine_orm.php @@ -13,6 +13,7 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; +use Doctrine\ORM\Events; use Sonata\MediaBundle\Entity\GalleryManager; use Sonata\MediaBundle\Entity\MediaManager; use Sonata\MediaBundle\Generator\IdGenerator; @@ -36,7 +37,27 @@ ->set('sonata.media.generator.default', IdGenerator::class) ->set('sonata.media.doctrine.event_subscriber', MediaEventSubscriber::class) - ->tag('doctrine.event_subscriber') + ->tag('doctrine.event_listener', [ + 'event' => Events::prePersist, + ]) + ->tag('doctrine.event_listener', [ + 'event' => Events::preUpdate, + ]) + ->tag('doctrine.event_listener', [ + 'event' => Events::preRemove, + ]) + ->tag('doctrine.event_listener', [ + 'event' => Events::postUpdate, + ]) + ->tag('doctrine.event_listener', [ + 'event' => Events::postRemove, + ]) + ->tag('doctrine.event_listener', [ + 'event' => Events::postPersist, + ]) + ->tag('doctrine.event_listener', [ + 'event' => Events::onClear, + ]) ->args([ service('sonata.media.pool'), service('sonata.media.manager.category')->nullOnInvalid(),