requireRole($this->security, 'ROLE_GESTIONNAIRE'); $machine = $this->machines->find($machineId); if (!$machine) { $this->mcpError('not_found', "Machine not found: {$machineId}"); } if (null !== $name) { $machine->setName($name); } if (null !== $reference) { $machine->setReference($reference); } if (null !== $prix) { $machine->setPrix($prix); } if (null !== $siteId) { $site = $this->sites->find($siteId); if (!$site) { $this->mcpError('not_found', "Site not found: {$siteId}"); } $machine->setSite($site); } if (null !== $constructeurIds) { foreach ($machine->getConstructeurs()->toArray() as $existing) { $machine->removeConstructeur($existing); } foreach ($constructeurIds as $cId) { $c = $this->constructeurs->find($cId); if (!$c) { $this->mcpError('not_found', "Constructeur not found: {$cId}"); } $machine->addConstructeur($c); } } $this->em->flush(); return $this->jsonResponse(['id' => $machine->getId(), 'name' => $machine->getName()]); } }