<?php
namespace App\Entity;
use App\Repository\DomainHistoryRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=DomainHistoryRepository::class)
* @ORM\Table(name="domain_history")
* @ORM\HasLifecycleCallbacks()
*/
class DomainHistory
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=Domain::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private ?Domain $domain = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private ?User $user = null;
/**
* Action performed (create, update, delete, etc.)
* @ORM\Column(type="string", length=50, nullable=true)
*/
private ?string $action = null;
/**
* Serialized data before changes (for updates/deletes)
* @ORM\Column(type="json", nullable=true)
*/
private ?array $oldData = null;
/**
* Serialized data after changes (for creates/updates)
* @ORM\Column(type="json", nullable=true)
*/
private ?array $newData = null;
/**
* Changes summary (what fields were modified)
* @ORM\Column(type="json", nullable=true)
*/
private ?array $changes = null;
/**
* IP address of the user who made the change
* @ORM\Column(type="string", length=45, nullable=true)
*/
private ?string $ipAddress = null;
/**
* User agent/browser info
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $userAgent = null;
/**
* @ORM\Column(type="datetime")
*/
private \DateTime $createdAt;
/**
* @ORM\Column(type="datetime")
*/
private \DateTime $updatedAt;
public function __construct()
{
$this->createdAt = new \DateTime('now');
$this->updatedAt = new \DateTime('now');
}
public function __toString(): string
{
return sprintf('Domain History #%d - %s', $this->id, $this->action ?? 'unknown');
}
/**
* @ORM\PrePersist
*/
public function onPrePersist(): void
{
$this->createdAt = new \DateTime('now');
$this->updatedAt = new \DateTime('now');
}
/**
* @ORM\PreUpdate
*/
public function onPreUpdate(): void
{
$this->updatedAt = new \DateTime('now');
}
public function getId(): ?int
{
return $this->id;
}
public function getDomain(): ?Domain
{
return $this->domain;
}
public function setDomain(?Domain $domain): self
{
$this->domain = $domain;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getAction(): ?string
{
return $this->action;
}
public function setAction(?string $action): self
{
$this->action = $action;
return $this;
}
public function getOldData(): ?array
{
return $this->oldData;
}
public function setOldData(?array $oldData): self
{
$this->oldData = $oldData;
return $this;
}
public function getNewData(): ?array
{
return $this->newData;
}
public function setNewData(?array $newData): self
{
$this->newData = $newData;
return $this;
}
public function getChanges(): ?array
{
return $this->changes;
}
public function setChanges(?array $changes): self
{
$this->changes = $changes;
return $this;
}
public function getIpAddress(): ?string
{
return $this->ipAddress;
}
public function setIpAddress(?string $ipAddress): self
{
$this->ipAddress = $ipAddress;
return $this;
}
public function getUserAgent(): ?string
{
return $this->userAgent;
}
public function setUserAgent(?string $userAgent): self
{
$this->userAgent = $userAgent;
return $this;
}
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getModifiedAt(): \DateTimeImmutable
{
return \DateTimeImmutable::createFromMutable($this->createdAt);
}
public function setModifiedAt(?\DateTimeImmutable $modifiedAt): self
{
if ($modifiedAt) {
$this->createdAt = \DateTime::createFromImmutable($modifiedAt);
}
return $this;
}
}