You are here

function advagg_generate_advagg_filename_from_db in Advanced CSS/JS Aggregation 7.2

Given a advagg type this will return the most recent aggregate from the db.

Parameters

string $type: String: css or js.

Return value

string Returns advagg filename or an empty string on failure.

2 calls to advagg_generate_advagg_filename_from_db()
advagg_get_relative_path in ./advagg.module
Given a uri, get the relative_path.
advagg_install_get_first_advagg_file in ./advagg.install
Given a advagg path this will return the first aggregate it can find.

File

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

Code

function advagg_generate_advagg_filename_from_db($type) {

  // Get the most recently accessed file from the database.
  $query = db_select('advagg_aggregates_versions', 'aav');
  $query
    ->join('advagg_aggregates', 'aa', 'aa.aggregate_filenames_hash =
    aav.aggregate_filenames_hash');
  $query
    ->join('advagg_files', 'af', 'af.filename_hash = aa.filename_hash AND
    af.filetype = :type', array(
    ':type' => $type,
  ));
  $query = $query
    ->fields('aav', array(
    'aggregate_filenames_hash',
    'aggregate_contents_hash',
  ))
    ->orderBy('atime', 'DESC')
    ->range(0, 1);
  $results = $query
    ->execute();
  if (empty($results)) {
    return '';
  }
  $hooks_hash = advagg_get_current_hooks_hash();
  foreach ($results as $row) {
    return $type . ADVAGG_SPACE . $row->aggregate_filenames_hash . ADVAGG_SPACE . $row->aggregate_contents_hash . ADVAGG_SPACE . $hooks_hash . '.' . $type;
  }
}