From 51214b66ce6d3ad96822c04509b2375c8a0080db Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Tue, 10 Dec 2019 21:30:37 +0100 Subject: [PATCH] Fix entity manager injection --- src/Controller/ArticleController.php | 4 ++-- src/Controller/FamilleController.php | 4 ++-- src/Controller/FournisseurController.php | 4 ++-- src/Controller/MissingBarcodeController.php | 10 ++++------ src/Controller/SupplyingController.php | 10 ++++------ src/Controller/TagPrintRequestController.php | 10 ++++------ 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/Controller/ArticleController.php b/src/Controller/ArticleController.php index c647ce3..f91e77c 100644 --- a/src/Controller/ArticleController.php +++ b/src/Controller/ArticleController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Entity\Article; +use Doctrine\ORM\EntityManagerInterface; use FOS\RestBundle\Context\Context; use FOS\RestBundle\Controller\AbstractFOSRestController; use FOS\RestBundle\Controller\Annotations as Rest; @@ -29,9 +30,8 @@ class ArticleController extends AbstractFOSRestController * * @SWG\Tag(name="articles") */ - public function getArticles() + public function getArticles(EntityManagerInterface $em) { - $em = $this->getDoctrine(); $articles = $em->getRepository(Article::class)->findAll(); return $this->view($articles)->setContext($this->getContext()); } diff --git a/src/Controller/FamilleController.php b/src/Controller/FamilleController.php index dcc6d1c..1143c42 100644 --- a/src/Controller/FamilleController.php +++ b/src/Controller/FamilleController.php @@ -4,6 +4,7 @@ use App\Entity\Article; use App\Entity\Famille; +use Doctrine\ORM\EntityManagerInterface; use FOS\RestBundle\Controller\AbstractFOSRestController; use FOS\RestBundle\Controller\Annotations as Rest; use Swagger\Annotations as SWG; @@ -29,9 +30,8 @@ class FamilleController extends AbstractFOSRestController * * @SWG\Tag(name="familles") */ - public function getFamilles() + public function getFamilles(EntityManagerInterface $em) { - $em = $this->getDoctrine(); $articles = $em->getRepository(Famille::class)->findAll(); return $articles; } diff --git a/src/Controller/FournisseurController.php b/src/Controller/FournisseurController.php index 484143a..de6e451 100644 --- a/src/Controller/FournisseurController.php +++ b/src/Controller/FournisseurController.php @@ -4,6 +4,7 @@ use App\Entity\Article; use App\Entity\Fournisseur; +use Doctrine\ORM\EntityManagerInterface; use FOS\RestBundle\Controller\AbstractFOSRestController; use FOS\RestBundle\Controller\Annotations as Rest; use Nelmio\ApiDocBundle\Annotation\Model; @@ -29,9 +30,8 @@ class FournisseurController extends AbstractFOSRestController * * @SWG\Tag(name="fournisseurs") */ - public function getFournisseurs() + public function getFournisseurs(EntityManagerInterface $em) { - $em = $this->getDoctrine(); $articles = $em->getRepository(Fournisseur::class)->findAll(); return $articles; } diff --git a/src/Controller/MissingBarcodeController.php b/src/Controller/MissingBarcodeController.php index 8aba420..cffb474 100644 --- a/src/Controller/MissingBarcodeController.php +++ b/src/Controller/MissingBarcodeController.php @@ -5,6 +5,7 @@ use App\Entity\MissingBarcode; use App\Form\MissingBarcodeType; +use Doctrine\ORM\EntityManagerInterface; use FOS\RestBundle\Context\Context; use FOS\RestBundle\Controller\AbstractFOSRestController; use FOS\RestBundle\Controller\Annotations as Rest; @@ -37,9 +38,8 @@ class MissingBarcodeController extends AbstractFOSRestController * * @SWG\Tag(name="missing_barcode") */ - public function getMissingBarcodes() + public function getMissingBarcodes(EntityManagerInterface $em) { - $em = $this->getDoctrine(); $missingBarcodes = $em->getRepository(MissingBarcode::class)->findAll(); return $this->view($missingBarcodes)->setContext($this->getContext()); } @@ -57,7 +57,7 @@ public function getMissingBarcodes() * @param Request $request * @return View|FormInterface */ - public function postMissingBarcode(Request $request) + public function postMissingBarcode(Request $request, EntityManagerInterface $em) { $missingBarcode = new MissingBarcode(); $form = $this->createForm(MissingBarcodeType::class, $missingBarcode); @@ -65,7 +65,6 @@ public function postMissingBarcode(Request $request) $form->submit($request->request->all()); if ($form->isValid()) { - $em = $this->getDoctrine()->getEntityManager(); $em->persist($missingBarcode); $em->flush(); @@ -90,9 +89,8 @@ public function postMissingBarcode(Request $request) * @param MissingBarcode $missingBarcode * @return \FOS\RestBundle\View\View */ - public function deleteMissingBarcode(MissingBarcode $missingBarcode) + public function deleteMissingBarcode(MissingBarcode $missingBarcode, EntityManagerInterface $em) { - $em = $this->getDoctrine()->getEntityManager(); $em->remove($missingBarcode); $em->flush(); diff --git a/src/Controller/SupplyingController.php b/src/Controller/SupplyingController.php index 5999b28..77c3e91 100644 --- a/src/Controller/SupplyingController.php +++ b/src/Controller/SupplyingController.php @@ -4,6 +4,7 @@ use App\Entity\Article; use App\Entity\Supplying; +use Doctrine\ORM\EntityManagerInterface; use FOS\RestBundle\Context\Context; use FOS\RestBundle\Controller\AbstractFOSRestController; use FOS\RestBundle\Controller\Annotations as Rest; @@ -35,9 +36,8 @@ class SupplyingController extends AbstractFOSRestController * * @SWG\Tag(name="supplying") */ - public function getSupplying() + public function getSupplying(EntityManagerInterface $em) { - $em = $this->getDoctrine(); $supplyings = $em->getRepository(Supplying::class)->getOngoing(); return $this->view($supplyings)->setContext($this->getContext()); } @@ -59,9 +59,8 @@ public function getSupplying() * * @SWG\Tag(name="supplying") */ - public function createSupplying($articleCode, $quantity) + public function createSupplying($articleCode, $quantity, EntityManagerInterface $em) { - $em = $this->getDoctrine()->getEntityManager(); $article = $em->getRepository(Article::class)->findOneByCode($articleCode); $supplying = new Supplying(); @@ -96,9 +95,8 @@ public function createSupplying($articleCode, $quantity) * * @SWG\Tag(name="supplying") */ - public function updateSupplying(int $id, Supplying $updates) + public function updateSupplying(int $id, Supplying $updates, EntityManagerInterface $em) { - $em = $this->getDoctrine()->getEntityManager(); $supplying = $em->getRepository(Supplying::class)->findOneById($id); $supplying->setQuantity($updates->getQuantity()); diff --git a/src/Controller/TagPrintRequestController.php b/src/Controller/TagPrintRequestController.php index 3980785..1f6821b 100644 --- a/src/Controller/TagPrintRequestController.php +++ b/src/Controller/TagPrintRequestController.php @@ -4,6 +4,7 @@ use App\Entity\TagPrintRequest; use App\Form\TagPrintRequestType; +use Doctrine\ORM\EntityManagerInterface; use FOS\RestBundle\Context\Context; use FOS\RestBundle\Controller\AbstractFOSRestController; use FOS\RestBundle\Controller\Annotations as Rest; @@ -36,9 +37,8 @@ class TagPrintRequestController extends AbstractFOSRestController * * @SWG\Tag(name="tag_print_request") */ - public function getTagPrintRequests() + public function getTagPrintRequests(EntityManagerInterface $em) { - $em = $this->getDoctrine(); $tagPrintRequests = $em->getRepository(TagPrintRequest::class)->findAll(); return $this->view($tagPrintRequests)->setContext($this->getContext()); } @@ -56,7 +56,7 @@ public function getTagPrintRequests() * @param Request $request * @return View|FormInterface */ - public function postTagPrintRequest(Request $request) + public function postTagPrintRequest(Request $request, EntityManagerInterface $em) { $tagPrintRequest = new TagPrintRequest(); $form = $this->createForm(TagPrintRequestType::class, $tagPrintRequest); @@ -64,7 +64,6 @@ public function postTagPrintRequest(Request $request) $form->submit($request->request->all()); if ($form->isValid()) { - $em = $this->getDoctrine()->getEntityManager(); $em->persist($tagPrintRequest); $em->flush(); @@ -89,9 +88,8 @@ public function postTagPrintRequest(Request $request) * @param TagPrintRequest $tagPrintRequest * @return \FOS\RestBundle\View\View */ - public function deleteTagPrintRequest(TagPrintRequest $tagPrintRequest) + public function deleteTagPrintRequest(TagPrintRequest $tagPrintRequest, EntityManagerInterface $em) { - $em = $this->getDoctrine()->getEntityManager(); $em->remove($tagPrintRequest); $em->flush();