Issue #2875228 by voleger, Bhanu951, andypost: Site install not using batch API service

merge-requests/3021/head
Alex Pott 2022-11-23 21:50:51 +00:00
parent d0ee369a05
commit 23250f8134
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
1 changed files with 32 additions and 21 deletions

View File

@ -1594,16 +1594,17 @@ function install_profile_modules(&$install_state) {
arsort($required); arsort($required);
arsort($non_required); arsort($non_required);
$operations = []; $batch_builder = new BatchBuilder();
foreach ($required + $non_required as $module => $weight) { 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 = [ $batch_builder
'operations' => $operations, ->setTitle(t('Installing @drupal', ['@drupal' => drupal_install_profile_distribution_name()]))
'title' => t('Installing @drupal', ['@drupal' => drupal_install_profile_distribution_name()]), ->setErrorMessage(t('The installation has encountered an error.'));
'error_message' => t('The installation has encountered an error.'), return $batch_builder->toArray();
];
return $batch;
} }
/** /**
@ -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 // If there is more than one language or the single one is not English, we
// should import translations. // 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(); $languages = \Drupal::languageManager()->getLanguages();
if (count($languages) > 1 || !isset($languages['en'])) { 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 // Set up a batch to import translations for drupal core. Translation import
// for contrib modules happens in install_import_translations_remaining. // for contrib modules happens in install_import_translations_remaining.
foreach ($languages as $language) { foreach ($languages as $language) {
if (locale_translation_use_remote_source()) { 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'); $module_handler->loadInclude('locale', 'inc', 'locale.fetch');
$batch = [ $batch_builder
'operations' => $operations, ->setTitle(t('Updating translations.'))
'title' => t('Updating translations.'), ->setProgressMessage('')
'progress_message' => '', ->setErrorMessage(t('Error importing translation files'))
'error_message' => t('Error importing translation files'), ->setFinishCallback('locale_translation_batch_fetch_finished');
'finished' => 'locale_translation_batch_fetch_finished', return $batch_builder->toArray();
'file' => \Drupal::service('extension.list.module')->getPath('locale') . '/locale.batch.inc',
];
return $batch;
} }
} }