You are here

public function JsCollectionOptimizer::deleteStale in Advanced CSS/JS Aggregation 8.2

Delete stale optimized collection assets.

File

src/Asset/JsCollectionOptimizer.php, line 214

Class

JsCollectionOptimizer

Namespace

Drupal\advagg\Asset

Code

public function deleteStale() {
  $log = [];
  $this->state
    ->delete('system.js_cache_files');
  Cache::invalidateTags([
    'library_info',
  ]);
  $delete_stale = function ($uri) use (&$log) {

    // Default stale file threshold is 30 days.
    if (REQUEST_TIME - fileatime($uri) > $this->systemConfig
      ->get('stale_file_threshold')) {
      file_unmanaged_delete($uri);
      $log[] = $uri;
    }
  };
  file_scan_directory($this->dumper
    ->preparePath('js'), '/.*/', [
    'callback' => $delete_stale,
  ]);
  return $log;
}