diff --git a/core/core.services.yml b/core/core.services.yml index 40c6a8a..923bfa4 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1357,6 +1357,10 @@ services: tags: - { name: backend_overridable } lazy: true + batch.event_subscriber.late_kernel_response_subscriber: + class: \Drupal\Core\Batch\EventSubscriber\LateKernelResponseSubscriber + tags: + - {name: event_subscriber} replica_database_ignore__subscriber: class: Drupal\Core\EventSubscriber\ReplicaDatabaseIgnoreSubscriber tags: diff --git a/core/includes/batch.inc b/core/includes/batch.inc index 5d05cd5..89ec7ac 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -48,6 +48,9 @@ function _batch_page(Request $request) { } // Register database update for the end of processing. + // On a non error batch processing + // \Drupal\Core\Batch\EventSubscriber\LateKernelResponseSubscriber should be + // triggered. drupal_register_shutdown_function('_batch_shutdown'); $build = []; diff --git a/core/lib/Drupal/Core/Batch/BatchStorage.php b/core/lib/Drupal/Core/Batch/BatchStorage.php index 82f5b65..ba29f4c 100644 --- a/core/lib/Drupal/Core/Batch/BatchStorage.php +++ b/core/lib/Drupal/Core/Batch/BatchStorage.php @@ -4,10 +4,11 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Database\SchemaObjectExistsException; +use Drupal\Core\DestructableInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Drupal\Core\Access\CsrfTokenGenerator; -class BatchStorage implements BatchStorageInterface { +class BatchStorage implements BatchStorageInterface, DestructableInterface { /** * The table name. diff --git a/core/lib/Drupal/Core/Batch/EventSubscriber/LateKernelResponseSubscriber.php b/core/lib/Drupal/Core/Batch/EventSubscriber/LateKernelResponseSubscriber.php new file mode 100644 index 0000000..9277d3f --- /dev/null +++ b/core/lib/Drupal/Core/Batch/EventSubscriber/LateKernelResponseSubscriber.php @@ -0,0 +1,30 @@ +isMasterRequest()) { + if ($batch = batch_get()) { + _batch_shutdown(); + } + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + $events[KernelEvents::RESPONSE][] = 'onResponse'; + return $events; + } + +}