Skip to content

Commit

Permalink
Resolve doctrine/dbal v3 compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
natewiebe13 committed Dec 15, 2021
1 parent c1d0505 commit 519d157
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/DataDog/AuditBundle/EventSubscriber/AuditSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 519d157

Please sign in to comment.