From 82fb98348bb61d4243c215d67e77df101ff45e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 16 Dec 2024 15:44:40 +0100 Subject: [PATCH] Wrap PdfSignedMessage handling in a transaction Ensure atomicity when writing stored objects and marking signatures as signed by wrapping these operations in a database transaction. This reduces the risk of partial updates and improves data consistency. --- .changes/unreleased/Fixed-20241216-153850.yaml | 5 +++++ .../Driver/BaseSigner/PdfSignedMessageHandler.php | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changes/unreleased/Fixed-20241216-153850.yaml diff --git a/.changes/unreleased/Fixed-20241216-153850.yaml b/.changes/unreleased/Fixed-20241216-153850.yaml new file mode 100644 index 000000000..09b3a3a7e --- /dev/null +++ b/.changes/unreleased/Fixed-20241216-153850.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: Wrap handling of PdfSignedMessage into transactions +time: 2024-12-16T15:38:50.974937062+01:00 +custom: + Issue: "" diff --git a/src/Bundle/ChillDocStoreBundle/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandler.php b/src/Bundle/ChillDocStoreBundle/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandler.php index e97781a15..7b94b3124 100644 --- a/src/Bundle/ChillDocStoreBundle/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandler.php +++ b/src/Bundle/ChillDocStoreBundle/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandler.php @@ -51,11 +51,12 @@ final readonly class PdfSignedMessageHandler implements MessageHandlerInterface throw new \RuntimeException('no stored object found'); } - $this->storedObjectManager->write($storedObject, $message->content); + $this->entityManager->wrapInTransaction(function () use ($storedObject, $message, $signature) { + $this->storedObjectManager->write($storedObject, $message->content); - $this->signatureStepStateChanger->markSignatureAsSigned($signature, $message->signatureZoneIndex); + $this->signatureStepStateChanger->markSignatureAsSigned($signature, $message->signatureZoneIndex); + }); - $this->entityManager->flush(); $this->entityManager->clear(); } }