Delete photos when deleting offer

This commit is contained in:
Jannis Portmann 2021-06-15 17:24:15 +02:00
parent 91fb30ed40
commit 171a816f9d

View file

@ -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')]