From 519d1574c44e5b889e509bd66c2200f400fb5dce Mon Sep 17 00:00:00 2001 From: Nate Wiebe Date: Wed, 15 Dec 2021 16:27:51 -0500 Subject: [PATCH] Resolve doctrine/dbal v3 compatibility issues --- .../EventSubscriber/AuditSubscriber.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php b/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php index 216fccf..6c48b01 100644 --- a/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php +++ b/src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php @@ -11,6 +11,7 @@ use Symfony\Component\Security\Core\Role\SwitchUserRole; use Symfony\Component\Security\Core\User\UserInterface; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Logging\LoggerChain; use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\Common\EventSubscriber; @@ -122,15 +123,20 @@ public function onFlush(OnFlushEventArgs $args) $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); + $loggers = [ + new AuditLogger(function () use($em) { + $this->flush($em); + }) + ]; + // extend the sql logger $this->old = $em->getConnection()->getConfiguration()->getSQLLogger(); - $new = new LoggerChain(); - $new->addLogger(new AuditLogger(function () use($em) { - $this->flush($em); - })); + if ($this->old instanceof SQLLogger) { - $new->addLogger($this->old); + $loggers[] = $this->old; } + + $new = new LoggerChain($loggers); $em->getConnection()->getConfiguration()->setSQLLogger($new); foreach ($uow->getScheduledEntityUpdates() as $entity) { @@ -348,7 +354,7 @@ protected function audit(EntityManager $em, array $data) if (isset($meta->fieldMappings[$name]['type'])) { $typ = $meta->fieldMappings[$name]['type']; } else { - $typ = Type::getType(Type::BIGINT); // relation + $typ = Type::getType(Types::BIGINT); // relation } // @TODO: this check may not be necessary, simply it ensures that empty values are nulled if (in_array($name, ['source', 'target', 'blame']) && $data[$name] === false) { @@ -464,7 +470,7 @@ protected function value(EntityManager $em, Type $type, $value) $platform = $em->getConnection()->getDatabasePlatform(); switch ($type->getName()) { - case Type::BOOLEAN: + case Types::BOOLEAN: return $type->convertToPHPValue($value, $platform); // json supports boolean values default: return $type->convertToDatabaseValue($value, $platform);