You are here

protected function CleanFilesCommand::execute in Tome 8

File

modules/tome_sync/src/Commands/CleanFilesCommand.php, line 81

Class

CleanFilesCommand
Contains the tome:clean-files command.

Namespace

Drupal\tome_sync\Commands

Code

protected function execute(InputInterface $input, OutputInterface $output) {
  $this
    ->io()
    ->writeLn('Searching for unused files...');
  $files = $this
    ->getUnusedFiles();
  if (empty($files)) {
    $this
      ->io()
      ->success('No unused files found.');
    return 0;
  }
  $this
    ->io()
    ->listing($files);
  if (!$this
    ->io()
    ->confirm('The files listed above will be deleted.', FALSE)) {
    return 0;
  }
  foreach ($files as $uuid => $filename) {
    $this->contentStorage
      ->delete("file.{$uuid}");
    $this
      ->unIndexContentByName("file.{$uuid}");
    $this->fileSync
      ->deleteFile($filename);
  }
  $this
    ->io()
    ->success('Deleted all unused files.');
}