From 1efe75e62b568dc11f0812a986c408e0ae87b2b3 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Mon, 27 Nov 2023 14:46:22 +0100 Subject: [PATCH] Fixed submission logging --- CHANGELOG.md | 2 ++ .../os2forms_digital_post.services.yml | 2 +- .../src/Helper/WebformHelperSF1601.php | 18 ++++++++---------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e04657..f93d2fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- [#76](https://github.com/OS2Forms/os2forms/pull/76) + Fixed digital post logging on submissions. - [#73](https://github.com/OS2Forms/os2forms/pull/73a) Fix issue with nested elements in webform inherit diff --git a/modules/os2forms_digital_post/os2forms_digital_post.services.yml b/modules/os2forms_digital_post/os2forms_digital_post.services.yml index e4930534..a40d88a4 100644 --- a/modules/os2forms_digital_post/os2forms_digital_post.services.yml +++ b/modules/os2forms_digital_post/os2forms_digital_post.services.yml @@ -5,7 +5,7 @@ services: logger.channel.os2forms_digital_post_submission: parent: logger.channel_base - arguments: [ 'os2forms_digital_post_submission' ] + arguments: [ 'webform_submission' ] Drupal\os2forms_digital_post\Helper\Settings: arguments: diff --git a/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php b/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php index fd8a0815..4fb86767 100644 --- a/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php +++ b/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php @@ -217,6 +217,7 @@ public function log($level, $message, array $context = []): void { */ public function createJob(WebformSubmissionInterface $webformSubmission, array $handlerConfiguration): ?Job { $context = [ + 'handler_id' => 'os2forms_digital_post', 'webform_submission' => $webformSubmission, ]; @@ -230,7 +231,6 @@ public function createJob(WebformSubmissionInterface $webformSubmission, array $ $queue->enqueueJob($job); $context['@queue'] = $queue->id(); $this->notice('Job for sending digital post add to the queue @queue.', $context + [ - 'handler_id' => 'os2forms_digital_post', 'operation' => 'digital post queued for sending', ]); @@ -238,7 +238,6 @@ public function createJob(WebformSubmissionInterface $webformSubmission, array $ } catch (\Exception $exception) { $this->error('Error creating job for sending digital post.', $context + [ - 'handler_id' => 'os2forms_digital_post', 'operation' => 'digital post failed', ]); return NULL; @@ -253,6 +252,10 @@ public function createJob(WebformSubmissionInterface $webformSubmission, array $ public function processJob(Job $job): JobResult { $payload = $job->getPayload(); + $context = [ + 'handler_id' => 'os2forms_digital_post', + 'operation' => 'digital post send', + ]; try { $submissionId = $payload['submissionId']; $submission = $this->loadSubmission($submissionId); @@ -267,21 +270,16 @@ public function processJob(Job $job): JobResult { $message)); } + $context['webform_submission'] = $submission; $this->sendDigitalPost($submission, $payload['handlerConfiguration']); - $this->notice('Digital post sent', [ - 'handler_id' => 'os2forms_digital_post', - 'operation' => 'digital post send', - 'webform_submission' => $submission, - ]); + $this->notice('Digital post sent', $context); return JobResult::success(); } catch (\Exception $e) { - $this->error('Error: @message', [ + $this->error('Error: @message', $context + [ '@message' => $e->getMessage(), - 'handler_id' => 'os2forms_digital_post', - 'operation' => 'digital post send', ]); return JobResult::failure($e->getMessage());