You are here

public static function NodeRevisionGenerateBatch::finish in Node Revision Delete 8

Actions on finishing the batch.

Parameters

bool $success: The flag to identify if batch has successfully run or not.

array $results: The results from running context.

array $operations: The array of operations remained unprocessed.

File

modules/node_revision_generate/src/NodeRevisionGenerateBatch.php, line 57

Class

NodeRevisionGenerateBatch
Methods for generate revisions in a batch.

Namespace

Drupal\node_revision_generate

Code

public static function finish($success, array $results, array $operations) {
  $messenger = \Drupal::messenger();
  $logger = \Drupal::logger('node_revision_generate');
  if ($success) {
    $logger
      ->notice(t('@total revisions generated for nodes', [
      '@total' => $results['revisions'],
    ]));
    $success_message = \Drupal::translation()
      ->formatPlural($results['revisions'], 'One revision has been created for the selected content types.', 'A total of @count revisions were created for the selected content types.', [
      '@total' => $results['revisions'],
    ]);
    $messenger
      ->addMessage($success_message);
    $messenger
      ->addWarning(t('Revisions were generated up to the current date, no revisions were generated with a date in the future. So, depending on this maybe we will not generate the number of revisions you expect.'));
  }
  else {

    // An error occurred.
    // $operations contains the operations that remained unprocessed.
    $error_operation = reset($operations);
    $message = t('An error occurred while processing %error_operation with arguments: @arguments', [
      '%error_operation' => $error_operation[0],
      '@arguments' => print_r($error_operation[1], TRUE),
    ]);
    $logger
      ->error($message);
    $messenger
      ->addError($message);
  }
}