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\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);