Skip to content

Commit

Permalink
Merge pull request #100 from indjeto/v1.0
Browse files Browse the repository at this point in the history
Migrate doctrine mappings from xml to php attributes
  • Loading branch information
indjeto authored Feb 2, 2024
2 parents a67af1f + 72c391b commit 754786a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 42 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"require": {
"php": ">=8.0",
"doctrine/dbal": "^2.9|^3.1.4",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/orm": "^2.6",
"doctrine/doctrine-bundle": "^2.9",
"doctrine/orm": "^2.9",
"symfony/security-bundle": "^5.4|^6.0",
"symfony/framework-bundle": "^5.4|^6.0"
},
Expand Down
3 changes: 1 addition & 2 deletions src/DataDogAuditBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ public function build(ContainerBuilder $container): void
parent::build($container);

if (class_exists(DoctrineOrmMappingsPass::class)) {
$namespaces = [__DIR__.'/Resources/config/doctrine' => 'DataDog\\AuditBundle\\Entity'];
$container->addCompilerPass(
DoctrineOrmMappingsPass::createXmlMappingDriver($namespaces)
DoctrineOrmMappingsPass::createAttributeMappingDriver(['DataDog\\AuditBundle\\Entity'], [__DIR__.'/Entity'])
);
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/Entity/Association.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@

namespace DataDog\AuditBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'audit_associations')]
#[ORM\Index(columns: ['fk'])]
class Association
{
#[ORM\Column(type: 'bigint', options: ['unsigned' => true])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private ?int $id;

#[ORM\Column(length: 128)]
private string $typ;

#[ORM\Column(length: 128, nullable: true)]
private ?string $tbl;

#[ORM\Column(nullable: true)]
private ?string $label;

private string $fk;
#[ORM\Column(type: 'integer', options: ['unsigned' => true])]
private int $fk;

#[ORM\Column]
private string $class;

public function getId(): ?int
Expand Down Expand Up @@ -43,7 +56,7 @@ public function getLabel(): ?string
return $this->label;
}

public function getFk(): string
public function getFk(): int
{
return $this->fk;
}
Expand Down
18 changes: 18 additions & 0 deletions src/Entity/AuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,40 @@

namespace DataDog\AuditBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'audit_logs')]
#[ORM\Index(columns: ['logged_at'])]
class AuditLog
{
#[ORM\Column(type: 'bigint', options: ['unsigned' => true])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private ?int $id;

#[ORM\Column(length: 12)]
private string $action;

#[ORM\Column(length: 128)]
private string $tbl;

#[ORM\OneToOne(targetEntity: Association::class)]
#[ORM\JoinColumn(unique: true, nullable: false)]
private Association $source;

#[ORM\OneToOne(targetEntity: Association::class)]
#[ORM\JoinColumn(unique: true)]
private ?Association $target;

#[ORM\OneToOne(targetEntity: Association::class)]
#[ORM\JoinColumn(unique: true)]
private ?Association $blame;

#[ORM\Column(type: 'json', nullable: true)]
private ?array $diff;

#[ORM\Column(name: 'logged_at', type: 'datetime')]
private \DateTimeInterface $loggedAt;

public function getId(): ?int
Expand Down
16 changes: 0 additions & 16 deletions src/Resources/config/doctrine/Association.orm.xml

This file was deleted.

20 changes: 0 additions & 20 deletions src/Resources/config/doctrine/AuditLog.orm.xml

This file was deleted.

0 comments on commit 754786a

Please sign in to comment.