fix: update table scheme

This commit is contained in:
Maël Gangloff
2024-07-11 02:29:08 +02:00
parent 9cc575ff09
commit fbb14df399
14 changed files with 711 additions and 56 deletions

View File

@@ -0,0 +1,74 @@
<?php
namespace App\Entity;
use App\Repository\BookmarkDomainListRepository;
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\Id]
#[ORM\Column(length: 36)]
private string $token;
#[ORM\ManyToOne(inversedBy: 'bookmarkDomainLists')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user = null;
/**
* @var Collection<int, Domain>
*/
#[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'ldhname')]
private Collection $domains;
public function __construct()
{
$this->token = Uuid::v4();
$this->domains = new ArrayCollection();
}
public function getToken(): ?string
{
return $this->token;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): static
{
$this->user = $user;
return $this;
}
/**
* @return Collection<int, Domain>
*/
public function getDomains(): Collection
{
return $this->domains;
}
public function addDomain(Domain $domain): static
{
if (!$this->domains->contains($domain)) {
$this->domains->add($domain);
}
return $this;
}
public function removeDomain(Domain $domain): static
{
$this->domains->removeElement($domain);
return $this;
}
}

View File

@@ -18,7 +18,7 @@ class Domain
#[ORM\Column(length: 255)]
private ?string $handle = null;
#[ORM\Column(type: Types::ARRAY)]
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $status = [];
/**

View File

@@ -11,15 +11,15 @@ class DomainEntity
{
#[ORM\Id]
#[ORM\ManyToOne(inversedBy: 'domainEntities')]
#[ORM\JoinColumn(nullable: false, referencedColumnName: 'ldhname')]
#[ORM\JoinColumn(referencedColumnName: 'ldhname', nullable: false)]
private ?Domain $domain = null;
#[ORM\Id]
#[ORM\ManyToOne(inversedBy: 'domainEntities')]
#[ORM\JoinColumn(nullable: false, referencedColumnName: 'handle')]
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
private ?Entity $entity = null;
#[ORM\Column(type: Types::ARRAY)]
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $roles = [];
public function getDomain(): ?Domain

View File

@@ -18,7 +18,7 @@ class Event
#[ORM\Id]
#[ORM\ManyToOne(inversedBy: 'events')]
#[ORM\JoinColumn(nullable: false, referencedColumnName: 'ldhname')]
#[ORM\JoinColumn(referencedColumnName: 'ldhname', nullable: false)]
private ?Domain $domain = null;
public function getAction(): ?string

View File

@@ -11,18 +11,18 @@ class NameserverEntity
{
#[ORM\Id]
#[ORM\ManyToOne(inversedBy: 'nameserverEntities')]
#[ORM\JoinColumn(nullable: false, referencedColumnName: 'handle')]
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
private ?Nameserver $nameserver = null;
#[ORM\Id]
#[ORM\ManyToOne(inversedBy: 'nameserverEntities')]
#[ORM\JoinColumn(nullable: false, referencedColumnName: 'handle')]
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
private ?Entity $entity = null;
#[ORM\Column(type: Types::ARRAY)]
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $roles = [];
#[ORM\Column(type: Types::ARRAY)]
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $status = [];
public function getNameserver(): ?Nameserver

151
src/Entity/User.php Normal file
View File

@@ -0,0 +1,151 @@
<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180)]
private ?string $email = null;
/**
* @var list<string> The user roles
*/
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
/**
* @var Collection<int, BookmarkDomainList>
*/
#[ORM\OneToMany(targetEntity: BookmarkDomainList::class, mappedBy: 'user', orphanRemoval: true)]
private Collection $bookmarkDomainLists;
public function __construct()
{
$this->bookmarkDomainLists = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*
* @return list<string>
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return Collection<int, BookmarkDomainList>
*/
public function getBookmarkDomainLists(): Collection
{
return $this->bookmarkDomainLists;
}
public function addBookmarkDomainList(BookmarkDomainList $bookmarkDomainList): static
{
if (!$this->bookmarkDomainLists->contains($bookmarkDomainList)) {
$this->bookmarkDomainLists->add($bookmarkDomainList);
$bookmarkDomainList->setUser($this);
}
return $this;
}
public function removeBookmarkDomainList(BookmarkDomainList $bookmarkDomainList): static
{
if ($this->bookmarkDomainLists->removeElement($bookmarkDomainList)) {
// set the owning side to null (unless already changed)
if ($bookmarkDomainList->getUser() === $this) {
$bookmarkDomainList->setUser(null);
}
}
return $this;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\BookmarkDomainList;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<BookmarkDomainList>
*/
class BookmarkDomainListRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, BookmarkDomainList::class);
}
// /**
// * @return BookmarkDomainList[] Returns an array of BookmarkDomainList objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('b.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?BookmarkDomainList
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Repository;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
/**
* @extends ServiceEntityRepository<User>
*/
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
/**
* Used to upgrade (rehash) the user's password automatically over time.
*/
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
{
if (!$user instanceof User) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class));
}
$user->setPassword($newHashedPassword);
$this->getEntityManager()->persist($user);
$this->getEntityManager()->flush();
}
// /**
// * @return User[] Returns an array of User objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('u.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?User
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}