diff --git a/core/modules/locale/locale.compare.inc b/core/modules/locale/locale.compare.inc index 9b26803974..61f4211725 100644 --- a/core/modules/locale/locale.compare.inc +++ b/core/modules/locale/locale.compare.inc @@ -237,42 +237,46 @@ function locale_translation_batch_status_build($projects = [], $langcodes = []) $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list()); $options = _locale_translation_default_update_options(); + $operations = _locale_translation_batch_status_operations($projects, $langcodes, $options); + $batch_builder = (new BatchBuilder()) ->setFile(drupal_get_path('module', 'locale') . '/locale.batch.inc') ->setTitle(t('Checking translations')) ->setErrorMessage(t('Error checking translation updates.')) ->setFinishCallback('locale_translation_batch_status_finished'); - _locale_translation_batch_status_operations($batch_builder, $projects, $langcodes, $options); + + array_walk($operations, function ($operation) use ($batch_builder) { + call_user_func_array([$batch_builder, 'addOperation'], $operation); + }); return $batch_builder->toArray(); } /** - * Helper function to construct batch operations. + * Helper function to construct batch operations checking remote translation + * status. * - * This checks remote translation status. - * - * @param \Drupal\Core\Batch\BatchBuilder $batch_builder - * The batch builder to add the operations to. * @param array $projects * Array of project names to be processed. * @param array $langcodes * Array of language codes. * @param array $options * Batch processing options. + * + * @return array + * Array of batch operations. */ -function _locale_translation_batch_status_operations(BatchBuilder $batch_builder, $projects, $langcodes, $options = []) { +function _locale_translation_batch_status_operations($projects, $langcodes, $options = []) { + $operations = []; + foreach ($projects as $project) { foreach ($langcodes as $langcode) { // Check status of local and remote translation sources. - $batch_builder->addOperation( - 'locale_translation_batch_status_check', - [ - $project, $langcode, $options, - ] - ); + $operations[] = ['locale_translation_batch_status_check', [$project, $langcode, $options]]; } } + + return $operations; } /** diff --git a/core/modules/locale/locale.fetch.inc b/core/modules/locale/locale.fetch.inc index 9f60dee3ca..a1c7603700 100644 --- a/core/modules/locale/locale.fetch.inc +++ b/core/modules/locale/locale.fetch.inc @@ -42,9 +42,12 @@ function locale_translation_batch_update_build($projects = [], $langcodes = [], ->setFinishCallback('locale_translation_batch_fetch_finished'); // Check status of local and remote translation files. - _locale_translation_batch_status_operations($batch_builder, $projects, $langcodes, $status_options); + $operations = _locale_translation_batch_status_operations($projects, $langcodes, $status_options); // Download and import translations. - _locale_translation_fetch_operations($batch_builder, $projects, $langcodes, $options); + $operations = array_merge($operations, _locale_translation_fetch_operations($projects, $langcodes, $options)); + array_walk($operations, function ($operation) use ($batch_builder) { + call_user_func_array([$batch_builder, 'addOperation'], $operation); + }); return $batch_builder->toArray(); } @@ -67,21 +70,21 @@ function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $ $projects = $projects ? $projects : array_keys(locale_translation_get_projects()); $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list()); - $batch = (new BatchBuilder()) + $batch_builder = (new BatchBuilder()) ->setTitle(t('Updating translations.')) ->setErrorMessage(t('Error importing translation files')) ->setFile(drupal_get_path('module', 'locale') . '/locale.batch.inc') ->setFinishCallback('locale_translation_batch_fetch_finished'); - _locale_translation_fetch_operations($batch, $projects, $langcodes, $options); - - return $batch->toArray(); + $operations = _locale_translation_fetch_operations($projects, $langcodes, $options); + array_walk($operations, function ($operation) use ($batch_builder) { + call_user_func_array([$batch_builder, 'addOperation'], $operation); + }); + return $batch_builder->toArray(); } /** * Helper function to construct the batch operations to fetch translations. * - * @param \Drupal\Core\Batch\BatchBuilder $batch_builder - * The batch builder to add the operations to. * @param array $projects * Array of project names for which to check the state of translation files. * Defaults to all translatable projects. @@ -89,27 +92,21 @@ function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $ * Array of language codes. Defaults to all translatable languages. * @param array $options * Array of import options. + * + * @return array + * Array of batch operations. */ -function _locale_translation_fetch_operations(BatchBuilder $batch_builder, $projects, $langcodes, $options) { +function _locale_translation_fetch_operations($projects, $langcodes, $options) { + $operations = []; + foreach ($projects as $project) { foreach ($langcodes as $langcode) { if (locale_translation_use_remote_source()) { - $batch_builder->addOperation( - 'locale_translation_batch_fetch_download', - [ - $project, - $langcode, - ] - ); + $operations[] = ['locale_translation_batch_fetch_download', [$project, $langcode]]; } - $batch_builder->addOperation( - 'locale_translation_batch_fetch_import', - [ - $project, - $langcode, - $options, - ] - ); + $operations[] = ['locale_translation_batch_fetch_import', [$project, $langcode, $options]]; } } + + return $operations; } diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index 4af9a2bbe3..48e7542863 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -610,14 +610,11 @@ protected function triggerBatch(Request $request) { drupal_set_installed_schema_version($update['module'], $update['number'] - 1); unset($start[$update['module']]); } - $batch_builder->addOperation( - 'update_do_one', - [ - $update['module'], - $update['number'], - $dependency_map[$function], - ] - ); + $batch_builder->addOperation('update_do_one', [ + $update['module'], + $update['number'], + $dependency_map[$function], + ]); } } @@ -626,7 +623,7 @@ protected function triggerBatch(Request $request) { if ($post_updates) { // Now we rebuild all caches and after that execute the hook_post_update() // functions. - $batch_builder->addOperation('drupal_flush_all_caches'); + $batch_builder->addOperation('drupal_flush_all_caches', []); foreach ($post_updates as $function) { $batch_builder->addOperation('update_invoke_post_update', [$function]); } diff --git a/core/modules/update/src/Form/UpdateManagerUpdate.php b/core/modules/update/src/Form/UpdateManagerUpdate.php index 50d7d6e3bc..24c0318f28 100644 --- a/core/modules/update/src/Form/UpdateManagerUpdate.php +++ b/core/modules/update/src/Form/UpdateManagerUpdate.php @@ -376,13 +376,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ->setInitMessage($this->t('Preparing to download selected updates')) ->setFinishCallback('update_manager_download_batch_finished'); foreach ($projects as $project) { - $batch_builder->addOperation( - 'update_manager_batch_project_get', - [ - $project, - $form_state->getValue(['project_downloads', $project]), - ] - ); + $batch_builder->addOperation('update_manager_batch_project_get', [ + $project, + $form_state->getValue(['project_downloads', $project]), + ]); } batch_set($batch_builder->toArray()); } diff --git a/core/modules/update/update.authorize.inc b/core/modules/update/update.authorize.inc index 2c3b045cfe..9b33f270c2 100644 --- a/core/modules/update/update.authorize.inc +++ b/core/modules/update/update.authorize.inc @@ -43,15 +43,12 @@ function update_authorize_run_update($filetransfer, $projects) { ->setFinishCallback('update_authorize_update_batch_finished'); foreach ($projects as $project_info) { - $batch_builder->addOperation( - 'update_authorize_batch_copy_project', - [ - $project_info['project'], - $project_info['updater_name'], - $project_info['local_url'], - $filetransfer, - ] - ); + $batch_builder->addOperation('update_authorize_batch_copy_project', [ + $project_info['project'], + $project_info['updater_name'], + $project_info['local_url'], + $filetransfer, + ]); } batch_set($batch_builder->toArray());