From 8bceb975505dbf60813456d6302b6e36084738e0 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Sat, 22 Jul 2023 17:42:30 +0300 Subject: [PATCH] save method in PasteRepository changed --- src/Controller/PasteController.php | 2 +- src/Repository/PasteRepository.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Controller/PasteController.php b/src/Controller/PasteController.php index 5b37231..67fad63 100644 --- a/src/Controller/PasteController.php +++ b/src/Controller/PasteController.php @@ -27,7 +27,7 @@ class PasteController extends AbstractController $pasteData->ip = $request->getClientIp(); $paste = Paste::fromFormData($pasteData); - $pasteRepository->save($paste); + $pasteRepository->save($paste, true); return $this->redirectToRoute($request->attributes->get('_route')); } diff --git a/src/Repository/PasteRepository.php b/src/Repository/PasteRepository.php index 74ee7d5..0817611 100644 --- a/src/Repository/PasteRepository.php +++ b/src/Repository/PasteRepository.php @@ -14,10 +14,13 @@ class PasteRepository extends ServiceEntityRepository parent::__construct($registry, Paste::class); } - public function save(Paste $paste): void + public function save(Paste $paste, bool $flush=false): void { $entityManager = $this->getEntityManager(); $entityManager->persist($paste); - $entityManager->flush(); + + if ($flush) { + $entityManager->flush(); + } } } \ No newline at end of file