You are here

public function BatchGenerator::createBatch in User Merge 2.x

Performs an operation to several values in a batch.

Overrides BatchGeneratorInterface::createBatch

File

src/BatchGenerator.php, line 81

Class

BatchGenerator
Class BatchGenerator.

Namespace

Drupal\usermerge

Code

public function createBatch() : void {
  $batch = [
    'title' => $this
      ->t('Merge account…'),
    'init_message' => $this
      ->t('Starting merge process.'),
    'progress_message' => $this
      ->t('Completed step @current of @total.'),
    'error_message' => $this
      ->t('There was an error in the merge process.'),
    'operations' => [],
    'finished' => [
      $this,
      'batchFinished',
    ],
    'progressive' => TRUE,
  ];
  $retain_id = $this->multiStepStorage
    ->getValueFromStore('', 'retain');
  $retire_id = $this->multiStepStorage
    ->getValueFromStore('', 'retire');
  $definitions = $this->userMerger
    ->getPropertyPlugins();
  foreach ($definitions as $plugin_id) {
    $settings = $this->multiStepStorage
      ->getValuesFromStore($plugin_id);
    $batch['operations'][] = [
      [
        $this,
        'performPropertyProcess',
      ],
      [
        $plugin_id,
        $retire_id,
        $retain_id,
        $settings,
      ],
    ];
    $this->multiStepStorage
      ->delete($plugin_id);
  }

  // Perform action.
  $batch['operations'][] = [
    [
      $this,
      'performActionProcess',
    ],
    [
      $this->multiStepStorage
        ->getValueFromStore('', 'action'),
      $retire_id,
      $retain_id,
    ],
  ];
  $this->multiStepStorage
    ->delete('');
  batch_set($batch);
}