diff --git a/web/themes/contrib/civictheme/src/CivicthemeUpdateHelper.php b/web/themes/contrib/civictheme/src/CivicthemeUpdateHelper.php index 042f32e9e..c7a37b61d 100644 --- a/web/themes/contrib/civictheme/src/CivicthemeUpdateHelper.php +++ b/web/themes/contrib/civictheme/src/CivicthemeUpdateHelper.php @@ -65,17 +65,26 @@ public static function create(ContainerInterface $container): self { * Finish callback called when batch finished. * @param int $batch_size * Batch size. Defaults to 10. + * @param int|null $limit + * Limit. Defaults to no limit. * * @return string|null * Return log message on the last pass of the update. + * + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - public function update(array &$sandbox, $entity_type, array $entity_bundles, callable $start_callback, callable $process_callback, callable $finish_callback, int $batch_size = 10): ?string { + public function update(array &$sandbox, $entity_type, array $entity_bundles, callable $start_callback, callable $process_callback, callable $finish_callback, int $batch_size = 10, ?int $limit = NULL): ?string { $storage = $this->entityTypeManager->getStorage($entity_type); if (!isset($sandbox['entities'])) { - $sandbox['batch'] = 0; - $sandbox['entities'] = $storage->getQuery()->accessCheck(FALSE)->condition('type', $entity_bundles, 'IN')->execute(); + $query = $storage->getQuery()->accessCheck(FALSE)->condition('type', $entity_bundles, 'IN'); + if ($limit) { + $query->range(0, $limit); + } + $sandbox['entities'] = $query->execute(); + $sandbox['max'] = count($sandbox['entities']); + $sandbox['batch'] = 0; $sandbox['results']['processed'] = []; $sandbox['results']['updated'] = [];