Skip to content

Commit

Permalink
Merge pull request #83 from natewiebe13/symfony-6
Browse files Browse the repository at this point in the history
WIP: Symfony 6
  • Loading branch information
l3pp4rd authored Dec 28, 2021
2 parents d80a751 + 519d157 commit c6601cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
35 changes: 12 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,48 @@
"type": "symfony-bundle",
"description": "Audit bundle for symfony2 and doctrine orm, logs any database change",
"keywords": ["audit", "log", "symfony2", "bundle", "doctrine", "orm"],
"homepage": "http://github.com/DATA-DOG/DataDogAuditBundle",
"homepage": "https://github.com/DATA-DOG/DataDogAuditBundle",
"license": "MIT",

"authors": [
{
"name": "DataDog Team",
"homepage": "http://datadog.lt"
"homepage": "https://datadog.lt"
},
{
"name": "Symfony2 Community",
"homepage": "http://github.com/DATA-DOG/DataDogAuditBundle/contributors"
"homepage": "https://github.com/DATA-DOG/DataDogAuditBundle/contributors"
}
],

"require": {
"php": ">=5.4.0",
"symfony/framework-bundle": "^2.6|^3.0|^4.0|^5.0",
"doctrine/orm": "^2.4"
"php": ">=7.4",
"doctrine/dbal": "^3.1.4",
"doctrine/orm": "^2.6",
"symfony/framework-bundle": "^4.4|^5.4|^6.0"
},

"require-dev": {
"php": ">=5.6.0",
"ext-pdo": "*",
"ext-pdo_sqlite": "*",

"symfony/symfony": "^3.0|^4.0|^5.0",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-fixtures-bundle": "^2.2",
"sensio/framework-extra-bundle": "^3.0.2",
"data-dog/pager-bundle": "^0.2",
"doctrine/doctrine-bundle": "^2.5",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"knplabs/knp-menu-bundle": "^2.0",
"knplabs/knp-time-bundle": "^1.3",
"data-dog/pager-bundle": "^0.2",

"phpunit/phpunit": "~4.7.0"
"sensio/framework-extra-bundle": "^5.6",
"symfony/symfony": "^4.4|^5.4|^6.0"
},

"autoload": {
"psr-4": {
"DataDog\\AuditBundle\\": "src/DataDog/AuditBundle"
}
},

"autoload-dev": {
"psr-4": {
"": "example/src/"
}
},

"archive": {
"exclude": ["vendor", "tests", "*phpunit.xml", ".travis.yml", "example", "Makefile", "screenshots"]
},

"extra": {
"branch-alias": {
"dev-master": "0.1.x-dev"
Expand Down
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 c6601cf

Please sign in to comment.