fix: ensure flushing entity manager, add logging

This commit is contained in:
Björn Fromme
2025-04-24 09:22:06 +02:00
parent 190d6200ce
commit fb0f8054d5
@@ -6,6 +6,7 @@ use App\Entity\Upload;
use App\Repository\UploadRepository; use App\Repository\UploadRepository;
use App\Service\Upload\UploadHandler; use App\Service\Upload\UploadHandler;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\HeaderUtils; use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -21,7 +22,8 @@ class BatchDownloadController extends AbstractController
public function __construct( public function __construct(
private readonly UploadRepository $uploadRepository, private readonly UploadRepository $uploadRepository,
private readonly UploadHandler $uploadHandler, 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() ->setDownloaded()
->setDownloadedBy($this->getUser()->getUserIdentifier()) ->setDownloadedBy($this->getUser()->getUserIdentifier())
; ;
} catch (FileNotFoundException $e) { } catch (FileNotFoundException|FileNotReadableException $e) {
} catch (FileNotReadableException $e) { $this->logger->error('Unable to add file to ZIP', [
'upload' => $upload->getUuid(),
'error' => $e->getMessage(),
]);
} }
} }
$zip->finish(); $zip->finish();
$this->entityManager->flush();
}); });
$this->entityManager->flush();
$disposition = HeaderUtils::makeDisposition('attachment', $zipFilename, md5($zipFilename)); $disposition = HeaderUtils::makeDisposition('attachment', $zipFilename, md5($zipFilename));
$response->headers->set('Content-Disposition', $disposition); $response->headers->set('Content-Disposition', $disposition);