You are here

public function MTimeProtectedFastFileStorage::garbageCollection in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php \Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage::garbageCollection()

Performs garbage collection on the storage.

The storage may choose to delete expired or invalidated items.

Overrides FileStorage::garbageCollection

File

core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php, line 155
Contains \Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage.

Class

MTimeProtectedFastFileStorage
Stores PHP code in files with securely hashed names.

Namespace

Drupal\Component\PhpStorage

Code

public function garbageCollection() {
  $flags = \FilesystemIterator::CURRENT_AS_FILEINFO;
  $flags += \FilesystemIterator::SKIP_DOTS;
  foreach ($this
    ->listAll() as $name) {
    $directory = $this
      ->getContainingDirectoryFullPath($name);
    try {
      $dir_iterator = new \FilesystemIterator($directory, $flags);
    } catch (\UnexpectedValueException $e) {

      // FilesystemIterator throws an UnexpectedValueException if the
      // specified path is not a directory, or if it is not accessible.
      continue;
    }
    $directory_unlink = TRUE;
    $directory_mtime = filemtime($directory);
    foreach ($dir_iterator as $fileinfo) {
      if ($directory_mtime > $fileinfo
        ->getMTime()) {

        // Ensure the folder is writable.
        @chmod($directory, 0777);
        @unlink($fileinfo
          ->getPathName());
      }
      else {

        // The directory still contains valid files.
        $directory_unlink = FALSE;
      }
    }
    if ($directory_unlink) {
      $this
        ->unlink($name);
    }
  }
}