Delete photos when deleting offer
This commit is contained in:
		
							parent
							
								
									91fb30ed40
								
							
						
					
					
						commit
						171a816f9d
					
				
					 1 changed files with 10 additions and 9 deletions
				
			
		|  | @ -139,12 +139,13 @@ class OfferController extends AbstractController | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[Route('/offer/delete/{id}', name: 'delete_offer')]
 |     #[Route('/offer/delete/{id}', name: 'delete_offer')]
 | ||||||
|     public function deleteOffer(Offering $offer): Response |     public function deleteOffer(Offering $offer, string $photoDir): Response | ||||||
|     { |     { | ||||||
|         $user = $this->getUser();  |         $user = $this->getUser();  | ||||||
| 
 | 
 | ||||||
|         if ($offer->getByUser() === $user) |         if ($offer->getByUser() === $user) | ||||||
|         { |         { | ||||||
|  |             unlink($photoDir . '/' . $offer->getPhotoFilename()); | ||||||
|             $this->entityManager->remove($offer); |             $this->entityManager->remove($offer); | ||||||
|             $this->entityManager->flush(); |             $this->entityManager->flush(); | ||||||
|             $this->addFlash( |             $this->addFlash( | ||||||
|  | @ -154,7 +155,7 @@ class OfferController extends AbstractController | ||||||
|             return $this->redirectToRoute('own_offers');     |             return $this->redirectToRoute('own_offers');     | ||||||
|         }  |         }  | ||||||
| 
 | 
 | ||||||
|         throw new HttpException(403, "No permission"); |         throw new HttpException(403); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[Route('/myoffers', name: 'own_offers')]
 |     #[Route('/myoffers', name: 'own_offers')]
 | ||||||
|  |  | ||||||
		Reference in a new issue