diff --git a/config/services.yaml b/config/services.yaml index 19d614e1..88f13415 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -76,7 +76,7 @@ services: # Only the event classes specified here are saved to DB (set to []) to log all events $whitelist: [] - App\EventListener\LogSystem\EventLoggerListener: + App\EventSubscriber\LogSystem\EventLoggerSubscriber: arguments: $save_changed_fields: '%env(bool:HISTORY_SAVE_CHANGED_FIELDS)%' $save_changed_data: '%env(bool:HISTORY_SAVE_CHANGED_DATA)%' @@ -85,7 +85,7 @@ services: tags: - { name: 'doctrine.event_subscriber' } - App\EventListener\LogSystem\LogDBMigrationListener: + App\EventSubscriber\LogSystem\LogDBMigrationSubscriber: tags: - { name: 'doctrine.event_subscriber' } diff --git a/src/EventListener/LogSystem/EventLoggerListener.php b/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php similarity index 97% rename from src/EventListener/LogSystem/EventLoggerListener.php rename to src/EventSubscriber/LogSystem/EventLoggerSubscriber.php index bfecf1cd..b3f07a9b 100644 --- a/src/EventListener/LogSystem/EventLoggerListener.php +++ b/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php @@ -20,7 +20,7 @@ declare(strict_types=1); -namespace App\EventListener\LogSystem; +namespace App\EventSubscriber\LogSystem; use App\Entity\Attachments\Attachment; use App\Entity\Base\AbstractDBElement; @@ -38,7 +38,7 @@ use App\Entity\UserSystem\User; use App\Services\LogSystem\EventCommentHelper; use App\Services\LogSystem\EventLogger; use App\Services\LogSystem\EventUndoHelper; -use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; +use Doctrine\Common\EventSubscriber; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\Event\PostFlushEventArgs; @@ -50,10 +50,7 @@ use Symfony\Component\Serializer\SerializerInterface; /** * This event subscriber writes to the event log when entities are changed, removed, created. */ -#[AsDoctrineListener(Events::onFlush)] -#[AsDoctrineListener(Events::postPersist)] -#[AsDoctrineListener(Events::postFlush)] -class EventLoggerListener +class EventLoggerSubscriber implements EventSubscriber { /** * @var array The given fields will not be saved, because they contain sensitive information @@ -190,6 +187,14 @@ class EventLoggerListener return true; } + public function getSubscribedEvents(): array + { + return[ + Events::onFlush, + Events::postPersist, + Events::postFlush, + ]; + } protected function logElementDeleted(AbstractDBElement $entity, EntityManagerInterface $em): void { diff --git a/src/EventListener/LogSystem/LogDBMigrationListener.php b/src/EventSubscriber/LogSystem/LogDBMigrationSubscriber.php similarity index 90% rename from src/EventListener/LogSystem/LogDBMigrationListener.php rename to src/EventSubscriber/LogSystem/LogDBMigrationSubscriber.php index edcc12d4..07ec8ea4 100644 --- a/src/EventListener/LogSystem/LogDBMigrationListener.php +++ b/src/EventSubscriber/LogSystem/LogDBMigrationSubscriber.php @@ -20,11 +20,11 @@ declare(strict_types=1); -namespace App\EventListener\LogSystem; +namespace App\EventSubscriber\LogSystem; use App\Entity\LogSystem\DatabaseUpdatedLogEntry; use App\Services\LogSystem\EventLogger; -use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; +use Doctrine\Common\EventSubscriber; use Doctrine\Migrations\DependencyFactory; use Doctrine\Migrations\Event\MigrationsEventArgs; use Doctrine\Migrations\Events; @@ -32,9 +32,7 @@ use Doctrine\Migrations\Events; /** * This subscriber logs databaseMigrations to Event log. */ -#[AsDoctrineListener(Events::onMigrationsMigrated)] -#[AsDoctrineListener(Events::onMigrationsMigrating)] -class LogDBMigrationListener +class LogDBMigrationSubscriber implements EventSubscriber { protected ?string $old_version = null; protected ?string $new_version = null; @@ -78,4 +76,12 @@ class LogDBMigrationListener $this->old_version = (string) $aliasResolver->resolveVersionAlias('current'); } } + + public function getSubscribedEvents(): array + { + return [ + Events::onMigrationsMigrated, + Events::onMigrationsMigrating, + ]; + } }