Commit c5886a79 authored by catch's avatar catch
Browse files

Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9,...

Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
parent d3dabc46
Loading
Loading
Loading
Loading
+9 −11
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Drupal\config\StorageReplaceDataWrapper;
use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\ConfigImporterException;
use Drupal\Core\Config\ConfigManagerInterface;
@@ -411,19 +412,16 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    else {
      try {
        $sync_steps = $config_importer->initialize();
        $batch = [
          'operations' => [],
          'finished' => [ConfigImporterBatch::class, 'finish'],
          'title' => $this->t('Importing configuration'),
          'init_message' => $this->t('Starting configuration import.'),
          'progress_message' => $this->t('Completed @current step of @total.'),
          'error_message' => $this->t('Configuration import has encountered an error.'),
        ];
        $batch_builder = (new BatchBuilder())
          ->setTitle($this->t('Importing configuration'))
          ->setFinishCallback([ConfigImporterBatch::class, 'finish'])
          ->setInitMessage($this->t('Starting configuration import.'))
          ->setProgressMessage($this->t('Completed @current step of @total.'))
          ->setErrorMessage($this->t('Configuration import has encountered an error.'));
        foreach ($sync_steps as $sync_step) {
          $batch['operations'][] = [[ConfigImporterBatch::class, 'process'], [$config_importer, $sync_step]];
          $batch_builder->addOperation([ConfigImporterBatch::class, 'process'], [$config_importer, $sync_step]);
        }

        batch_set($batch);
        batch_set($batch_builder->toArray());
      }
      catch (ConfigImporterException $e) {
        // There are validation errors.
+9 −10
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\config\Form;

use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Config\ConfigImporterException;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\Importer\ConfigImporterBatch;
@@ -364,19 +365,17 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    else {
      try {
        $sync_steps = $config_importer->initialize();
        $batch = [
          'operations' => [],
          'finished' => [ConfigImporterBatch::class, 'finish'],
          'title' => $this->t('Synchronizing configuration'),
          'init_message' => $this->t('Starting configuration synchronization.'),
          'progress_message' => $this->t('Completed step @current of @total.'),
          'error_message' => $this->t('Configuration synchronization has encountered an error.'),
        ];
        $batch_builder = (new BatchBuilder())
          ->setTitle($this->t('Synchronizing configuration'))
          ->setFinishCallback([ConfigImporterBatch::class, 'finish'])
          ->setInitMessage($this->t('Starting configuration synchronization.'))
          ->setProgressMessage($this->t('Completed step @current of @total.'))
          ->setErrorMessage($this->t('Configuration synchronization has encountered an error.'));
        foreach ($sync_steps as $sync_step) {
          $batch['operations'][] = [[ConfigImporterBatch::class, 'process'], [$config_importer, $sync_step]];
          $batch_builder->addOperation([ConfigImporterBatch::class, 'process'], [$config_importer, $sync_step]);
        }

        batch_set($batch);
        batch_set($batch_builder->toArray());
      }
      catch (ConfigImporterException $e) {
        // There are validation errors.
+20 −26
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * Mass import-export and batch import functionality for Gettext .po files.
 */

use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Url;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\Language\LanguageInterface;
@@ -143,28 +144,24 @@ function locale_translate_batch_build(array $files, array $options) {
    'finish_feedback' => TRUE,
  ];
  if (count($files)) {
    $operations = [];
    $batch_builder = (new BatchBuilder())
      ->setFile(drupal_get_path('module', 'locale') . '/locale.bulk.inc')
      ->setTitle(t('Importing interface translations'))
      ->setErrorMessage(t('Error importing interface translations'));
    foreach ($files as $file) {
      // We call locale_translate_batch_import for every batch operation.
      $operations[] = ['locale_translate_batch_import', [$file, $options]];
      $batch_builder->addOperation('locale_translate_batch_import', [$file, $options]);
    }
    // Save the translation status of all files.
    $operations[] = ['locale_translate_batch_import_save', []];
    $batch_builder->addOperation('locale_translate_batch_import_save', []);

    // Add a final step to refresh JavaScript and configuration strings.
    $operations[] = ['locale_translate_batch_refresh', []];

    $batch = [
      'operations'    => $operations,
      'title'         => t('Importing interface translations'),
      'progress_message' => '',
      'error_message' => t('Error importing interface translations'),
      'file'          => drupal_get_path('module', 'locale') . '/locale.bulk.inc',
    ];
    $batch_builder->addOperation('locale_translate_batch_refresh', []);

    if ($options['finish_feedback']) {
      $batch['finished'] = 'locale_translate_batch_finished';
      $batch_builder->setFinishCallback('locale_translate_batch_finished');
    }
    return $batch;
    return $batch_builder->toArray();
  }
  return FALSE;
}
@@ -569,9 +566,13 @@ function locale_config_batch_update_components(array $options, array $langcodes
 */
function locale_config_batch_build(array $names, array $langcodes, array $options = []) {
  $options += ['finish_feedback' => TRUE];
  $batch_builder = (new BatchBuilder())
    ->setFile(drupal_get_path('module', 'locale') . '/locale.bulk.inc')
    ->setTitle(t('Updating configuration translations'))
    ->setInitMessage(t('Starting configuration update'))
    ->setErrorMessage(t('Error updating configuration translations'));
  $i = 0;
  $batch_names = [];
  $operations = [];
  foreach ($names as $name) {
    $batch_names[] = $name;
    $i++;
@@ -580,24 +581,17 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
    // request. We batch a small number of configuration object upgrades
    // together to improve the overall performance of the process.
    if ($i % 20 == 0) {
      $operations[] = ['locale_config_batch_refresh_name', [$batch_names, $langcodes]];
      $batch_builder->addOperation('locale_config_batch_refresh_name', [$batch_names, $langcodes]);
      $batch_names = [];
    }
  }
  if (!empty($batch_names)) {
    $operations[] = ['locale_config_batch_refresh_name', [$batch_names, $langcodes]];
  }
  $batch = [
    'operations'    => $operations,
    'title'         => t('Updating configuration translations'),
    'init_message'  => t('Starting configuration update'),
    'error_message' => t('Error updating configuration translations'),
    'file'          => drupal_get_path('module', 'locale') . '/locale.bulk.inc',
  ];
    $batch_builder->addOperation('locale_config_batch_refresh_name', [$batch_names, $langcodes]);
  }
  if (!empty($options['finish_feedback'])) {
    $batch['completed'] = 'locale_config_batch_finished';
    $batch_builder->setFinishCallback('locale_config_batch_finished');
  }
  return $batch;
  return $batch_builder->toArray();
}

/**
+12 −9
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * The API for comparing project translation status with available translation.
 */

use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Utility\ProjectInfo;

/**
@@ -238,15 +239,17 @@ function locale_translation_batch_status_build($projects = [], $langcodes = [])

  $operations = _locale_translation_batch_status_operations($projects, $langcodes, $options);

  $batch = [
    'operations' => $operations,
    'title' => t('Checking translations'),
    'progress_message' => '',
    'finished' => 'locale_translation_batch_status_finished',
    'error_message' => t('Error checking translation updates.'),
    'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
  ];
  return $batch;
  $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');

  array_walk($operations, function ($operation) use ($batch_builder) {
    call_user_func_array([$batch_builder, 'addOperation'], $operation);
  });

  return $batch_builder->toArray();
}

/**
+21 −18
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@
 * The API for download and import of translations from remote and local sources.
 */

use Drupal\Core\Batch\BatchBuilder;

/**
 * Load the common translation API.
 */
@@ -33,20 +35,20 @@ function locale_translation_batch_update_build($projects = [], $langcodes = [],
  $status_options = $options;
  $status_options['finish_feedback'] = FALSE;

  $batch_builder = (new BatchBuilder())
    ->setFile(drupal_get_path('module', 'locale') . '/locale.batch.inc')
    ->setTitle(t('Updating translations'))
    ->setErrorMessage(t('Error importing translation files'))
    ->setFinishCallback('locale_translation_batch_fetch_finished');
  // Check status of local and remote translation files.
  $operations = _locale_translation_batch_status_operations($projects, $langcodes, $status_options);
  // Download and import translations.
  $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);
  });

  $batch = [
    'operations' => $operations,
    'title' => t('Updating translations'),
    'progress_message' => '',
    'error_message' => t('Error importing translation files'),
    'finished' => 'locale_translation_batch_fetch_finished',
    'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
  ];
  return $batch;
  return $batch_builder->toArray();
}

/**
@@ -67,15 +69,16 @@ 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 = [
    'operations' => _locale_translation_fetch_operations($projects, $langcodes, $options),
    'title' => t('Updating translations.'),
    'progress_message' => '',
    'error_message' => t('Error importing translation files'),
    'finished' => 'locale_translation_batch_fetch_finished',
    'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
  ];
  return $batch;
  $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');
  $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();
}

/**
Loading