chill-bundles/src/Bundle/ChillMainBundle/Workflow/Messenger/PostSignatureStateChangeHandler.php
Julien Fastré 5287824dbe
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.
2024-09-25 11:58:41 +02:00

42 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Workflow\Messenger;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository;
use Chill\MainBundle\Workflow\SignatureStepStateChanger;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
final readonly class PostSignatureStateChangeHandler implements MessageHandlerInterface
{
public function __construct(
private EntityWorkflowStepSignatureRepository $entityWorkflowStepSignatureRepository,
private SignatureStepStateChanger $signatureStepStateChanger,
private EntityManagerInterface $entityManager,
) {}
public function __invoke(PostSignatureStateChangeMessage $message): void
{
$signature = $this->entityWorkflowStepSignatureRepository->find($message->signatureId);
if (null === $signature) {
throw new UnrecoverableMessageHandlingException('signature not found');
}
$this->signatureStepStateChanger->onPostMark($signature);
$this->entityManager->flush();
$this->entityManager->clear();
}
}