You are here

public function FancyFileDeleteBatch::setBatch in Fancy File Delete 2.0.x

Sets the batch operations.

Parameters

array $values: The array of values we are looking to set in the batch.

bool $force: If we are forcing the delete.

bool $ui: If we are running this through the UI or CLI.

File

src/FancyFileDeleteBatch.php, line 93

Class

FancyFileDeleteBatch
Class FancyFileDeleteBatch.

Namespace

Drupal\fancy_file_delete

Code

public function setBatch($values, $force, $ui = TRUE) {

  // Sets up our batch.
  $batch_builder = new BatchBuilder();
  $batch_builder
    ->setTitle($this
    ->t('Deleting Files...'))
    ->setInitMessage($this
    ->t('Fun Stuff is Happening...'))
    ->setErrorMessage($this
    ->t('Fancy File Delete has encountered an error.'))
    ->setFinishCallback([
    $this,
    'finish',
  ]);
  foreach ($values as $value) {
    $batch_builder
      ->addOperation([
      $this,
      'process',
    ], [
      $value,
      $force,
    ]);
  }

  // Engage.
  batch_set($batch_builder
    ->toArray());
  if (!$ui) {
    $batch =& batch_get();
    $batch['progressive'] = FALSE;

    // Start the process.
    drush_backend_batch_process();
  }
}