refactor(mcp) : update MCP tools to use ConstructeurLinks

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-31 14:29:10 +02:00
parent 43fafc2251
commit 691f632be0
12 changed files with 64 additions and 28 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Mcp\Tool\Composant;
use App\Entity\Composant;
use App\Entity\ComposantConstructeurLink;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\ConstructeurRepository;
use App\Repository\ModelTypeRepository;
@@ -67,7 +68,10 @@ class CreateComposantTool
if (!$c) {
$this->mcpError('not_found', "Constructeur not found: {$cId}");
}
$composant->addConstructeur($c);
$link = new ComposantConstructeurLink();
$link->setComposant($composant);
$link->setConstructeur($c);
$this->em->persist($link);
}
$this->em->persist($composant);

View File

@@ -30,10 +30,11 @@ class GetComposantTool
}
$constructeurs = [];
foreach ($composant->getConstructeurs() as $c) {
foreach ($composant->getConstructeurLinks() as $link) {
$constructeurs[] = [
'id' => $c->getId(),
'name' => $c->getName(),
'id' => $link->getConstructeur()->getId(),
'name' => $link->getConstructeur()->getName(),
'supplierReference' => $link->getSupplierReference(),
];
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Mcp\Tool\Composant;
use App\Entity\ComposantConstructeurLink;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\ComposantRepository;
use App\Repository\ConstructeurRepository;
@@ -75,15 +76,18 @@ class UpdateComposantTool
}
if (null !== $constructeurIds) {
foreach ($composant->getConstructeurs()->toArray() as $existing) {
$composant->removeConstructeur($existing);
foreach ($composant->getConstructeurLinks()->toArray() as $existing) {
$this->em->remove($existing);
}
foreach ($constructeurIds as $cId) {
$c = $this->constructeurs->find($cId);
if (!$c) {
$this->mcpError('not_found', "Constructeur not found: {$cId}");
}
$composant->addConstructeur($c);
$link = new ComposantConstructeurLink();
$link->setComposant($composant);
$link->setConstructeur($c);
$this->em->persist($link);
}
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Mcp\Tool\Machine;
use App\Entity\Machine;
use App\Entity\MachineConstructeurLink;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\ConstructeurRepository;
use App\Repository\SiteRepository;
@@ -61,7 +62,10 @@ class CreateMachineTool
if (!$c) {
$this->mcpError('not_found', "Constructeur not found: {$cId}");
}
$machine->addConstructeur($c);
$link = new MachineConstructeurLink();
$link->setMachine($machine);
$link->setConstructeur($c);
$this->em->persist($link);
}
$this->em->persist($machine);

View File

@@ -30,10 +30,11 @@ class GetMachineTool
}
$constructeurs = [];
foreach ($machine->getConstructeurs() as $c) {
foreach ($machine->getConstructeurLinks() as $link) {
$constructeurs[] = [
'id' => $c->getId(),
'name' => $c->getName(),
'id' => $link->getConstructeur()->getId(),
'name' => $link->getConstructeur()->getName(),
'supplierReference' => $link->getSupplierReference(),
];
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Mcp\Tool\Machine;
use App\Entity\MachineConstructeurLink;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\ConstructeurRepository;
use App\Repository\MachineRepository;
@@ -67,15 +68,18 @@ class UpdateMachineTool
}
if (null !== $constructeurIds) {
foreach ($machine->getConstructeurs()->toArray() as $existing) {
$machine->removeConstructeur($existing);
foreach ($machine->getConstructeurLinks()->toArray() as $existing) {
$this->em->remove($existing);
}
foreach ($constructeurIds as $cId) {
$c = $this->constructeurs->find($cId);
if (!$c) {
$this->mcpError('not_found', "Constructeur not found: {$cId}");
}
$machine->addConstructeur($c);
$link = new MachineConstructeurLink();
$link->setMachine($machine);
$link->setConstructeur($c);
$this->em->persist($link);
}
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Mcp\Tool\Piece;
use App\Entity\Piece;
use App\Entity\PieceConstructeurLink;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\ConstructeurRepository;
use App\Repository\ModelTypeRepository;
@@ -67,7 +68,10 @@ class CreatePieceTool
if (!$c) {
$this->mcpError('not_found', "Constructeur not found: {$cId}");
}
$piece->addConstructeur($c);
$link = new PieceConstructeurLink();
$link->setPiece($piece);
$link->setConstructeur($c);
$this->em->persist($link);
}
$this->em->persist($piece);

View File

@@ -30,10 +30,11 @@ class GetPieceTool
}
$constructeurs = [];
foreach ($piece->getConstructeurs() as $c) {
foreach ($piece->getConstructeurLinks() as $link) {
$constructeurs[] = [
'id' => $c->getId(),
'name' => $c->getName(),
'id' => $link->getConstructeur()->getId(),
'name' => $link->getConstructeur()->getName(),
'supplierReference' => $link->getSupplierReference(),
];
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Mcp\Tool\Piece;
use App\Entity\PieceConstructeurLink;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\ConstructeurRepository;
use App\Repository\ModelTypeRepository;
@@ -75,15 +76,18 @@ class UpdatePieceTool
}
if (null !== $constructeurIds) {
foreach ($piece->getConstructeurs()->toArray() as $existing) {
$piece->removeConstructeur($existing);
foreach ($piece->getConstructeurLinks()->toArray() as $existing) {
$this->em->remove($existing);
}
foreach ($constructeurIds as $cId) {
$c = $this->constructeurs->find($cId);
if (!$c) {
$this->mcpError('not_found', "Constructeur not found: {$cId}");
}
$piece->addConstructeur($c);
$link = new PieceConstructeurLink();
$link->setPiece($piece);
$link->setConstructeur($c);
$this->em->persist($link);
}
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Mcp\Tool\Product;
use App\Entity\Product;
use App\Entity\ProductConstructeurLink;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\ConstructeurRepository;
use App\Repository\ModelTypeRepository;
@@ -63,7 +64,10 @@ class CreateProductTool
if (!$c) {
$this->mcpError('not_found', "Constructeur not found: {$cId}");
}
$product->addConstructeur($c);
$link = new ProductConstructeurLink();
$link->setProduct($product);
$link->setConstructeur($c);
$this->em->persist($link);
}
$this->em->persist($product);

View File

@@ -30,10 +30,11 @@ class GetProductTool
}
$constructeurs = [];
foreach ($product->getConstructeurs() as $c) {
foreach ($product->getConstructeurLinks() as $link) {
$constructeurs[] = [
'id' => $c->getId(),
'name' => $c->getName(),
'id' => $link->getConstructeur()->getId(),
'name' => $link->getConstructeur()->getName(),
'supplierReference' => $link->getSupplierReference(),
];
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Mcp\Tool\Product;
use App\Entity\ProductConstructeurLink;
use App\Mcp\Tool\McpToolHelper;
use App\Repository\ConstructeurRepository;
use App\Repository\ModelTypeRepository;
@@ -71,15 +72,18 @@ class UpdateProductTool
}
if (null !== $constructeurIds) {
foreach ($product->getConstructeurs()->toArray() as $existing) {
$product->removeConstructeur($existing);
foreach ($product->getConstructeurLinks()->toArray() as $existing) {
$this->em->remove($existing);
}
foreach ($constructeurIds as $cId) {
$c = $this->constructeurs->find($cId);
if (!$c) {
$this->mcpError('not_found', "Constructeur not found: {$cId}");
}
$product->addConstructeur($c);
$link = new ProductConstructeurLink();
$link->setProduct($product);
$link->setConstructeur($c);
$this->em->persist($link);
}
}