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:
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
class TestController
|
||||
{
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Entity;
|
||||
use App\Repository\EntityRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: EntityRepository::class)]
|
||||
@@ -26,10 +27,17 @@ class Entity
|
||||
#[ORM\OneToMany(targetEntity: NameserverEntity::class, mappedBy: 'entity')]
|
||||
private Collection $nameserverEntities;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Event>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Event::class, mappedBy: 'entity', orphanRemoval: true)]
|
||||
private Collection $events;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->domainEntities = new ArrayCollection();
|
||||
$this->nameserverEntities = new ArrayCollection();
|
||||
$this->events = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getHandle(): ?string
|
||||
@@ -103,4 +111,35 @@ class Entity
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Event>
|
||||
*/
|
||||
public function getEvents(): Collection
|
||||
{
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
public function addEvent(Event $event): static
|
||||
{
|
||||
if (!$this->events->contains($event)) {
|
||||
$this->events->add($event);
|
||||
$event->setEntity($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeEvent(Event $event): static
|
||||
{
|
||||
if ($this->events->removeElement($event)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($event->getEntity() === $this) {
|
||||
$event->setEntity(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,46 +3,31 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Config\EventAction;
|
||||
use App\Repository\NameserverEventRepository;
|
||||
use App\Repository\EventRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: NameserverEventRepository::class)]
|
||||
class NameserverEvent
|
||||
#[ORM\Entity(repositoryClass: EventRepository::class)]
|
||||
class Event
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?\DateTimeImmutable $date = null;
|
||||
private ?int $id = 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
|
||||
#[ORM\Column]
|
||||
private ?\DateTimeImmutable $date = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Entity::class, inversedBy: 'events')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
private ?Entity $entity = null;
|
||||
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
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;
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getAction(): ?EventAction
|
||||
@@ -56,4 +41,29 @@ class NameserverEvent
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(\DateTimeImmutable $date): static
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEntity(): ?Entity
|
||||
{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
public function setEntity(?Entity $entity): static
|
||||
{
|
||||
$this->entity = $entity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,16 +28,9 @@ 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
|
||||
@@ -109,34 +102,4 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,39 +2,39 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\NameserverEvent;
|
||||
use App\Entity\Event;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<NameserverEvent>
|
||||
* @extends ServiceEntityRepository<Event>
|
||||
*/
|
||||
class NameserverEventRepository extends ServiceEntityRepository
|
||||
class EventRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, NameserverEvent::class);
|
||||
parent::__construct($registry, Event::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return NameserverEvent[] Returns an array of NameserverEvent objects
|
||||
// * @return Event[] Returns an array of Event objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('n')
|
||||
// ->andWhere('n.exampleField = :val')
|
||||
// return $this->createQueryBuilder('e')
|
||||
// ->andWhere('e.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('n.id', 'ASC')
|
||||
// ->orderBy('e.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?NameserverEvent
|
||||
// public function findOneBySomeField($value): ?Event
|
||||
// {
|
||||
// return $this->createQueryBuilder('n')
|
||||
// ->andWhere('n.exampleField = :val')
|
||||
// return $this->createQueryBuilder('e')
|
||||
// ->andWhere('e.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
Reference in New Issue
Block a user