From 5fff226f84a1ae5c9066b918dc2ded7ef650fb69 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 31 Mar 2026 14:50:05 +0200 Subject: [PATCH] fix(constructeur) : fix remaining references after ConstructeurLink migration Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Controller/MachineStructureController.php | 6 ++--- src/Mcp/Tool/Machine/CloneMachineTool.php | 11 ++++++--- src/Mcp/Tool/Machine/MachineStructureTool.php | 24 +++++++++++-------- src/Service/EntityVersionService.php | 15 ++++++++---- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/Controller/MachineStructureController.php b/src/Controller/MachineStructureController.php index c4d2e3e..30e4b9e 100644 --- a/src/Controller/MachineStructureController.php +++ b/src/Controller/MachineStructureController.php @@ -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()), diff --git a/src/Mcp/Tool/Machine/CloneMachineTool.php b/src/Mcp/Tool/Machine/CloneMachineTool.php index fe76a66..df25c30 100644 --- a/src/Mcp/Tool/Machine/CloneMachineTool.php +++ b/src/Mcp/Tool/Machine/CloneMachineTool.php @@ -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); diff --git a/src/Mcp/Tool/Machine/MachineStructureTool.php b/src/Mcp/Tool/Machine/MachineStructureTool.php index 36d35af..c5de485 100644 --- a/src/Mcp/Tool/Machine/MachineStructureTool.php +++ b/src/Mcp/Tool/Machine/MachineStructureTool.php @@ -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(), ]; } diff --git a/src/Service/EntityVersionService.php b/src/Service/EntityVersionService.php index 1f5d285..955c7fc 100644 --- a/src/Service/EntityVersionService.php +++ b/src/Service/EntityVersionService.php @@ -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(), + ]; } }