Ported UserRenameEvent entity and repo.

This commit is contained in:
Alexey Skobkin 2023-03-12 21:11:27 +03:00
parent 4f37cb9782
commit 528099baa9
No known key found for this signature in database
GPG Key ID: 5D5CEF6F221278E7
4 changed files with 90 additions and 89 deletions

View File

@ -1,75 +0,0 @@
<?php
namespace src\PointToolsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use src\PointToolsBundle\Entity\User;
/**
* @ORM\Table(name="rename_log", schema="users", indexes={
* @ORM\Index(name="idx_rename_log_date", columns={"date"}),
* @ORM\Index(name="idx_rename_log_old_login", columns={"old_login"})
* })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\UserRenameEventRepository", readOnly=true)
*/
class UserRenameEvent
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", nullable=false, onDelete="CASCADE")
*/
private $user;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* @var string
*
* @ORM\Column(name="old_login", type="text")
*/
private $oldLogin;
public function __construct(User $user, string $old)
{
$this->user = $user;
$this->oldLogin = $old;
$this->date = new \DateTime();
}
public function getId(): int
{
return $this->id;
}
public function getDate(): \DateTime
{
return $this->date;
}
public function getUser(): User
{
return $this->user;
}
public function getOldLogin(): string
{
return $this->oldLogin;
}
}

View File

@ -1,14 +0,0 @@
<?php
namespace src\PointToolsBundle\Repository;
use Doctrine\ORM\EntityRepository;
use src\PointToolsBundle\Entity\UserRenameEvent;
class UserRenameEventRepository extends EntityRepository
{
public function add(UserRenameEvent $event)
{
$this->getEntityManager()->persist($event);
}
}

View File

@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\UserRenameEventRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: UserRenameEventRepository::class, readOnly: true)]
#[ORM\Table(name: 'rename_log', schema: 'users')]
class UserRenameEvent
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(name: 'id', type: 'integer')]
private ?int $id;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'user_id', nullable: false, onDelete: 'CASCADE')]
private User $user;
#[ORM\Column(name: 'date', type: 'datetime')]
private \DateTime $date;
#[ORM\Column(name: 'old_login', type: 'text')]
private string $oldLogin;
public function __construct(User $user, string $old)
{
$this->user = $user;
$this->oldLogin = $old;
$this->date = new \DateTime();
}
public function getId(): int
{
return $this->id;
}
public function getDate(): \DateTime
{
return $this->date;
}
public function getUser(): User
{
return $this->user;
}
public function getOldLogin(): string
{
return $this->oldLogin;
}
}

View File

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\UserRenameEvent;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<UserRenameEvent>
*
* @method UserRenameEvent|null find($id, $lockMode = null, $lockVersion = null)
* @method UserRenameEvent|null findOneBy(array $criteria, array $orderBy = null)
* @method UserRenameEvent[] findAll()
* @method UserRenameEvent[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class UserRenameEventRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, UserRenameEvent::class);
}
public function save(UserRenameEvent $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
}