You are here

public function NodeRevisionDelete::getRevisionDeletionBatch in Node Revision Delete 8

Return the revision deletion batch definition.

Parameters

array $revisions: The revisions array.

bool $dry_run: The dry run option.

Return value

array The batch definition.

Overrides NodeRevisionDeleteInterface::getRevisionDeletionBatch

File

src/NodeRevisionDelete.php, line 499

Class

NodeRevisionDelete
Class NodeRevisionDelete.

Namespace

Drupal\node_revision_delete

Code

public function getRevisionDeletionBatch(array $revisions, $dry_run) {

  // Defining the batch builder.
  $batch_builder = new BatchBuilder();
  $batch_builder
    ->setTitle($this
    ->t('Deleting revisions'))
    ->setInitMessage($this
    ->t('Starting to delete revisions.'))
    ->setProgressMessage($this
    ->t('Deleted @current out of @total (@percentage%). Estimated time: @estimate.'))
    ->setErrorMessage($this
    ->t('Error deleting revisions.'))
    ->setFinishCallback([
    NodeRevisionDeleteBatch::class,
    'finish',
  ]);

  // Loop through the revisions to delete, create batch operations array.
  foreach ($revisions as $revision) {

    // Adding the operation.
    $batch_builder
      ->addOperation([
      NodeRevisionDeleteBatch::class,
      'deleteRevision',
    ], [
      $revision,
      $dry_run,
    ]);
  }
  return $batch_builder
    ->toArray();
}