You are here

function advagg_get_atime in Advanced CSS/JS Aggregation 7.2

Read the atime value for the given aggregate.

Parameters

string $aggregate_filenames_hash: Hash of the groupings of files.

string $aggregate_contents_hash: Hash of the files contents.

string $uri: URI pointing to the aggregate file.

Return value

mixed File atime or FALSE if not found.

2 calls to advagg_get_atime()
advagg_admin_get_file_info in ./advagg.admin.inc
Get detailed info about the given filename.
advagg_delete_files_if_stale in ./advagg.cache.inc
Given an array of files remove that file if atime is grater than 30 days.

File

./advagg.missing.inc, line 1512
Advanced CSS/JS aggregation module.

Code

function advagg_get_atime($aggregate_filenames_hash, $aggregate_contents_hash, $uri) {

  // Try to use the cache to avoid hitting the database with a select query.
  $cache_id = 'advagg:db:' . $aggregate_filenames_hash . ADVAGG_SPACE . $aggregate_contents_hash;
  $cache = cache_get($cache_id, 'cache_advagg_info');
  if ($cache) {

    // If the atime in the cache is less than 12 hours old, use that.
    if (!empty($cache->data['atime']) && $cache->data['atime'] > REQUEST_TIME - 12 * 60 * 60) {
      return $cache->data['atime'];
    }
  }

  // Try to get the atime from the DB.
  $atime = db_select('advagg_aggregates_versions', 'aav')
    ->fields('aav', array(
    'atime',
  ))
    ->condition('aav.aggregate_filenames_hash', $aggregate_filenames_hash)
    ->condition('aav.aggregate_contents_hash', $aggregate_contents_hash)
    ->execute()
    ->fetchField();
  if (!empty($atime)) {
    return $atime;
  }

  // Return the atime from disk as a last resort.
  if (file_exists($uri)) {
    return fileatime($uri);
  }

  // No atime was found, return FALSE.
  return FALSE;
}