You are here

AcsfDuplicationScrubTemporaryFilesHandler.php in Acquia Cloud Site Factory Connector 8.2

Same filename and directory in other branches
  1. 8 src/Event/AcsfDuplicationScrubTemporaryFilesHandler.php

Namespace

Drupal\acsf\Event

File

src/Event/AcsfDuplicationScrubTemporaryFilesHandler.php
View source
<?php

namespace Drupal\acsf\Event;


/**
 * Handles the scrubbing of Drupal temporary files.
 */
class AcsfDuplicationScrubTemporaryFilesHandler extends AcsfEventHandler {

  /**
   * Implements AcsfEventHandler::handle().
   */
  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();
    }
  }

}

Classes

Namesort descending Description
AcsfDuplicationScrubTemporaryFilesHandler Handles the scrubbing of Drupal temporary files.