mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-26 16:45:01 +00:00
Add async handling for signature state changes
Introduce MessageBus to handle post-signature operations asynchronously. This ensures that further steps are executed through dispatched messages, improving system scalability and performance. Implement new handlers and messages for the workflow state transitions.
This commit is contained in:
@@ -15,8 +15,10 @@ use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
|
||||
use Chill\MainBundle\Workflow\Messenger\PostSignatureStateChangeMessage;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
|
||||
class SignatureStepStateChanger
|
||||
@@ -27,6 +29,7 @@ class SignatureStepStateChanger
|
||||
private readonly Registry $registry,
|
||||
private readonly ClockInterface $clock,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly MessageBusInterface $messageBus,
|
||||
) {}
|
||||
|
||||
public function markSignatureAsSigned(EntityWorkflowStepSignature $signature, ?int $atIndex): void
|
||||
@@ -36,7 +39,7 @@ class SignatureStepStateChanger
|
||||
->setZoneSignatureIndex($atIndex)
|
||||
->setStateDate($this->clock->now());
|
||||
$this->logger->info(self::LOG_PREFIX.'Mark signature entity as signed', ['signatureId' => $signature->getId(), 'index' => (string) $atIndex]);
|
||||
$this->onPostMark($signature);
|
||||
$this->messageBus->dispatch(new PostSignatureStateChangeMessage((int) $signature->getId()));
|
||||
}
|
||||
|
||||
public function markSignatureAsCanceled(EntityWorkflowStepSignature $signature): void
|
||||
@@ -45,6 +48,7 @@ class SignatureStepStateChanger
|
||||
->setState(EntityWorkflowSignatureStateEnum::CANCELED)
|
||||
->setStateDate($this->clock->now());
|
||||
$this->logger->info(self::LOG_PREFIX.'Mark signature entity as canceled', ['signatureId' => $signature->getId()]);
|
||||
$this->messageBus->dispatch(new PostSignatureStateChangeMessage((int) $signature->getId()));
|
||||
}
|
||||
|
||||
public function markSignatureAsRejected(EntityWorkflowStepSignature $signature): void
|
||||
@@ -53,9 +57,15 @@ class SignatureStepStateChanger
|
||||
->setState(EntityWorkflowSignatureStateEnum::REJECTED)
|
||||
->setStateDate($this->clock->now());
|
||||
$this->logger->info(self::LOG_PREFIX.'Mark signature entity as rejected', ['signatureId' => $signature->getId()]);
|
||||
$this->messageBus->dispatch(new PostSignatureStateChangeMessage((int) $signature->getId()));
|
||||
}
|
||||
|
||||
private function onPostMark(EntityWorkflowStepSignature $signature): void
|
||||
/**
|
||||
* Executed after a signature has a new state.
|
||||
*
|
||||
* This should be executed only by a system user (without any user registered)
|
||||
*/
|
||||
public function onPostMark(EntityWorkflowStepSignature $signature): void
|
||||
{
|
||||
if (!EntityWorkflowStepSignature::isAllSignatureNotPendingForStep($signature->getStep())) {
|
||||
$this->logger->info(self::LOG_PREFIX.'This is not the last signature, skipping transition to another place', ['signatureId' => $signature->getId()]);
|
||||
|
Reference in New Issue
Block a user