You are here

public static function ScannerConfirmForm::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/ScannerConfirmForm.php, line 160

Class

ScannerConfirmForm
Form for configure messages.

Namespace

Drupal\scanner\Form

Code

public static function batchFinished($success, $results, $operations) {
  $count = 0;
  $messenger = \Drupal::messenger();
  if ($success) {
    if (!empty($results['data'])) {
      foreach ($results['data'] as $value) {
        if (count($value) == 2) {
          $count++;
        }
        else {

          // Something went wrong.
          \Drupal::logger('scanner')
            ->error('An issue has occured during the replace operation.');
        }
      }
      $results['count'] = $count;
      $messenger
        ->addMessage(t('@count entities processed.', [
        '@count' => $count,
      ]));
      $connection = \Drupal::service('database');

      // Insert to row into the scanner table so that the
      // action can be undone in the future.
      $connection
        ->insert('scanner')
        ->fields([
        'undo_data' => serialize($results['data']),
        'undone' => 0,
        'searched' => $results['inputs']['search'],
        'replaced' => $results['inputs']['replace'],
        'count' => $count,
        'time' => \Drupal::time()
          ->getRequestTime(),
      ])
        ->execute();
    }
  }
  else {
    $message = t('There were some errors.');
    $messenger
      ->addMessage($message);
  }
}