src/Entity/DomainHistory.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DomainHistoryRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity(repositoryClass=DomainHistoryRepository::class)
  7.  * @ORM\Table(name="domain_history")
  8.  * @ORM\HasLifecycleCallbacks()
  9.  */
  10. class DomainHistory
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private ?int $id null;
  18.     /**
  19.      * @ORM\ManyToOne(targetEntity=Domain::class)
  20.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  21.      */
  22.     private ?Domain $domain null;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity=User::class)
  25.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  26.      */
  27.     private ?User $user null;
  28.     /**
  29.      * Action performed (create, update, delete, etc.)
  30.      * @ORM\Column(type="string", length=50, nullable=true)
  31.      */
  32.     private ?string $action null;
  33.     /**
  34.      * Serialized data before changes (for updates/deletes)
  35.      * @ORM\Column(type="json", nullable=true)
  36.      */
  37.     private ?array $oldData null;
  38.     /**
  39.      * Serialized data after changes (for creates/updates)
  40.      * @ORM\Column(type="json", nullable=true)
  41.      */
  42.     private ?array $newData null;
  43.     /**
  44.      * Changes summary (what fields were modified)
  45.      * @ORM\Column(type="json", nullable=true)
  46.      */
  47.     private ?array $changes null;
  48.     /**
  49.      * IP address of the user who made the change
  50.      * @ORM\Column(type="string", length=45, nullable=true)
  51.      */
  52.     private ?string $ipAddress null;
  53.     /**
  54.      * User agent/browser info
  55.      * @ORM\Column(type="string", length=255, nullable=true)
  56.      */
  57.     private ?string $userAgent null;
  58.     /**
  59.      * @ORM\Column(type="datetime")
  60.      */
  61.     private \DateTime $createdAt;
  62.     /**
  63.      * @ORM\Column(type="datetime")
  64.      */
  65.     private \DateTime $updatedAt;
  66.     public function __construct()
  67.     {
  68.         $this->createdAt = new \DateTime('now');
  69.         $this->updatedAt = new \DateTime('now');
  70.     }
  71.     public function __toString(): string
  72.     {
  73.         return sprintf('Domain History #%d - %s'$this->id$this->action ?? 'unknown');
  74.     }
  75.     /**
  76.      * @ORM\PrePersist
  77.      */
  78.     public function onPrePersist(): void
  79.     {
  80.         $this->createdAt = new \DateTime('now');
  81.         $this->updatedAt = new \DateTime('now');
  82.     }
  83.     /**
  84.      * @ORM\PreUpdate
  85.      */
  86.     public function onPreUpdate(): void
  87.     {
  88.         $this->updatedAt = new \DateTime('now');
  89.     }
  90.     public function getId(): ?int
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function getDomain(): ?Domain
  95.     {
  96.         return $this->domain;
  97.     }
  98.     public function setDomain(?Domain $domain): self
  99.     {
  100.         $this->domain $domain;
  101.         return $this;
  102.     }
  103.     public function getUser(): ?User
  104.     {
  105.         return $this->user;
  106.     }
  107.     public function setUser(?User $user): self
  108.     {
  109.         $this->user $user;
  110.         return $this;
  111.     }
  112.     public function getAction(): ?string
  113.     {
  114.         return $this->action;
  115.     }
  116.     public function setAction(?string $action): self
  117.     {
  118.         $this->action $action;
  119.         return $this;
  120.     }
  121.     public function getOldData(): ?array
  122.     {
  123.         return $this->oldData;
  124.     }
  125.     public function setOldData(?array $oldData): self
  126.     {
  127.         $this->oldData $oldData;
  128.         return $this;
  129.     }
  130.     public function getNewData(): ?array
  131.     {
  132.         return $this->newData;
  133.     }
  134.     public function setNewData(?array $newData): self
  135.     {
  136.         $this->newData $newData;
  137.         return $this;
  138.     }
  139.     public function getChanges(): ?array
  140.     {
  141.         return $this->changes;
  142.     }
  143.     public function setChanges(?array $changes): self
  144.     {
  145.         $this->changes $changes;
  146.         return $this;
  147.     }
  148.     public function getIpAddress(): ?string
  149.     {
  150.         return $this->ipAddress;
  151.     }
  152.     public function setIpAddress(?string $ipAddress): self
  153.     {
  154.         $this->ipAddress $ipAddress;
  155.         return $this;
  156.     }
  157.     public function getUserAgent(): ?string
  158.     {
  159.         return $this->userAgent;
  160.     }
  161.     public function setUserAgent(?string $userAgent): self
  162.     {
  163.         $this->userAgent $userAgent;
  164.         return $this;
  165.     }
  166.     public function getCreatedAt(): \DateTime
  167.     {
  168.         return $this->createdAt;
  169.     }
  170.     public function setCreatedAt(\DateTime $createdAt): self
  171.     {
  172.         $this->createdAt $createdAt;
  173.         return $this;
  174.     }
  175.     public function getUpdatedAt(): \DateTime
  176.     {
  177.         return $this->updatedAt;
  178.     }
  179.     public function setUpdatedAt(\DateTime $updatedAt): self
  180.     {
  181.         $this->updatedAt $updatedAt;
  182.         return $this;
  183.     }
  184.     public function getModifiedAt(): \DateTimeImmutable
  185.     {
  186.         return \DateTimeImmutable::createFromMutable($this->createdAt);
  187.     }
  188.     public function setModifiedAt(?\DateTimeImmutable $modifiedAt): self
  189.     {
  190.         if ($modifiedAt) {
  191.             $this->createdAt \DateTime::createFromImmutable($modifiedAt);
  192.         }
  193.         return $this;
  194.     }
  195. }