daa0cb1e28
Auto Tag Develop / tag (push) Successful in 9s
- Nouvelles entites ConstructeurCategorie (referentiel M2M) et ConstructeurTelephone (1-N) - Constructeur : retrait colonne phone, ajout collections telephones/categories, groupes de serialisation constructeur:read/write - Migration : cree les 3 tables, migre la colonne phone existante vers constructeur_telephone, drop phone - Commande app:import-fournisseurs (dry-run par defaut, --force) : non destructive, find-or-create par nom, ne touche jamais un ID existant, ajout-seulement pour telephones/categories - MAJ MCP tools / MachineStructureController / audit subscriber / tests - Frontend : page constructeurs avec telephones multiples + categories (tableau, filtre, formulaire), composable useConstructeurCategories, composant ConstructeurCategorieSelect Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
70 lines
2.1 KiB
PHP
70 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Mcp\Tool\Constructeur;
|
|
|
|
use App\Entity\ConstructeurTelephone;
|
|
use App\Mcp\Tool\McpToolHelper;
|
|
use App\Repository\ConstructeurRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Mcp\Capability\Attribute\McpTool;
|
|
use Mcp\Schema\Result\CallToolResult;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
|
|
#[McpTool(
|
|
name: 'update_constructeur',
|
|
description: 'Update an existing constructeur. Only provided fields are changed. A non-empty "phone" is added as an additional phone number if not already present (existing numbers are never removed). Requires ROLE_GESTIONNAIRE.',
|
|
)]
|
|
class UpdateConstructeurTool
|
|
{
|
|
use McpToolHelper;
|
|
|
|
public function __construct(
|
|
private readonly ConstructeurRepository $constructeurs,
|
|
private readonly EntityManagerInterface $em,
|
|
private readonly Security $security,
|
|
) {}
|
|
|
|
public function __invoke(
|
|
string $constructeurId,
|
|
?string $name = null,
|
|
?string $email = null,
|
|
?string $phone = null,
|
|
): CallToolResult {
|
|
$this->requireRole($this->security, 'ROLE_GESTIONNAIRE');
|
|
|
|
$constructeur = $this->constructeurs->find($constructeurId);
|
|
|
|
if (!$constructeur) {
|
|
$this->mcpError('not_found', "Constructeur not found: {$constructeurId}");
|
|
}
|
|
|
|
if (null !== $name) {
|
|
$constructeur->setName($name);
|
|
}
|
|
if (null !== $email) {
|
|
$constructeur->setEmail($email);
|
|
}
|
|
if (null !== $phone && '' !== $phone) {
|
|
$alreadyPresent = false;
|
|
foreach ($constructeur->getTelephones() as $existing) {
|
|
if ($existing->getNumero() === $phone) {
|
|
$alreadyPresent = true;
|
|
|
|
break;
|
|
}
|
|
}
|
|
if (!$alreadyPresent) {
|
|
$telephone = new ConstructeurTelephone();
|
|
$telephone->setNumero($phone);
|
|
$constructeur->addTelephone($telephone);
|
|
}
|
|
}
|
|
|
|
$this->em->flush();
|
|
|
|
return $this->jsonResponse(['id' => $constructeur->getId(), 'name' => $constructeur->getName()]);
|
|
}
|
|
}
|