feat(sync) : add version field and PieceProductSlot entity

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-13 13:38:13 +01:00
parent 3f07162b94
commit 5210e53d73
4 changed files with 193 additions and 0 deletions

View File

@@ -114,12 +114,23 @@ class Piece
#[ORM\InverseJoinColumn(name: 'product_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
private Collection $products;
/**
* @var Collection<int, PieceProductSlot>
*/
#[ORM\OneToMany(targetEntity: PieceProductSlot::class, mappedBy: 'piece', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['position' => 'ASC'])]
private Collection $productSlots;
/**
* @var Collection<int, MachinePieceLink>
*/
#[ORM\OneToMany(mappedBy: 'piece', targetEntity: MachinePieceLink::class)]
private Collection $machineLinks;
#[ORM\Column(type: Types::INTEGER, options: ['default' => 1])]
#[Groups(['piece:read'])]
private int $version = 1;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
#[Groups(['piece:read'])]
private DateTimeImmutable $createdAt;
@@ -136,6 +147,7 @@ class Piece
$this->documents = new ArrayCollection();
$this->customFieldValues = new ArrayCollection();
$this->products = new ArrayCollection();
$this->productSlots = new ArrayCollection();
$this->machineLinks = new ArrayCollection();
}
@@ -287,4 +299,41 @@ class Piece
return $this;
}
/**
* @return Collection<int, PieceProductSlot>
*/
public function getProductSlots(): Collection
{
return $this->productSlots;
}
public function addProductSlot(PieceProductSlot $slot): static
{
if (!$this->productSlots->contains($slot)) {
$this->productSlots->add($slot);
$slot->setPiece($this);
}
return $this;
}
public function removeProductSlot(PieceProductSlot $slot): static
{
$this->productSlots->removeElement($slot);
return $this;
}
public function getVersion(): int
{
return $this->version;
}
public function incrementVersion(): static
{
++$this->version;
return $this;
}
}