From 4e588ed0e0071b8259bd70b6733f065c4b1da8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 11 Sep 2024 21:14:07 +0200 Subject: [PATCH] Add logging to SignatureStepStateChanger Enhanced the SignatureStepStateChanger by integrating a LoggerInterface to provide detailed logging at key points in the state transition process. This includes informational messages when marking signatures or skipping transitions, as well as debug messages when determining the next steps. --- .../Workflow/SignatureStepStateChanger.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Workflow/SignatureStepStateChanger.php b/src/Bundle/ChillMainBundle/Workflow/SignatureStepStateChanger.php index efba00b02..3e2871810 100644 --- a/src/Bundle/ChillMainBundle/Workflow/SignatureStepStateChanger.php +++ b/src/Bundle/ChillMainBundle/Workflow/SignatureStepStateChanger.php @@ -15,14 +15,18 @@ use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature; +use Psr\Log\LoggerInterface; use Symfony\Component\Clock\ClockInterface; use Symfony\Component\Workflow\Registry; class SignatureStepStateChanger { + private const LOG_PREFIX = '[SignatureStepStateChanger] '; + public function __construct( private readonly Registry $registry, private readonly ClockInterface $clock, + private readonly LoggerInterface $logger, ) {} public function markSignatureAsSigned(EntityWorkflowStepSignature $signature, ?int $atIndex): void @@ -33,10 +37,16 @@ class SignatureStepStateChanger ->setStateDate($this->clock->now()) ; + $this->logger->info(self::LOG_PREFIX.'Mark signature entity as signed', ['signatureId' => $signature->getId(), 'index' => (string) $atIndex]); + 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()]); + return; } + $this->logger->debug(self::LOG_PREFIX.'Continuing the process to find a transition', ['signatureId' => $signature->getId()]); + $entityWorkflow = $signature->getStep()->getEntityWorkflow(); $workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName()); $metadataStore = $workflow->getMetadataStore(); @@ -54,12 +64,16 @@ class SignatureStepStateChanger } if (null === $transition) { + $this->logger->info(self::LOG_PREFIX.'The transition is not configured, will not apply a transition', ['signatureId' => $signature->getId()]); + return; } $previousUser = $this->getPreviousSender($signature->getStep()); if (null === $previousUser) { + $this->logger->info(self::LOG_PREFIX.'No previous user, will not apply a transition', ['signatureId' => $signature->getId()]); + return; } @@ -71,6 +85,8 @@ class SignatureStepStateChanger 'transitionAt' => $this->clock->now(), 'transition' => $transition, ]); + + $this->logger->info(self::LOG_PREFIX.'Transition automatically applied', ['signatureId' => $signature->getId()]); } private function getPreviousSender(EntityWorkflowStep $entityWorkflowStep): ?User