fix(constructeur) : fix remaining references after ConstructeurLink migration

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-31 14:50:05 +02:00
parent 34b0d9225c
commit 5fff226f84
4 changed files with 35 additions and 21 deletions

View File

@@ -714,7 +714,7 @@ class MachineStructureController extends AbstractController
'productId' => $composant->getProduct()?->getId(),
'product' => $composant->getProduct() ? $this->normalizeProduct($composant->getProduct()) : null,
'structure' => $this->buildStructureFromSlots($composant),
'constructeurs' => $this->normalizeConstructeurs($composant->getConstructeurs()),
'constructeurs' => $this->normalizeConstructeurLinks($composant->getConstructeurLinks()),
'documents' => [],
'customFields' => $type ? $this->normalizeCustomFieldDefinitions($type->getComponentCustomFields()) : [],
'customFieldValues' => $this->normalizeCustomFieldValues($composant->getCustomFieldValues()),
@@ -776,7 +776,7 @@ class MachineStructureController extends AbstractController
'typePiece' => $this->normalizeModelType($type),
'productId' => $piece->getProduct()?->getId(),
'product' => $piece->getProduct() ? $this->normalizeProduct($piece->getProduct()) : null,
'constructeurs' => $this->normalizeConstructeurs($piece->getConstructeurs()),
'constructeurs' => $this->normalizeConstructeurLinks($piece->getConstructeurLinks()),
'documents' => [],
'customFields' => $type ? $this->normalizeCustomFieldDefinitions($type->getPieceCustomFields()) : [],
'customFieldValues' => $this->normalizeCustomFieldValues($piece->getCustomFieldValues()),
@@ -794,7 +794,7 @@ class MachineStructureController extends AbstractController
'supplierPrice' => $product->getSupplierPrice(),
'typeProductId' => $type?->getId(),
'typeProduct' => $this->normalizeModelType($type),
'constructeurs' => $this->normalizeConstructeurs($product->getConstructeurs()),
'constructeurs' => $this->normalizeConstructeurLinks($product->getConstructeurLinks()),
'documents' => [],
'customFields' => $type ? $this->normalizeCustomFieldDefinitions($type->getProductCustomFields()) : [],
'customFieldValues' => $this->normalizeCustomFieldValues($product->getCustomFieldValues()),

View File

@@ -8,6 +8,7 @@ use App\Entity\CustomField;
use App\Entity\CustomFieldValue;
use App\Entity\Machine;
use App\Entity\MachineComponentLink;
use App\Entity\MachineConstructeurLink;
use App\Entity\MachinePieceLink;
use App\Entity\MachineProductLink;
use App\Entity\Site;
@@ -65,9 +66,13 @@ class CloneMachineTool
}
$newMachine->setPrix($source->getPrix());
// Copy constructeurs
foreach ($source->getConstructeurs() as $constructeur) {
$newMachine->getConstructeurs()->add($constructeur);
// Copy constructeur links
foreach ($source->getConstructeurLinks() as $link) {
$newLink = new MachineConstructeurLink();
$newLink->setMachine($newMachine);
$newLink->setConstructeur($link->getConstructeur());
$newLink->setSupplierReference($link->getSupplierReference());
$this->entityManager->persist($newLink);
}
$this->entityManager->persist($newMachine);

View File

@@ -145,7 +145,7 @@ class MachineStructureTool
'id' => $site->getId(),
'name' => $site->getName(),
],
'constructeurs' => $this->normalizeConstructeurs($machine->getConstructeurs()),
'constructeurs' => $this->normalizeConstructeurLinks($machine->getConstructeurLinks()),
'customFields' => $this->normalizeCustomFields($machine->getCustomFields()),
'customFieldValues' => $this->normalizeCustomFieldValues($machine->getCustomFieldValues()),
];
@@ -255,7 +255,7 @@ class MachineStructureTool
'productId' => $composant->getProduct()?->getId(),
'product' => $composant->getProduct() ? $this->normalizeProduct($composant->getProduct()) : null,
'structure' => $this->buildStructureFromSlots($composant),
'constructeurs' => $this->normalizeConstructeurs($composant->getConstructeurs()),
'constructeurs' => $this->normalizeConstructeurLinks($composant->getConstructeurLinks()),
'customFields' => $type ? $this->normalizeCustomFieldDefinitions($type->getComponentCustomFields()) : [],
'customFieldValues' => $this->normalizeCustomFieldValues($composant->getCustomFieldValues()),
];
@@ -316,7 +316,7 @@ class MachineStructureTool
'typePiece' => $this->normalizeModelType($type),
'productId' => $piece->getProduct()?->getId(),
'product' => $piece->getProduct() ? $this->normalizeProduct($piece->getProduct()) : null,
'constructeurs' => $this->normalizeConstructeurs($piece->getConstructeurs()),
'constructeurs' => $this->normalizeConstructeurLinks($piece->getConstructeurLinks()),
'customFields' => $type ? $this->normalizeCustomFieldDefinitions($type->getPieceCustomFields()) : [],
'customFieldValues' => $this->normalizeCustomFieldValues($piece->getCustomFieldValues()),
];
@@ -333,7 +333,7 @@ class MachineStructureTool
'supplierPrice' => $product->getSupplierPrice(),
'typeProductId' => $type?->getId(),
'typeProduct' => $this->normalizeModelType($type),
'constructeurs' => $this->normalizeConstructeurs($product->getConstructeurs()),
'constructeurs' => $this->normalizeConstructeurLinks($product->getConstructeurLinks()),
'customFields' => $type ? $this->normalizeCustomFieldDefinitions($type->getProductCustomFields()) : [],
'customFieldValues' => $this->normalizeCustomFieldValues($product->getCustomFieldValues()),
];
@@ -354,15 +354,19 @@ class MachineStructureTool
];
}
private function normalizeConstructeurs(Collection $constructeurs): array
private function normalizeConstructeurLinks(Collection $constructeurLinks): array
{
$items = [];
foreach ($constructeurs as $constructeur) {
foreach ($constructeurLinks as $link) {
$items[] = [
'id' => $constructeur->getId(),
'name' => $constructeur->getName(),
'email' => $constructeur->getEmail(),
'phone' => $constructeur->getPhone(),
'id' => $link->getId(),
'constructeur' => [
'id' => $link->getConstructeur()->getId(),
'name' => $link->getConstructeur()->getName(),
'email' => $link->getConstructeur()->getEmail(),
'phone' => $link->getConstructeur()->getPhone(),
],
'supplierReference' => $link->getSupplierReference(),
];
}

View File

@@ -837,11 +837,16 @@ final class EntityVersionService
$snapshot['version'] = $entity->getVersion();
}
// Constructeurs
if (method_exists($entity, 'getConstructeurs')) {
$snapshot['constructeurIds'] = [];
foreach ($entity->getConstructeurs() as $c) {
$snapshot['constructeurIds'][] = ['id' => $c->getId(), 'name' => $c->getName()];
// Constructeur links
if (method_exists($entity, 'getConstructeurLinks')) {
$snapshot['constructeurLinks'] = [];
foreach ($entity->getConstructeurLinks() as $link) {
$snapshot['constructeurLinks'][] = [
'id' => $link->getId(),
'constructeurId' => $link->getConstructeur()->getId(),
'constructeurName' => $link->getConstructeur()->getName(),
'supplierReference' => $link->getSupplierReference(),
];
}
}