You are here

class FancyFileDeleteCommands in Fancy File Delete 2.0.x

Class FancyFileDeleteCommands

Hierarchy

Expanded class hierarchy of FancyFileDeleteCommands

1 string reference to 'FancyFileDeleteCommands'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses FancyFileDeleteCommands
fancy_file_delete.commands in ./drush.services.yml
\Drupal\fancy_file_delete\Commands\FancyFileDeleteCommands

File

src/Commands/FancyFileDeleteCommands.php, line 12

Namespace

Drupal\fancy_file_delete\Commands
View source
class FancyFileDeleteCommands extends DrushCommands {

  /**
   * The Batch Service.
   *
   * @var \Drupal\fancy_file_delete\FancyFileDeleteBatch
   */
  protected $batch;

  /**
   * Constructs a new FancyFileDeleteCommands.
   *
   * @param \Drupal\fancy_file_delete\FancyFileDeleteBatch
   *   The Batch Service.
   */
  public function __construct(FancyFileDeleteBatch $batch) {
    parent::__construct();
    $this->batch = $batch;
  }

  /**
   * Deletes any number of files by fid or path.
   *
   * @param $file_list
   *   A comma separate list of file ID's OR.
   *   relative paths to any files you wish to delete.
   * @param array $options
   *   An associative array of options whose values come from cli.
   * @option force
   *   Forcefully remove the file, even if it is still being referenced.
   *
   * @command fancy:file-delete
   * @aliases ffd,fancy-file-delete
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FancyFileDeleteCommands::$batch protected property The Batch Service.
FancyFileDeleteCommands::fileDelete public function Deletes any number of files by fid or path.
FancyFileDeleteCommands::__construct public function Constructs a new FancyFileDeleteCommands.