You are here

public function AcsfDuplicationScrubTemporaryFilesHandler::handle in Acquia Cloud Site Factory Connector 8.2

Same name and namespace in other branches
  1. 8 src/Event/AcsfDuplicationScrubTemporaryFilesHandler.php \Drupal\acsf\Event\AcsfDuplicationScrubTemporaryFilesHandler::handle()

Implements AcsfEventHandler::handle().

Overrides AcsfEventHandler::handle

File

src/Event/AcsfDuplicationScrubTemporaryFilesHandler.php, line 13

Class

AcsfDuplicationScrubTemporaryFilesHandler
Handles the scrubbing of Drupal temporary files.

Namespace

Drupal\acsf\Event

Code

public function handle() {
  $this
    ->consoleLog(dt('Entered @class', [
    '@class' => get_class($this),
  ]));
  $file_storage = \Drupal::entityTypeManager()
    ->getStorage('file');

  // Remove all temporary files. As in file_cron(), temporary is encoded as
  // "<> FILE_STATUS_PERMANENT".
  $fids = $file_storage
    ->getQuery()
    ->condition('status', FILE_STATUS_PERMANENT, '<>')
    ->range(0, 1000)
    ->execute();
  $files = $file_storage
    ->loadMultiple($fids);
  foreach ($files as $file) {
    $file
      ->delete();
  }
}