src/Entity/EntityDeletion.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\EntityDeletionRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * Trace légère d'une suppression — plusieurs entités synchronisées hors
  7.  * ligne (Absence, Late, Note, Punish, HomeWork, DailyAbsence...) sont des
  8.  * hard-deletes (EntityManager::remove()), et chaque endpoint sync()
  9.  * codait `deleted_ids` en dur à `[]` : un enregistrement supprimé restait
  10.  * donc indéfiniment dans le cache local (Drift) de tout rôle l'ayant déjà
  11.  * synchronisé, sauf sur l'appareil de l'auteur de la suppression (épargné
  12.  * par la suppression optimiste locale) — constaté à l'usage côté devoirs,
  13.  * puis confirmé systémique pour absence/retard/note/sanction.
  14.  *
  15.  * Une seule table générique (discriminée par [entityType]) plutôt qu'une
  16.  * table par entité — même rôle partout (répondre "cet id a disparu depuis
  17.  * $since"), pas de raison de dupliquer le schéma cinq fois. $entityId
  18.  * n'est PAS une vraie FK (l'entité visée n'existe plus au moment où on lit
  19.  * cette trace) — juste l'id brut à renvoyer dans deleted_ids.
  20.  */
  21. #[ORM\Entity(repositoryClassEntityDeletionRepository::class)]
  22. #[ORM\Index(columns: ['entity_type''school_id''year_id''deleted_at'], name'idx_entity_deletion_lookup')]
  23. class EntityDeletion
  24. {
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column]
  28.     private ?int $id null;
  29.     /** 'absence' | 'late' | 'note' | 'punish' | 'homework' | 'daily_absence' */
  30.     #[ORM\Column(length32)]
  31.     private string $entityType;
  32.     #[ORM\Column]
  33.     private int $entityId;
  34.     #[ORM\ManyToOne]
  35.     #[ORM\JoinColumn(nullablefalse)]
  36.     private School $school;
  37.     #[ORM\ManyToOne]
  38.     #[ORM\JoinColumn(nullablefalse)]
  39.     private SchoolYear $year;
  40.     #[ORM\Column]
  41.     private \DateTimeImmutable $deletedAt;
  42.     public function __construct(string $entityTypeint $entityIdSchool $schoolSchoolYear $year)
  43.     {
  44.         $this->entityType $entityType;
  45.         $this->entityId   $entityId;
  46.         $this->school     $school;
  47.         $this->year       $year;
  48.         $this->deletedAt  = new \DateTimeImmutable();
  49.     }
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function getEntityType(): string
  55.     {
  56.         return $this->entityType;
  57.     }
  58.     public function getEntityId(): int
  59.     {
  60.         return $this->entityId;
  61.     }
  62.     public function getSchool(): School
  63.     {
  64.         return $this->school;
  65.     }
  66.     public function getYear(): SchoolYear
  67.     {
  68.         return $this->year;
  69.     }
  70.     public function getDeletedAt(): \DateTimeImmutable
  71.     {
  72.         return $this->deletedAt;
  73.     }
  74. }