Skip to content
Open
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 @@ -38,6 +38,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa
Removing SaveToFileWebformHandler (id: save_to_file)
- [#380](https://github.com/OS2Forms/os2forms/pull/380)
Computed twig encryption fix
- [PR-394](https://github.com/OS2Forms/os2forms/pull/394)
Add event subscriber to reset webform submissions state between processing jobs in queue

## [6.1.0] 2026-10-22

Expand Down
1 change: 1 addition & 0 deletions os2forms.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package: OS2Forms
core_version_requirement: ^10 || ^11

dependencies:
- 'drupal:advancedqueue'
- 'drupal:editor'
- 'drupal:entity_print'
- 'drupal:eu_cookie_compliance'
Expand Down
11 changes: 11 additions & 0 deletions os2forms.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
_defaults:
autowire: true

logger.channel.os2forms:
parent: logger.channel_base
arguments: [ 'os2forms' ]

Drupal\os2forms\EventSubscriber\AdvancedQueueSubscriber:
tags:
- { name: event_subscriber }
61 changes: 61 additions & 0 deletions src/EventSubscriber/AdvancedQueueSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Drupal\os2forms\EventSubscriber;

use Drupal\advancedqueue\Event\AdvancedQueueEvents;
use Drupal\advancedqueue\Event\JobEvent;
use Drupal\webform\Entity\WebformSubmission;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Subscriber for Advanced Queue events.
*/
final class AdvancedQueueSubscriber implements EventSubscriberInterface {

public function __construct(
#[Autowire(service: 'logger.channel.os2forms')]
private readonly LoggerInterface $logger,
) {
}

/**
* Resets static Webform submissions state before processing a job.
*
* If multiple submissions are processed in one (Drush) request and one of
* them activates a webform getting the content of an OS2Forms attachment
* element, all submissions afterwards will use the same webform as the first
* submission (see <https://github.com/OS2Forms/os2forms/issues/393> for some
* details).
*
* @see WebformSubmission::getWebform()
* @see WebformSubmission::$webform
*/
public function onPreProcess(JobEvent $event): void {
try {
$property = new \ReflectionProperty(WebformSubmission::class, 'webform');
$property->setValue(NULL);
}
catch (\ReflectionException $exception) {
$this->logger->error('Cannot reset webform submission webform state: @message', [
'@message' => $exception->getMessage(),
'exception' => $exception,
]);
}
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array {
return [
// We want our subscriber to run very early (cf.
// https://www.drupal.org/docs/develop/creating-modules/subscribe-to-and-dispatch-events#s-event-subscriber-priorities)
AdvancedQueueEvents::PRE_PROCESS => ['onPreProcess', 999_999],
];
}

}
Loading