From 171a816f9d02db946b24674a72e1f2d9a710f027 Mon Sep 17 00:00:00 2001 From: thisfro Date: Tue, 15 Jun 2021 17:24:15 +0200 Subject: [PATCH] Delete photos when deleting offer --- src/Controller/OfferController.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Controller/OfferController.php b/src/Controller/OfferController.php index f4551b7..2f44983 100644 --- a/src/Controller/OfferController.php +++ b/src/Controller/OfferController.php @@ -139,22 +139,23 @@ class OfferController extends AbstractController } #[Route('/offer/delete/{id}', name: 'delete_offer')] - public function deleteOffer(Offering $offer): Response + public function deleteOffer(Offering $offer, string $photoDir): Response { $user = $this->getUser(); if ($offer->getByUser() === $user) { - $this->entityManager->remove($offer); - $this->entityManager->flush(); - $this->addFlash( - 'success','Successfully removed offer!' - ); - - return $this->redirectToRoute('own_offers'); + unlink($photoDir . '/' . $offer->getPhotoFilename()); + $this->entityManager->remove($offer); + $this->entityManager->flush(); + $this->addFlash( + 'success','Successfully removed offer!' + ); + + return $this->redirectToRoute('own_offers'); } - throw new HttpException(403, "No permission"); + throw new HttpException(403); } #[Route('/myoffers', name: 'own_offers')]