mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: update database relation
This commit is contained in:
8
src/Controller/TestController.php
Normal file
8
src/Controller/TestController.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
class TestController
|
||||
{
|
||||
|
||||
}
|
||||
@@ -15,14 +15,14 @@ class BookmarkDomainList
|
||||
#[ORM\Column(length: 36)]
|
||||
private string $token;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'bookmarkDomainLists')]
|
||||
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'bookmarkDomainLists')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $user = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Domain>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'ldhname')]
|
||||
#[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'handle')]
|
||||
private Collection $domains;
|
||||
|
||||
public function __construct()
|
||||
|
||||
@@ -14,15 +14,16 @@ class Domain
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $ldhname = null;
|
||||
private ?string $ldhName = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $handle = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Event>
|
||||
* @var Collection<int, DomainEvent>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Event::class, mappedBy: 'domain', orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: DomainEvent::class, mappedBy: 'domain', orphanRemoval: true)]
|
||||
private Collection $events;
|
||||
|
||||
/**
|
||||
@@ -37,20 +38,27 @@ class Domain
|
||||
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainStatus::class)]
|
||||
private array $status = [];
|
||||
|
||||
/**
|
||||
* @var Collection<int, Nameserver>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Nameserver::class, mappedBy: 'handle')]
|
||||
private Collection $nameservers;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->events = new ArrayCollection();
|
||||
$this->domainEntities = new ArrayCollection();
|
||||
$this->nameservers = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getLdhname(): ?string
|
||||
public function getLdhName(): ?string
|
||||
{
|
||||
return $this->ldhname;
|
||||
return $this->ldhName;
|
||||
}
|
||||
|
||||
public function setLdhname(string $ldhname): static
|
||||
public function setLdhName(string $ldhName): static
|
||||
{
|
||||
$this->ldhname = $ldhname;
|
||||
$this->ldhName = $ldhName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -68,14 +76,14 @@ class Domain
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Event>
|
||||
* @return Collection<int, DomainEvent>
|
||||
*/
|
||||
public function getEvents(): Collection
|
||||
{
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
public function addEvent(Event $event): static
|
||||
public function addEvent(DomainEvent $event): static
|
||||
{
|
||||
if (!$this->events->contains($event)) {
|
||||
$this->events->add($event);
|
||||
@@ -85,7 +93,7 @@ class Domain
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeEvent(Event $event): static
|
||||
public function removeEvent(DomainEvent $event): static
|
||||
{
|
||||
if ($this->events->removeElement($event)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
@@ -153,4 +161,28 @@ class Domain
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Nameserver>
|
||||
*/
|
||||
public function getNameservers(): Collection
|
||||
{
|
||||
return $this->nameservers;
|
||||
}
|
||||
|
||||
public function addNameserver(Nameserver $nameserver): static
|
||||
{
|
||||
if (!$this->nameservers->contains($nameserver)) {
|
||||
$this->nameservers->add($nameserver);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeNameserver(Nameserver $nameserver): static
|
||||
{
|
||||
$this->nameservers->removeElement($nameserver);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
class DomainEntity
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(inversedBy: 'domainEntities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'ldhname', nullable: false)]
|
||||
#[ORM\ManyToOne(targetEntity: Domain::class, inversedBy: 'domainEntities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
private ?Domain $domain = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(inversedBy: 'domainEntities')]
|
||||
#[ORM\ManyToOne(targetEntity: Entity::class, inversedBy: 'domainEntities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
private ?Entity $entity = null;
|
||||
|
||||
|
||||
@@ -2,31 +2,32 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\EventRepository;
|
||||
use App\Config\EventAction;
|
||||
use App\Repository\DomainEventRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: EventRepository::class)]
|
||||
class Event
|
||||
#[ORM\Entity(repositoryClass: DomainEventRepository::class)]
|
||||
class DomainEvent
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $action = null;
|
||||
#[ORM\Column(enumType: EventAction::class)]
|
||||
private ?EventAction $action = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
private ?\DateTimeImmutable $date = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(inversedBy: 'events')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'ldhname', nullable: false)]
|
||||
#[ORM\ManyToOne(targetEntity: Domain::class, inversedBy: 'events')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
private ?Domain $domain = null;
|
||||
|
||||
public function getAction(): ?string
|
||||
public function getAction(): ?EventAction
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function setAction(string $action): static
|
||||
public function setAction(EventAction $action): static
|
||||
{
|
||||
$this->action = $action;
|
||||
|
||||
@@ -17,7 +17,7 @@ class Nameserver
|
||||
private ?string $handle = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $ldhname = null;
|
||||
private ?string $ldhName = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, NameserverEntity>
|
||||
@@ -28,9 +28,16 @@ class Nameserver
|
||||
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainStatus::class)]
|
||||
private array $status = [];
|
||||
|
||||
/**
|
||||
* @var Collection<int, NameserverEvent>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: NameserverEvent::class, mappedBy: 'nameserver', orphanRemoval: true)]
|
||||
private Collection $nameserverEvents;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->nameserverEntities = new ArrayCollection();
|
||||
$this->nameserverEvents = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getHandle(): ?string
|
||||
@@ -45,14 +52,14 @@ class Nameserver
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLdhname(): ?string
|
||||
public function getLdhName(): ?string
|
||||
{
|
||||
return $this->ldhname;
|
||||
return $this->ldhName;
|
||||
}
|
||||
|
||||
public function setLdhname(string $ldhname): static
|
||||
public function setLdhName(string $ldhName): static
|
||||
{
|
||||
$this->ldhname = $ldhname;
|
||||
$this->ldhName = $ldhName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -102,4 +109,34 @@ class Nameserver
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, NameserverEvent>
|
||||
*/
|
||||
public function getNameserverEvents(): Collection
|
||||
{
|
||||
return $this->nameserverEvents;
|
||||
}
|
||||
|
||||
public function addNameserverEvent(NameserverEvent $nameserverEvent): static
|
||||
{
|
||||
if (!$this->nameserverEvents->contains($nameserverEvent)) {
|
||||
$this->nameserverEvents->add($nameserverEvent);
|
||||
$nameserverEvent->setNameserver($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeNameserverEvent(NameserverEvent $nameserverEvent): static
|
||||
{
|
||||
if ($this->nameserverEvents->removeElement($nameserverEvent)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($nameserverEvent->getNameserver() === $this) {
|
||||
$nameserverEvent->setNameserver(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
class NameserverEntity
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(inversedBy: 'nameserverEntities')]
|
||||
#[ORM\ManyToOne(targetEntity: Nameserver::class, inversedBy: 'nameserverEntities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
private ?Nameserver $nameserver = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(inversedBy: 'nameserverEntities')]
|
||||
#[ORM\ManyToOne(targetEntity: Entity::class, inversedBy: 'nameserverEntities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
private ?Entity $entity = null;
|
||||
|
||||
|
||||
59
src/Entity/NameserverEvent.php
Normal file
59
src/Entity/NameserverEvent.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Config\EventAction;
|
||||
use App\Repository\NameserverEventRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: NameserverEventRepository::class)]
|
||||
class NameserverEvent
|
||||
{
|
||||
#[ORM\Column]
|
||||
private ?\DateTimeImmutable $date = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(inversedBy: 'nameserverEvents')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
private ?Nameserver $nameserver = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(enumType: EventAction::class)]
|
||||
private ?EventAction $action = null;
|
||||
|
||||
public function getDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(\DateTimeImmutable $date): static
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameserver(): ?Nameserver
|
||||
{
|
||||
return $this->nameserver;
|
||||
}
|
||||
|
||||
public function setNameserver(?Nameserver $nameserver): static
|
||||
{
|
||||
$this->nameserver = $nameserver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAction(): ?EventAction
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function setAction(EventAction $action): static
|
||||
{
|
||||
$this->action = $action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,13 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
private ?string $email = null;
|
||||
|
||||
/**
|
||||
* @var list<string> The user roles
|
||||
* @var array The user roles
|
||||
*/
|
||||
#[ORM\Column]
|
||||
private array $roles = [];
|
||||
|
||||
/**
|
||||
* @var string The hashed password
|
||||
* @var string|null The hashed password
|
||||
*/
|
||||
#[ORM\Column]
|
||||
private ?string $password = null;
|
||||
@@ -86,7 +86,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $roles
|
||||
* @param array $roles
|
||||
* @return User
|
||||
*/
|
||||
public function setRoles(array $roles): static
|
||||
{
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Event;
|
||||
use App\Entity\DomainEvent;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Event>
|
||||
* @extends ServiceEntityRepository<DomainEvent>
|
||||
*/
|
||||
class EventRepository extends ServiceEntityRepository
|
||||
class DomainEventRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Event::class);
|
||||
parent::__construct($registry, DomainEvent::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Event[] Returns an array of Event objects
|
||||
// * @return DomainEvent[] Returns an array of DomainEvent objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
@@ -31,7 +31,7 @@ class EventRepository extends ServiceEntityRepository
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Event
|
||||
// public function findOneBySomeField($value): ?DomainEvent
|
||||
// {
|
||||
// return $this->createQueryBuilder('e')
|
||||
// ->andWhere('e.exampleField = :val')
|
||||
43
src/Repository/NameserverEventRepository.php
Normal file
43
src/Repository/NameserverEventRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\NameserverEvent;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<NameserverEvent>
|
||||
*/
|
||||
class NameserverEventRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, NameserverEvent::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return NameserverEvent[] Returns an array of NameserverEvent objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('n')
|
||||
// ->andWhere('n.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('n.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?NameserverEvent
|
||||
// {
|
||||
// return $this->createQueryBuilder('n')
|
||||
// ->andWhere('n.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user