Moved deprecated doctrine subscribers to doctrine event listeners

This commit is contained in:
Jan Böhmer 2024-06-21 23:41:22 +02:00
parent 8ce93a028a
commit 43a68b96ae
3 changed files with 12 additions and 22 deletions

View file

@ -76,18 +76,12 @@ 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)%'
$save_removed_data: '%env(bool:HISTORY_SAVE_REMOVED_DATA)%' $save_removed_data: '%env(bool:HISTORY_SAVE_REMOVED_DATA)%'
$save_new_data: '%env(bool:HISTORY_SAVE_NEW_DATA)%' $save_new_data: '%env(bool:HISTORY_SAVE_NEW_DATA)%'
tags:
- { name: 'doctrine.event_subscriber' }
App\EventSubscriber\LogSystem\LogDBMigrationSubscriber:
tags:
- { name: 'doctrine.event_subscriber' }
App\Form\AttachmentFormType: App\Form\AttachmentFormType:
arguments: arguments:

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(event: Events::onFlush)]
#[AsDoctrineListener(event: Events::postPersist)]
#[AsDoctrineListener(event: 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,15 +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
{ {
$log = new ElementDeletedLogEntry($entity); $log = new ElementDeletedLogEntry($entity);

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(event: Events::onMigrationsMigrated)]
#[AsDoctrineListener(event: Events::onMigrationsMigrating)]
class LogDBMigrationListener
{ {
protected ?string $old_version = null; protected ?string $old_version = null;
protected ?string $new_version = null; protected ?string $new_version = null;