Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed submission logging #76

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading