Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate doctrine mappings from xml to php attributes #100

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading