Delete old optimized collection assets.

File

src/Asset/JsCollectionOptimizer.php, line 232

Class

JsCollectionOptimizer

Namespace

Drupal\advagg\Asset

Code

public function deleteOld() {
    $log = [];
    $this->state
        ->delete('system.js_cache_files');
    Cache::invalidateTags([
        'library_info',
    ]);
    $delete_old = function ($uri) use (&$log) {
        // Default stale file threshold is 30 days.
        // Delete old if > 3 times that.
        if (REQUEST_TIME - filemtime($uri) > $this->systemConfig
            ->get('stale_file_threshold') * 3) {
            file_unmanaged_delete($uri);
            $log[] = $uri;
        }
    };
    file_scan_directory($this->dumper
        ->preparePath('js'), '/.*/', [
        'callback' => $delete_old,
    ]);
    return $log;
}