You are here

public function FancyFileDeleteCommands::fileDelete in Fancy File Delete 2.0.x

Deletes any number of files by fid or path.

@option force Forcefully remove the file, even if it is still being referenced.

@command fancy:file-delete @aliases ffd,fancy-file-delete

Parameters

$file_list: A comma separate list of file ID's OR. relative paths to any files you wish to delete.

array $options: An associative array of options whose values come from cli.

File

src/Commands/FancyFileDeleteCommands.php, line 46

Class

FancyFileDeleteCommands
Class FancyFileDeleteCommands

Namespace

Drupal\fancy_file_delete\Commands

Code

public function fileDelete($file_list, array $options = [
  'force' => FALSE,
]) {

  // Prompt user for confirmation.
  $confirm = $this
    ->io()
    ->confirm('WARNING! Are you sure you want to delete these files?');
  if (!$confirm) {
    throw new UserAbortException();
  }

  // Initialize our batch operations.
  $files = explode(',', $file_list);
  $values = [];
  foreach ($files as $file) {
    $values[] = $file;
  }
  $this->batch
    ->setBatch($values, $options['force'], FALSE);
}