Revert "Migrated deprecated doctrine event subsrcibers"

For some very very weird reasoning this cause issues with the ObjectNormalizer, which does not get an an serializer injected anymore.
When the EventLoggerSubscriber is a doctrine subscriber it seems that the serializer service is initialized (as its requested in constructor but not used) and later injected into the object normalizer.
When its an listener, this does not work anymore.
This commit is contained in:
Jan Böhmer 2023-12-07 00:17:27 +01:00
parent d7383539ba
commit b5721dcfd0
3 changed files with 24 additions and 13 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\EventListener\LogSystem\EventLoggerListener: App\EventSubscriber\LogSystem\EventLoggerSubscriber:
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\EventListener\LogSystem\LogDBMigrationListener: App\EventSubscriber\LogSystem\LogDBMigrationSubscriber:
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\EventListener\LogSystem; namespace App\EventSubscriber\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\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; use Doctrine\Common\EventSubscriber;
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,10 +50,7 @@ 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.
*/ */
#[AsDoctrineListener(Events::onFlush)] class EventLoggerSubscriber implements EventSubscriber
#[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
@ -190,6 +187,14 @@ class EventLoggerListener
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\EventListener\LogSystem; namespace App\EventSubscriber\LogSystem;
use App\Entity\LogSystem\DatabaseUpdatedLogEntry; use App\Entity\LogSystem\DatabaseUpdatedLogEntry;
use App\Services\LogSystem\EventLogger; use App\Services\LogSystem\EventLogger;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; use Doctrine\Common\EventSubscriber;
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,9 +32,7 @@ use Doctrine\Migrations\Events;
/** /**
* This subscriber logs databaseMigrations to Event log. * This subscriber logs databaseMigrations to Event log.
*/ */
#[AsDoctrineListener(Events::onMigrationsMigrated)] class LogDBMigrationSubscriber implements EventSubscriber
#[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;
@ -78,4 +76,12 @@ class LogDBMigrationListener
$this->old_version = (string) $aliasResolver->resolveVersionAlias('current'); $this->old_version = (string) $aliasResolver->resolveVersionAlias('current');
} }
} }
public function getSubscribedEvents(): array
{
return [
Events::onMigrationsMigrated,
Events::onMigrationsMigrating,
];
}
} }