<?php
namespace App\Entity;
use App\Repository\EntityDeletionRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* Trace légère d'une suppression — plusieurs entités synchronisées hors
* ligne (Absence, Late, Note, Punish, HomeWork, DailyAbsence...) sont des
* hard-deletes (EntityManager::remove()), et chaque endpoint sync()
* codait `deleted_ids` en dur à `[]` : un enregistrement supprimé restait
* donc indéfiniment dans le cache local (Drift) de tout rôle l'ayant déjà
* synchronisé, sauf sur l'appareil de l'auteur de la suppression (épargné
* par la suppression optimiste locale) — constaté à l'usage côté devoirs,
* puis confirmé systémique pour absence/retard/note/sanction.
*
* Une seule table générique (discriminée par [entityType]) plutôt qu'une
* table par entité — même rôle partout (répondre "cet id a disparu depuis
* $since"), pas de raison de dupliquer le schéma cinq fois. $entityId
* n'est PAS une vraie FK (l'entité visée n'existe plus au moment où on lit
* cette trace) — juste l'id brut à renvoyer dans deleted_ids.
*/
#[ORM\Entity(repositoryClass: EntityDeletionRepository::class)]
#[ORM\Index(columns: ['entity_type', 'school_id', 'year_id', 'deleted_at'], name: 'idx_entity_deletion_lookup')]
class EntityDeletion
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
/** 'absence' | 'late' | 'note' | 'punish' | 'homework' | 'daily_absence' */
#[ORM\Column(length: 32)]
private string $entityType;
#[ORM\Column]
private int $entityId;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private School $school;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private SchoolYear $year;
#[ORM\Column]
private \DateTimeImmutable $deletedAt;
public function __construct(string $entityType, int $entityId, School $school, SchoolYear $year)
{
$this->entityType = $entityType;
$this->entityId = $entityId;
$this->school = $school;
$this->year = $year;
$this->deletedAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getEntityType(): string
{
return $this->entityType;
}
public function getEntityId(): int
{
return $this->entityId;
}
public function getSchool(): School
{
return $this->school;
}
public function getYear(): SchoolYear
{
return $this->year;
}
public function getDeletedAt(): \DateTimeImmutable
{
return $this->deletedAt;
}
}