diff --git a/xmlsitemap.module b/xmlsitemap.module index ce969c2..cbe78e2 100644 --- a/xmlsitemap.module +++ b/xmlsitemap.module @@ -1421,7 +1421,27 @@ function xmlsitemap_run_unprogressive_batch() { drush_backend_batch_process(); } else { - batch_process(); + // batch_process() unconditionally builds a 'source_url' via + // Url::fromRouteMatch(\Drupal::routeMatch()) before it even looks at + // the progressive flag. That call requires a resolved current route, + // which is not always available - e.g. automated cron running in + // kernel.terminate, or drush cron in CLI context if + // drush_backend_batch_process() is unavailable. This batch is always + // non-progressive (see above), so 'source_url' and the other + // progressive-only data are never used. Do the initialization that + // batch_process() would do for a non-progressive batch (current set, + // batch id, memory queues), then process it directly. + // Calling _batch_process() without this initialization fails with + // "Call to a member function claimItem() on null" - an \Error, which + // the cron service does not catch, so it aborts the whole cron run. + // See https://www.drupal.org/project/xmlsitemap/issues/3100808 + require_once DRUPAL_ROOT . '/core/includes/batch.inc'; + $batch += ['current_set' => 0]; + $batch['id'] = 'non-progressive'; + foreach ($batch['sets'] as $key => $batch_set) { + _batch_populate_queue($batch, $key); + } + _batch_process(); } $lock->release($batch_callback);