From 4937f7dde11807dadcb9240730220904f4401b85 Mon Sep 17 00:00:00 2001 From: Jurriaan Roelofs Date: Mon, 11 May 2026 13:42:04 +0200 Subject: [PATCH 1/2] Fix batch progress tracking causing infinite loop processBatch() calculated $context['finished'] as a fraction of total entities across all operations, but the form creates one batch operation per chunk of 5. After processing a chunk, finished was e.g. 5/100 = 0.05, so Drupal re-invoked the same operation endlessly instead of advancing to the next chunk. Set finished = 1 at the end of each chunk since each chunk is a separate complete batch operation. Closes #20 --- src/Service/AnalyzeBatchService.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Service/AnalyzeBatchService.php b/src/Service/AnalyzeBatchService.php index 520499a..583d6b9 100644 --- a/src/Service/AnalyzeBatchService.php +++ b/src/Service/AnalyzeBatchService.php @@ -320,12 +320,9 @@ public function processBatch(array $entities, array $analyzer_ids, bool $force_r '@max' => $context['sandbox']['total_entities'], ])->render(); - if ($context['sandbox']['total_entities'] > 0) { - $context['finished'] = $done / $context['sandbox']['total_entities']; - } - else { - $context['finished'] = 1; - } + // Each chunk is a separate batch operation, so mark it complete. + // Drupal advances to the next operation when finished >= 1. + $context['finished'] = 1; } /** @@ -429,7 +426,7 @@ private function getFullyAnalyzedEntityIds(array $analyzer_ids, string $entity_t } } catch (\Exception) { - // Entity type may lack a view_builder — skip it. + // Entity type may lack a view_builder, skip it. } } // Clear static entity cache to keep memory flat. From 522583c8944b62ed62d5ad34279766d4f306961c Mon Sep 17 00:00:00 2001 From: Jurriaan Roelofs Date: Fri, 15 May 2026 09:15:01 +0200 Subject: [PATCH 2/2] Preserve batch totals across chunk operations --- src/Service/AnalyzeBatchService.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Service/AnalyzeBatchService.php b/src/Service/AnalyzeBatchService.php index 583d6b9..a1ef063 100644 --- a/src/Service/AnalyzeBatchService.php +++ b/src/Service/AnalyzeBatchService.php @@ -236,13 +236,10 @@ public function getAnalysisStatus(array $analyzer_ids, array $entity_bundles): a * Batch context. */ public function processBatch(array $entities, array $analyzer_ids, bool $force_refresh, int $total_entities, array &$context): void { - if (!isset($context['sandbox']['total_entities'])) { - $context['sandbox']['total_entities'] = $total_entities; - $context['results']['processed'] = 0; - $context['results']['failed'] = 0; - $context['results']['rate_limited'] = 0; - $context['results']['errors'] = []; - } + $context['results']['processed'] = $context['results']['processed'] ?? 0; + $context['results']['failed'] = $context['results']['failed'] ?? 0; + $context['results']['rate_limited'] = $context['results']['rate_limited'] ?? 0; + $context['results']['errors'] = $context['results']['errors'] ?? []; // Build analyzer instances. $all_analyzers = []; @@ -317,7 +314,7 @@ public function processBatch(array $entities, array $analyzer_ids, bool $force_r $done = $context['results']['processed'] + $context['results']['failed']; $context['message'] = $this->t('Processed @current of @max entities...', [ '@current' => $done, - '@max' => $context['sandbox']['total_entities'], + '@max' => $total_entities, ])->render(); // Each chunk is a separate batch operation, so mark it complete.