You are here

public static function ScannerForm::batchFinished in Search and Replace Scanner 8

The batch process has finished.

Parameters

bool $success: Indicates whether the batch process finish successfully.

array $results: Contains the output from the batch operations.

array $operations: A list of operations that were processed.

File

src/Form/ScannerForm.php, line 282

Class

ScannerForm
Form for performing searching.

Namespace

Drupal\scanner\Form

Code

public static function batchFinished($success, $results, $operations) {
  if ($success && isset($results['count'])) {
    $count = $results['count'];
    $count_for_theme = NULL;
    if (isset($results['count']['matches'])) {

      // Handle regex results.
      $count_for_theme = $results['count']['matches'];
    }
    elseif (isset($results['count']['entities'])) {

      // Handle other results.
      $count_for_theme = $results['count']['entities'];
    }
    else {

      // Handle other results.
      $count_for_theme = $results['count'];
    }

    // $count expected to be a numerical value.
    unset($results['count']);
    $renderable = [
      '#theme' => 'scanner_results',
      '#data' => [
        'values' => $results,
        'count' => $count_for_theme,
      ],
    ];
    $scannerStore = \Drupal::service('tempstore.private')
      ->get('scanner');

    // Persist the results to the tempstore.
    $scannerStore
      ->set('results', $renderable);
  }
  else {
    \Drupal::messenger()
      ->addMessage(t('There were some errors.'));
  }
  if (!isset($count['matches'])) {
    $count['matches'] = 0;
    $count['entities'] = 0;
  }
  \Drupal::messenger()
    ->addMessage(t('Found @matches matches in @entities entities.', [
    '@matches' => $count['matches'],
    '@entities' => $count['entities'],
  ]));
}