Refactor transaction handling for signature state changes, to wrap them into transactions

Wrap signature state changes in transactions to prevent race conditions and ensure data integrity. Update controller and test class names to reflect broader state change capabilities. Enhance documentation with comments to clarify transaction requirements and procedure details for signature operations.
This commit is contained in:
2024-12-06 12:20:42 +01:00
parent 033053c437
commit 3af7824d01
6 changed files with 87 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Twig\Environment;
final readonly class WorkflowSignatureCancelController
final readonly class WorkflowSignatureStateChangeController
{
public function __construct(
private EntityManagerInterface $entityManager,
@@ -79,8 +79,9 @@ final readonly class WorkflowSignatureCancelController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$markSignature($signature);
$this->entityManager->flush();
$this->entityManager->wrapInTransaction(function () use ($signature, $markSignature) {
$markSignature($signature);
});
return new RedirectResponse(
$this->chillUrlGenerator->returnPathOr('chill_main_workflow_show', ['id' => $signature->getStep()->getEntityWorkflow()->getId()])