From 3f3dfd197d04e96538a34150fc0a0f18b7b5edb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 18 Oct 2023 17:06:41 +0200 Subject: [PATCH] Fix: Resolve impossible confirmation of uploaded contract --- .../Admin/Document/CheckController.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Controller/Admin/Document/CheckController.php b/src/Controller/Admin/Document/CheckController.php index 5a16c58..5332dfd 100644 --- a/src/Controller/Admin/Document/CheckController.php +++ b/src/Controller/Admin/Document/CheckController.php @@ -76,36 +76,39 @@ class CheckController extends AbstractController private function rejectDocument(Upload $document, string $comment = null): void { - $transition = Upload::TYPE_CONTRACT === $document->getType() ? 'reject_contract' : 'reject_invoice'; - $this->workflow->apply($document->getDisposition(), $transition); $document ->setStatus(Upload::STATUS_REJECTED) ->setComment($comment) ; - $this->entityManager->flush(); $this->addFlash('success', 'Das Dokument wurde abgelehnt'); $this->logger->info('Reject document', [ 'document' => $document->getOriginalFilename(), ]); + $transition = Upload::TYPE_CONTRACT === $document->getType() ? 'reject_contract' : 'reject_invoice'; + $this->workflow->apply($document->getDisposition(), $transition); + + $this->entityManager->flush(); } private function confirmDocument(Upload $document, string $transition, string $status): void { + $document->setStatus($status); + $this->addFlash('success', 'Das Dokument wurde bestätigt'); + $this->logger->info('Confirm document', [ + 'document' => $document->getOriginalFilename(), + ]); + if (true === $this->workflow->can($document->getDisposition(), $transition)) { - $document->setStatus($status); $this->workflow->apply($document->getDisposition(), $transition); - $this->entityManager->flush(); - $this->addFlash('success', 'Das Dokument wurde bestätigt'); - $this->logger->info('Confirm document', [ - 'document' => $document->getOriginalFilename(), - ]); } else { $blockers = $this->workflow->buildTransitionBlockerList($document->getDisposition(), $transition); foreach ($blockers as $blocker) { $this->addFlash('error', $blocker->getMessage()); } } + + $this->entityManager->flush(); } }