From 23250f8134d8f1942c0cea47503359acc8b9518f Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 23 Nov 2022 21:50:51 +0000 Subject: [PATCH] Issue #2875228 by voleger, Bhanu951, andypost: Site install not using batch API service --- core/includes/install.core.inc | 53 ++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index b18c9e57a38f..8f8ba759f44a 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1594,16 +1594,17 @@ function install_profile_modules(&$install_state) { arsort($required); arsort($non_required); - $operations = []; + $batch_builder = new BatchBuilder(); foreach ($required + $non_required as $module => $weight) { - $operations[] = ['_install_module_batch', [$module, $files[$module]->info['name']]]; + $batch_builder->addOperation( + '_install_module_batch', + [$module, $files[$module]->info['name']], + ); } - $batch = [ - 'operations' => $operations, - 'title' => t('Installing @drupal', ['@drupal' => drupal_install_profile_distribution_name()]), - 'error_message' => t('The installation has encountered an error.'), - ]; - return $batch; + $batch_builder + ->setTitle(t('Installing @drupal', ['@drupal' => drupal_install_profile_distribution_name()])) + ->setErrorMessage(t('The installation has encountered an error.')); + return $batch_builder->toArray(); } /** @@ -1727,30 +1728,40 @@ function install_import_translations(&$install_state) { // If there is more than one language or the single one is not English, we // should import translations. - $operations = install_download_additional_translations_operations($install_state); + $batch_builder = (new BatchBuilder()) + ->setFile(\Drupal::service('extension.path.resolver')->getPath('module', 'locale') . '/locale.batch.inc'); + foreach (install_download_additional_translations_operations($install_state) as $operation) { + $batch_builder->addOperation($operation[0], $operation[1]); + } $languages = \Drupal::languageManager()->getLanguages(); if (count($languages) > 1 || !isset($languages['en'])) { - $operations[] = ['_install_prepare_import', [array_keys($languages), $install_state['server_pattern']]]; + $batch_builder->addOperation( + '_install_prepare_import', + [array_keys($languages), $install_state['server_pattern']], + ); // Set up a batch to import translations for drupal core. Translation import // for contrib modules happens in install_import_translations_remaining. foreach ($languages as $language) { if (locale_translation_use_remote_source()) { - $operations[] = ['locale_translation_batch_fetch_download', ['drupal', $language->getId()]]; + $batch_builder->addOperation( + 'locale_translation_batch_fetch_download', + ['drupal', $language->getId()], + ); } - $operations[] = ['locale_translation_batch_fetch_import', ['drupal', $language->getId(), []]]; + $batch_builder->addOperation( + 'locale_translation_batch_fetch_import', + ['drupal', $language->getId(), []], + ); } $module_handler->loadInclude('locale', 'inc', 'locale.fetch'); - $batch = [ - 'operations' => $operations, - 'title' => t('Updating translations.'), - 'progress_message' => '', - 'error_message' => t('Error importing translation files'), - 'finished' => 'locale_translation_batch_fetch_finished', - 'file' => \Drupal::service('extension.list.module')->getPath('locale') . '/locale.batch.inc', - ]; - return $batch; + $batch_builder + ->setTitle(t('Updating translations.')) + ->setProgressMessage('') + ->setErrorMessage(t('Error importing translation files')) + ->setFinishCallback('locale_translation_batch_fetch_finished'); + return $batch_builder->toArray(); } }