Skip to content

Commit

Permalink
Merge pull request #76 from itk-dev/feature/digital-post-submission-l…
Browse files Browse the repository at this point in the history
…ogging

Fixed submission logging
  • Loading branch information
jekuaitk authored Dec 5, 2023
2 parents 2c47532 + 068cb52 commit a62008d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- [#74](https://github.com/OS2Forms/os2forms/pull/74)
Allow composite elements in Maestro notification recipient
- [#73](https://github.com/OS2Forms/os2forms/pull/73a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 8 additions & 10 deletions modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

Expand All @@ -230,15 +231,13 @@ 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',
]);

return $job;
}
catch (\Exception $exception) {
$this->error('Error creating job for sending digital post.', $context + [
'handler_id' => 'os2forms_digital_post',
'operation' => 'digital post failed',
]);
return NULL;
Expand All @@ -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);
Expand All @@ -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());
Expand Down

0 comments on commit a62008d

Please sign in to comment.