From fb0f8054d5bc2633e4d11abc24be5c103793a5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 24 Apr 2025 09:22:06 +0200 Subject: [PATCH] fix: ensure flushing entity manager, add logging --- .../Document/BatchDownloadController.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Controller/Administrative/Document/BatchDownloadController.php b/src/Controller/Administrative/Document/BatchDownloadController.php index c8eb691..220e49a 100644 --- a/src/Controller/Administrative/Document/BatchDownloadController.php +++ b/src/Controller/Administrative/Document/BatchDownloadController.php @@ -6,6 +6,7 @@ use App\Entity\Upload; use App\Repository\UploadRepository; use App\Service\Upload\UploadHandler; use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\HeaderUtils; use Symfony\Component\HttpFoundation\Response; @@ -21,7 +22,8 @@ class BatchDownloadController extends AbstractController public function __construct( private readonly UploadRepository $uploadRepository, private readonly UploadHandler $uploadHandler, - private readonly EntityManagerInterface $entityManager + private readonly EntityManagerInterface $entityManager, + private readonly LoggerInterface $logger, ) { } @@ -72,14 +74,18 @@ class BatchDownloadController extends AbstractController ->setDownloaded() ->setDownloadedBy($this->getUser()->getUserIdentifier()) ; - } catch (FileNotFoundException $e) { - } catch (FileNotReadableException $e) { + } catch (FileNotFoundException|FileNotReadableException $e) { + $this->logger->error('Unable to add file to ZIP', [ + 'upload' => $upload->getUuid(), + 'error' => $e->getMessage(), + ]); } } $zip->finish(); - $this->entityManager->flush(); }); + $this->entityManager->flush(); + $disposition = HeaderUtils::makeDisposition('attachment', $zipFilename, md5($zipFilename)); $response->headers->set('Content-Disposition', $disposition);