You are here

function advagg_delete_files_if_stale in Advanced CSS/JS Aggregation 7.2

Given an array of files remove that file if atime is grater than 30 days.

Parameters

array $files: Array of files returned by file_scan_directory.

Return value

array Array of files that got removed.

1 call to advagg_delete_files_if_stale()
advagg_delete_stale_aggregates in ./advagg.cache.inc
Scan CSS/JS advagg dir and remove that file if atime is grater than 30 days.

File

./advagg.cache.inc, line 259
Advanced CSS/JS aggregation module.

Code

function advagg_delete_files_if_stale(array $files) {

  // Array used to record what files were deleted.
  $kill_list = array();
  foreach ($files as $uri => $file) {

    // Get info on file.
    $filename = $file->filename;
    $data = advagg_get_hashes_from_filename($filename);
    if (is_array($data)) {
      list(, $aggregate_filenames_hash, $aggregate_contents_hash) = $data;
    }
    else {

      // Can not get data on file, remove it.
      $kill_list[] = advagg_delete_file_by_uri($uri);
      continue;
    }

    // Get atime of file.
    $atime = advagg_get_atime($aggregate_filenames_hash, $aggregate_contents_hash, $uri);
    if (empty($atime)) {
      $kill_list[] = advagg_delete_file_by_uri($uri);
      continue;
    }

    // Default stale file threshold is 30 days.
    if (REQUEST_TIME - $atime > variable_get('drupal_stale_file_threshold', 2592000)) {
      $kill_list[] = advagg_delete_file_by_uri($uri);
      continue;
    }
  }

  // Let other modules know about the removed files.
  // Call hook_advagg_removed_aggregates().
  module_invoke_all('advagg_removed_aggregates', $kill_list);
  return $kill_list;
}