fix: keep upload files until their deletion is committed

This commit is contained in:
fromme committed 2026-10-15 12:49:48 +02:00
1 parent 7e182e3d51
commit 4aa2d7a5e6
5 files changed
+221 -12

No files matched your search

@@ -13,6 +13,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Flagception\Manager\FeatureManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
@@ -49,6 +50,12 @@ class DocumentUploadController extends AbstractController
$form = $this->createFormBuilder()->getForm();
$form->handleRequest($request);
// Checked before processUpload() removes the existing document, which it replaces.
if ($form->isSubmitted()
&& true === $this->uploadHandler->getUploadSession()->getUploadsByType($type)->isEmpty()) {
$form->addError(new FormError('Bitte lade zuerst eine Datei hoch'));
}
if ($form->isSubmitted() && $form->isValid()) {
$this->processUpload($disposition, $type);
@@ -110,15 +117,17 @@ class DocumentUploadController extends AbstractController
$disposition->addDocument($upload);
$this->entityManager->flush();
$this->uploadHandler->moveUploadSessionFilesFromOrphanage($type, $uploadSession);
$this->uploadHandler->removeUploadSessionUploadsByType($type);
// Before the flush: converting a non-PDF renames the file, and the new filename has to
// be persisted with the row.
if (true === $this->featureManager->isActive('sanitize_uploads')) {
$this->uploadHandler->ensurePdf($upload);
}
$this->entityManager->flush();
$this->eventDispatcher->dispatch(new DocumentUploadedEvent($upload), DocumentUploadedEvent::NAME);
if (Upload::TYPE_CONTRACT === $type) {
$this->eventDispatcher->dispatch(new DocumentConfirmedEvent($upload), DocumentConfirmedEvent::NAME);