diff --git a/migrations/Version20240711162405.php b/migrations/Version20240711201708.php similarity index 58% rename from migrations/Version20240711162405.php rename to migrations/Version20240711201708.php index c2f2f15..9291b28 100644 --- a/migrations/Version20240711162405.php +++ b/migrations/Version20240711201708.php @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20240711162405 extends AbstractMigration +final class Version20240711201708 extends AbstractMigration { public function getDescription(): string { @@ -20,21 +20,27 @@ final class Version20240711162405 extends AbstractMigration public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TABLE bookmark_domain_list (token VARCHAR(36) NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY(token), CONSTRAINT FK_F05EDCECA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); - $this->addSql('CREATE INDEX IDX_F05EDCECA76ED395 ON bookmark_domain_list (user_id)'); + $this->addSql('CREATE TABLE bookmark_list (token VARCHAR(36) NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY(token), CONSTRAINT FK_A650C0C4A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_A650C0C4A76ED395 ON bookmark_list (user_id)'); + $this->addSql('CREATE TABLE bookmark_lists_domains (bookmark_token VARCHAR(36) NOT NULL, domain_ldh_name VARCHAR(255) NOT NULL, domain_handle VARCHAR(255) NOT NULL, PRIMARY KEY(bookmark_token, domain_ldh_name, domain_handle), CONSTRAINT FK_C12B6400D0B0A7FC FOREIGN KEY (bookmark_token) REFERENCES bookmark_list (token) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_C12B6400AF923913FEE32C10 FOREIGN KEY (domain_ldh_name, domain_handle) REFERENCES domain (ldh_name, handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_C12B6400D0B0A7FC ON bookmark_lists_domains (bookmark_token)'); + $this->addSql('CREATE INDEX IDX_C12B6400AF923913FEE32C10 ON bookmark_lists_domains (domain_ldh_name, domain_handle)'); $this->addSql('CREATE TABLE domain (ldh_name VARCHAR(255) NOT NULL, handle VARCHAR(255) NOT NULL, whois_status VARCHAR(255) NOT NULL, status CLOB NOT NULL --(DC2Type:simple_array) , PRIMARY KEY(ldh_name, handle))'); + $this->addSql('CREATE TABLE domain_nameservers (domain_handle VARCHAR(255) NOT NULL, domain_ldh_name VARCHAR(255) NOT NULL, nameserver_handle VARCHAR(255) NOT NULL, PRIMARY KEY(domain_handle, domain_ldh_name, nameserver_handle), CONSTRAINT FK_B6E6B63AFEE32C10AF923913 FOREIGN KEY (domain_handle, domain_ldh_name) REFERENCES domain (handle, ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_B6E6B63A3DC1CB05 FOREIGN KEY (nameserver_handle) REFERENCES nameserver (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_B6E6B63AFEE32C10AF923913 ON domain_nameservers (domain_handle, domain_ldh_name)'); + $this->addSql('CREATE INDEX IDX_B6E6B63A3DC1CB05 ON domain_nameservers (nameserver_handle)'); $this->addSql('CREATE TABLE domain_entity (domain_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array) , PRIMARY KEY(domain_id, entity_id), CONSTRAINT FK_614B48A1115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (handle) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_614B48A181257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); $this->addSql('CREATE INDEX IDX_614B48A1115F0EE5 ON domain_entity (domain_id)'); $this->addSql('CREATE INDEX IDX_614B48A181257D5D ON domain_entity (entity_id)'); - $this->addSql('CREATE TABLE domain_event ("action" VARCHAR(255) NOT NULL, domain_id VARCHAR(255) NOT NULL, date DATE NOT NULL --(DC2Type:date_immutable) - , PRIMARY KEY("action", domain_id), CONSTRAINT FK_E8D52271115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE TABLE domain_event (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, domain_id VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, date DATETIME NOT NULL --(DC2Type:datetime_immutable) + , CONSTRAINT FK_E8D52271115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); $this->addSql('CREATE INDEX IDX_E8D52271115F0EE5 ON domain_event (domain_id)'); $this->addSql('CREATE TABLE entity (handle VARCHAR(255) NOT NULL, PRIMARY KEY(handle))'); - $this->addSql('CREATE TABLE event (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, entity_id VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, date DATETIME NOT NULL --(DC2Type:datetime_immutable) - , CONSTRAINT FK_3BAE0AA781257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); - $this->addSql('CREATE INDEX IDX_3BAE0AA781257D5D ON event (entity_id)'); + $this->addSql('CREATE TABLE entity_event (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, entity_id VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, date DATETIME NOT NULL --(DC2Type:datetime_immutable) + , CONSTRAINT FK_975A3F5E81257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_975A3F5E81257D5D ON entity_event (entity_id)'); $this->addSql('CREATE TABLE nameserver (handle VARCHAR(255) NOT NULL, ldh_name VARCHAR(255) NOT NULL, status CLOB NOT NULL --(DC2Type:simple_array) , PRIMARY KEY(handle))'); $this->addSql('CREATE TABLE nameserver_entity (nameserver_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array) @@ -57,12 +63,14 @@ final class Version20240711162405 extends AbstractMigration public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE bookmark_domain_list'); + $this->addSql('DROP TABLE bookmark_list'); + $this->addSql('DROP TABLE bookmark_lists_domains'); $this->addSql('DROP TABLE domain'); + $this->addSql('DROP TABLE domain_nameservers'); $this->addSql('DROP TABLE domain_entity'); $this->addSql('DROP TABLE domain_event'); $this->addSql('DROP TABLE entity'); - $this->addSql('DROP TABLE event'); + $this->addSql('DROP TABLE entity_event'); $this->addSql('DROP TABLE nameserver'); $this->addSql('DROP TABLE nameserver_entity'); $this->addSql('DROP TABLE user'); diff --git a/src/Controller/TestController.php b/src/Controller/TestController.php new file mode 100644 index 0000000..e69de29 diff --git a/src/Entity/BookmarkDomainList.php b/src/Entity/BookmarkList.php similarity index 72% rename from src/Entity/BookmarkDomainList.php rename to src/Entity/BookmarkList.php index 9bd3eeb..7910b21 100644 --- a/src/Entity/BookmarkDomainList.php +++ b/src/Entity/BookmarkList.php @@ -2,14 +2,14 @@ namespace App\Entity; -use App\Repository\BookmarkDomainListRepository; +use App\Repository\BookmarkListRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Uid\Uuid; -#[ORM\Entity(repositoryClass: BookmarkDomainListRepository::class)] -class BookmarkDomainList +#[ORM\Entity(repositoryClass: BookmarkListRepository::class)] +class BookmarkList { #[ORM\Id] #[ORM\Column(length: 36)] @@ -22,7 +22,10 @@ class BookmarkDomainList /** * @var Collection */ - #[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'handle')] + #[ORM\ManyToMany(targetEntity: Domain::class, inversedBy: 'bookmarkLists')] + #[ORM\JoinTable(name: 'bookmark_lists_domains', + joinColumns: [new ORM\JoinColumn(name: 'bookmark_token', referencedColumnName: 'token')], + inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name'), new ORM\JoinColumn(name: 'domain_handle', referencedColumnName: 'handle')])] private Collection $domains; public function __construct() diff --git a/src/Entity/Domain.php b/src/Entity/Domain.php index 4607392..55955cc 100644 --- a/src/Entity/Domain.php +++ b/src/Entity/Domain.php @@ -38,16 +38,27 @@ class Domain #[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainStatus::class)] private array $status = []; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: BookmarkList::class, mappedBy: 'domains')] + private Collection $bookmarkLists; + /** * @var Collection */ - #[ORM\ManyToMany(targetEntity: Nameserver::class, mappedBy: 'handle')] + #[ORM\ManyToMany(targetEntity: Nameserver::class, inversedBy: 'domains')] + #[ORM\JoinTable(name: 'domain_nameservers', + joinColumns: [new ORM\JoinColumn(name: 'domain_handle', referencedColumnName: 'handle'), new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name')], + inverseJoinColumns: [new ORM\JoinColumn(name: 'nameserver_handle', referencedColumnName: 'handle')] + )] private Collection $nameservers; public function __construct() { $this->events = new ArrayCollection(); $this->domainEntities = new ArrayCollection(); + $this->bookmarkLists = new ArrayCollection(); $this->nameservers = new ArrayCollection(); } @@ -162,6 +173,33 @@ class Domain return $this; } + /** + * @return Collection + */ + public function getBookmarkLists(): Collection + { + return $this->bookmarkLists; + } + + public function addBookmarkList(BookmarkList $bookmarkList): static + { + if (!$this->bookmarkLists->contains($bookmarkList)) { + $this->bookmarkLists->add($bookmarkList); + $bookmarkList->addDomain($this); + } + + return $this; + } + + public function removeBookmarkList(BookmarkList $bookmarkList): static + { + if ($this->bookmarkLists->removeElement($bookmarkList)) { + $bookmarkList->removeDomain($this); + } + + return $this; + } + /** * @return Collection */ diff --git a/src/Entity/DomainEvent.php b/src/Entity/DomainEvent.php index f89d0a6..5a55c6a 100644 --- a/src/Entity/DomainEvent.php +++ b/src/Entity/DomainEvent.php @@ -2,50 +2,16 @@ namespace App\Entity; -use App\Config\EventAction; use App\Repository\DomainEventRepository; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: DomainEventRepository::class)] -class DomainEvent +class DomainEvent extends Event { - #[ORM\Id] - #[ORM\Column(enumType: EventAction::class)] - private ?EventAction $action = null; - - #[ORM\Column(type: Types::DATE_IMMUTABLE)] - private ?\DateTimeImmutable $date = null; - - #[ORM\Id] #[ORM\ManyToOne(targetEntity: Domain::class, inversedBy: 'events')] #[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)] private ?Domain $domain = null; - public function getAction(): ?EventAction - { - return $this->action; - } - - public function setAction(EventAction $action): static - { - $this->action = $action; - - return $this; - } - - public function getDate(): ?\DateTimeImmutable - { - return $this->date; - } - - public function setDate(\DateTimeImmutable $date): static - { - $this->date = $date; - - return $this; - } - public function getDomain(): ?Domain { return $this->domain; diff --git a/src/Entity/EntityEvent.php b/src/Entity/EntityEvent.php new file mode 100644 index 0000000..c9caed0 --- /dev/null +++ b/src/Entity/EntityEvent.php @@ -0,0 +1,29 @@ +entity; + } + + public function setEntity(?Entity $entity): static + { + $this->entity = $entity; + + return $this; + } +} diff --git a/src/Entity/Event.php b/src/Entity/Event.php index 2c16aa5..02f2464 100644 --- a/src/Entity/Event.php +++ b/src/Entity/Event.php @@ -3,10 +3,10 @@ namespace App\Entity; use App\Config\EventAction; -use App\Repository\EventRepository; +use App\Repository\EntityEventRepository; use Doctrine\ORM\Mapping as ORM; -#[ORM\Entity(repositoryClass: EventRepository::class)] +#[ORM\MappedSuperclass] class Event { #[ORM\Id] @@ -20,10 +20,6 @@ class Event #[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 { @@ -54,16 +50,4 @@ class Event return $this; } - public function getEntity(): ?Entity - { - return $this->entity; - } - - public function setEntity(?Entity $entity): static - { - $this->entity = $entity; - - return $this; - } - } diff --git a/src/Entity/Nameserver.php b/src/Entity/Nameserver.php index 8871451..6d8b2f0 100644 --- a/src/Entity/Nameserver.php +++ b/src/Entity/Nameserver.php @@ -28,9 +28,16 @@ class Nameserver #[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainStatus::class)] private array $status = []; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'nameservers')] + private Collection $domains; + public function __construct() { $this->nameserverEntities = new ArrayCollection(); + $this->domains = new ArrayCollection(); } public function getHandle(): ?string @@ -102,4 +109,31 @@ class Nameserver return $this; } + /** + * @return Collection + */ + public function getDomains(): Collection + { + return $this->domains; + } + + public function addDomain(Domain $domain): static + { + if (!$this->domains->contains($domain)) { + $this->domains->add($domain); + $domain->addNameserver($this); + } + + return $this; + } + + public function removeDomain(Domain $domain): static + { + if ($this->domains->removeElement($domain)) { + $domain->removeNameserver($this); + } + + return $this; + } + } diff --git a/src/Entity/User.php b/src/Entity/User.php index 2d4fe38..48b7d7e 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -34,9 +34,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface private ?string $password = null; /** - * @var Collection + * @var Collection */ - #[ORM\OneToMany(targetEntity: BookmarkDomainList::class, mappedBy: 'user', orphanRemoval: true)] + #[ORM\OneToMany(targetEntity: BookmarkList::class, mappedBy: 'user', orphanRemoval: true)] private Collection $bookmarkDomainLists; public function __construct() @@ -121,14 +121,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface } /** - * @return Collection + * @return Collection */ public function getBookmarkDomainLists(): Collection { return $this->bookmarkDomainLists; } - public function addBookmarkDomainList(BookmarkDomainList $bookmarkDomainList): static + public function addBookmarkDomainList(BookmarkList $bookmarkDomainList): static { if (!$this->bookmarkDomainLists->contains($bookmarkDomainList)) { $this->bookmarkDomainLists->add($bookmarkDomainList); @@ -138,7 +138,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } - public function removeBookmarkDomainList(BookmarkDomainList $bookmarkDomainList): static + public function removeBookmarkDomainList(BookmarkList $bookmarkDomainList): static { if ($this->bookmarkDomainLists->removeElement($bookmarkDomainList)) { // set the owning side to null (unless already changed) diff --git a/src/Repository/BookmarkDomainListRepository.php b/src/Repository/BookmarkListRepository.php similarity index 70% rename from src/Repository/BookmarkDomainListRepository.php rename to src/Repository/BookmarkListRepository.php index 0618368..67790d3 100644 --- a/src/Repository/BookmarkDomainListRepository.php +++ b/src/Repository/BookmarkListRepository.php @@ -2,22 +2,22 @@ namespace App\Repository; -use App\Entity\BookmarkDomainList; +use App\Entity\BookmarkList; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; /** - * @extends ServiceEntityRepository + * @extends ServiceEntityRepository */ -class BookmarkDomainListRepository extends ServiceEntityRepository +class BookmarkListRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { - parent::__construct($registry, BookmarkDomainList::class); + parent::__construct($registry, BookmarkList::class); } // /** - // * @return BookmarkDomainList[] Returns an array of BookmarkDomainList objects + // * @return BookmarkList[] Returns an array of BookmarkList objects // */ // public function findByExampleField($value): array // { @@ -31,7 +31,7 @@ class BookmarkDomainListRepository extends ServiceEntityRepository // ; // } - // public function findOneBySomeField($value): ?BookmarkDomainList + // public function findOneBySomeField($value): ?BookmarkList // { // return $this->createQueryBuilder('b') // ->andWhere('b.exampleField = :val') diff --git a/src/Repository/EventRepository.php b/src/Repository/EntityEventRepository.php similarity index 78% rename from src/Repository/EventRepository.php rename to src/Repository/EntityEventRepository.php index ec63e8e..d769998 100644 --- a/src/Repository/EventRepository.php +++ b/src/Repository/EntityEventRepository.php @@ -2,22 +2,23 @@ namespace App\Repository; +use App\Entity\EntityEvent; use App\Entity\Event; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; /** - * @extends ServiceEntityRepository + * @extends ServiceEntityRepository */ -class EventRepository extends ServiceEntityRepository +class EntityEventRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { - parent::__construct($registry, Event::class); + parent::__construct($registry, EntityEvent::class); } // /** - // * @return Event[] Returns an array of Event objects + // * @return EntityEvent[] Returns an array of EntityEvent objects // */ // public function findByExampleField($value): array // {