You are here

function advagg_bundle_built in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7 advagg.module \advagg_bundle_built()

See if this bundle has been built.

Parameters

$filepath: filename

Return value

Boolean indicating if the bundle already exists.

1 call to advagg_bundle_built()
advagg_css_js_file_builder in ./advagg.module
Aggregate CSS/JS files, putting them in the files directory.

File

./advagg.module, line 1520
Advanced CSS/JS aggregation module

Code

function advagg_bundle_built($filepath) {

  // Don't use the cache if not selected.
  if (!variable_get('advagg_bundle_built_mode', ADVAGG_BUNDLE_BUILT_MODE)) {
    advagg_clearstatcache(TRUE, $filepath);
    return file_exists($filepath);
  }
  $data = advagg_get_bundle_from_filename(basename($filepath));
  if (is_array($data)) {
    list($type, $md5, $counter) = $data;
  }
  else {
    return FALSE;
  }
  $data = cache_get($filepath, 'cache_advagg');
  if (isset($data->data)) {

    // Refresh timestamp if older then 12 hours.
    if (time() - $data->data > variable_get('advagg_file_last_used_interval', ADVAGG_FILE_LAST_USED_INTERVAL)) {
      cache_set($filepath, time(), 'cache_advagg', CACHE_PERMANENT);
      db_query("UPDATE {advagg_bundles} SET timestamp = %d WHERE bundle_md5 = '%s'", time(), $md5);
    }
    return TRUE;
  }

  // If not in cache check disk.
  advagg_clearstatcache(TRUE, $filepath);
  if (file_exists($filepath)) {
    if (@filesize($filepath) == 0) {
      return FALSE;
    }
  }
  else {
    return FALSE;
  }

  // File existed on disk; place in cache.
  cache_set($filepath, time(), 'cache_advagg', CACHE_PERMANENT);
  db_query("UPDATE {advagg_bundles} SET timestamp = %d WHERE bundle_md5 = '%s'", time(), $md5);
  return TRUE;
}