Migrated deprecated doctrine event subscribers to doctrine event listeners

This commit is contained in:
Jan Böhmer 2023-12-05 22:08:07 +01:00
parent d991643b0e
commit f9d47e0865
3 changed files with 13 additions and 24 deletions

View file

@ -76,7 +76,7 @@ services:
# Only the event classes specified here are saved to DB (set to []) to log all events # Only the event classes specified here are saved to DB (set to []) to log all events
$whitelist: [] $whitelist: []
App\EventSubscriber\LogSystem\EventLoggerSubscriber: App\EventListener\LogSystem\EventLoggerListener:
arguments: arguments:
$save_changed_fields: '%env(bool:HISTORY_SAVE_CHANGED_FIELDS)%' $save_changed_fields: '%env(bool:HISTORY_SAVE_CHANGED_FIELDS)%'
$save_changed_data: '%env(bool:HISTORY_SAVE_CHANGED_DATA)%' $save_changed_data: '%env(bool:HISTORY_SAVE_CHANGED_DATA)%'
@ -85,7 +85,7 @@ services:
tags: tags:
- { name: 'doctrine.event_subscriber' } - { name: 'doctrine.event_subscriber' }
App\EventSubscriber\LogSystem\LogDBMigrationSubscriber: App\EventListener\LogSystem\LogDBMigrationListener:
tags: tags:
- { name: 'doctrine.event_subscriber' } - { name: 'doctrine.event_subscriber' }

View file

@ -20,7 +20,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\EventSubscriber\LogSystem; namespace App\EventListener\LogSystem;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
@ -38,7 +38,7 @@ use App\Entity\UserSystem\User;
use App\Services\LogSystem\EventCommentHelper; use App\Services\LogSystem\EventCommentHelper;
use App\Services\LogSystem\EventLogger; use App\Services\LogSystem\EventLogger;
use App\Services\LogSystem\EventUndoHelper; use App\Services\LogSystem\EventUndoHelper;
use Doctrine\Common\EventSubscriber; use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Event\PostFlushEventArgs; use Doctrine\ORM\Event\PostFlushEventArgs;
@ -50,7 +50,10 @@ use Symfony\Component\Serializer\SerializerInterface;
/** /**
* This event subscriber writes to the event log when entities are changed, removed, created. * This event subscriber writes to the event log when entities are changed, removed, created.
*/ */
class EventLoggerSubscriber implements EventSubscriber #[AsDoctrineListener(Events::onFlush)]
#[AsDoctrineListener(Events::postPersist)]
#[AsDoctrineListener(Events::postFlush)]
class EventLoggerListener
{ {
/** /**
* @var array The given fields will not be saved, because they contain sensitive information * @var array The given fields will not be saved, because they contain sensitive information
@ -187,14 +190,6 @@ class EventLoggerSubscriber implements EventSubscriber
return true; return true;
} }
public function getSubscribedEvents(): array
{
return[
Events::onFlush,
Events::postPersist,
Events::postFlush,
];
}
protected function logElementDeleted(AbstractDBElement $entity, EntityManagerInterface $em): void protected function logElementDeleted(AbstractDBElement $entity, EntityManagerInterface $em): void
{ {

View file

@ -20,11 +20,11 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\EventSubscriber\LogSystem; namespace App\EventListener\LogSystem;
use App\Entity\LogSystem\DatabaseUpdatedLogEntry; use App\Entity\LogSystem\DatabaseUpdatedLogEntry;
use App\Services\LogSystem\EventLogger; use App\Services\LogSystem\EventLogger;
use Doctrine\Common\EventSubscriber; use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\Migrations\DependencyFactory; use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Event\MigrationsEventArgs; use Doctrine\Migrations\Event\MigrationsEventArgs;
use Doctrine\Migrations\Events; use Doctrine\Migrations\Events;
@ -32,7 +32,9 @@ use Doctrine\Migrations\Events;
/** /**
* This subscriber logs databaseMigrations to Event log. * This subscriber logs databaseMigrations to Event log.
*/ */
class LogDBMigrationSubscriber implements EventSubscriber #[AsDoctrineListener(Events::onMigrationsMigrated)]
#[AsDoctrineListener(Events::onMigrationsMigrating)]
class LogDBMigrationListener
{ {
protected ?string $old_version = null; protected ?string $old_version = null;
protected ?string $new_version = null; protected ?string $new_version = null;
@ -76,12 +78,4 @@ class LogDBMigrationSubscriber implements EventSubscriber
$this->old_version = (string) $aliasResolver->resolveVersionAlias('current'); $this->old_version = (string) $aliasResolver->resolveVersionAlias('current');
} }
} }
public function getSubscribedEvents(): array
{
return [
Events::onMigrationsMigrated,
Events::onMigrationsMigrating,
];
}
} }