Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
proc
/
212
/
root
/
proc
/
212
/
root
/
proc
/
self
/
root
/
proc
/
70528
/
cwd
/
src
/
Controller
/
back
/
//proc/212/root/proc/212/root/proc/self/root/proc/70528/cwd/src/Controller/back/ColorController.php
<?php namespace App\Controller\back; use App\Entity\Color; use App\Repository\ColorRepository; use App\Repository\ProductRepository; use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; /** * @Route("/admin") */ class ColorController extends AbstractController { /** * @Route("/product/{id}/color/add/{name}", name="back_product_color_add") */ public function addProductColor($id, $name, ProductRepository $productRepository, ManagerRegistry $doctrine): Response { $product = $productRepository->find($id); $color = new Color(); $color->setProduct($product); $color->setName($name); $em = $doctrine->getManager(); $em->persist($color); $em->flush(); return $this->json($color->getId()); } /** * @Route("/product/color/{id}/delete", name="back_product_color_delete") */ public function removeProductColor($id, ColorRepository $colorRepository, ManagerRegistry $doctrine) { $color = $colorRepository->find($id); try { $em = $doctrine->getManager(); $em->remove($color); $em->flush(); } catch (ForeignKeyConstraintViolationException $e) { $doctrine->resetManager(); $color = $colorRepository->find($id); $em = $doctrine->getManager(); $color->setActive(false); $em->persist($color); $em->flush(); return $this->json("Impossible de supprimer la couleur car elle est utilisé dans une commande. Elle à été archivée, et ne sera visible que sur les anciennes commandes."); } return $this->json("success"); } }