mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Additional dependencies have been added to the PdfSignedMessageHandler to handle the state of the signature. After writing the signed message content, the state is set to 'signed' and the state date is updated with the current time. Also, modifications are flushed in the EntityManager to save these changes to the database. Corresponding updates and tests have been made in the PdfSignedMessageHandlerTest file.
62 lines
2.1 KiB
PHP
62 lines
2.1 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\DocStoreBundle\Service\Signature\Driver\BaseSigner;
|
|
|
|
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
|
|
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository;
|
|
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Component\Clock\ClockInterface;
|
|
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
|
|
|
final readonly class PdfSignedMessageHandler implements MessageHandlerInterface
|
|
{
|
|
/**
|
|
* log prefix.
|
|
*/
|
|
private const P = '[pdf signed message] ';
|
|
|
|
public function __construct(
|
|
private LoggerInterface $logger,
|
|
private EntityWorkflowManager $entityWorkflowManager,
|
|
private StoredObjectManagerInterface $storedObjectManager,
|
|
private EntityWorkflowStepSignatureRepository $entityWorkflowStepSignatureRepository,
|
|
private EntityManagerInterface $entityManager,
|
|
private ClockInterface $clock,
|
|
) {}
|
|
|
|
public function __invoke(PdfSignedMessage $message): void
|
|
{
|
|
$this->logger->info(self::P.'a message is received', ['signaturedId' => $message->signatureId]);
|
|
|
|
$signature = $this->entityWorkflowStepSignatureRepository->find($message->signatureId);
|
|
|
|
if (null === $signature) {
|
|
throw new \RuntimeException('no signature found');
|
|
}
|
|
|
|
$storedObject = $this->entityWorkflowManager->getAssociatedStoredObject($signature->getStep()->getEntityWorkflow());
|
|
|
|
if (null === $storedObject) {
|
|
throw new \RuntimeException('no stored object found');
|
|
}
|
|
|
|
$this->storedObjectManager->write($storedObject, $message->content);
|
|
|
|
$signature->setState(EntityWorkflowSignatureStateEnum::SIGNED)->setStateDate($this->clock->now());
|
|
$this->entityManager->flush();
|
|
$this->entityManager->clear();
|
|
}
|
|
}
|