function advagg_insert_bundle_db in Advanced CSS/JS Aggregation 6
Same name and namespace in other branches
- 7 advagg.module \advagg_insert_bundle_db()
Insert info into the advagg_files and advagg_bundles database.
Parameters
$files: List of files in the proposed bundle.
$filetype: css or js.
$bundle_md5: Bundle's machine name.
$root: Is this a root bundle.
1 call to advagg_insert_bundle_db()
- advagg_get_filename in ./
advagg.module - Given a list of files; return back the aggregated filename.
File
- ./
advagg.module, line 1175 - Advanced CSS/JS aggregation module
Code
function advagg_insert_bundle_db($files, $filetype, $bundle_md5, $root) {
$lock_name = 'advagg_insert_bundle_db' . $bundle_md5;
if (!lock_acquire($lock_name)) {
// If using async, wait before returning to give the other request time
// to complete.
if (variable_get('advagg_aggregate_mode', ADVAGG_AGGREGATE_MODE) < 2) {
lock_wait($lock_name);
}
return;
}
// Double check that the bundle doesn't exist now that we are in a lock.
$bundle_exists = db_result(db_query("SELECT 1 FROM {advagg_bundles} WHERE bundle_md5 = '%s'", $bundle_md5));
if ($bundle_exists) {
lock_release($lock_name);
return;
}
foreach ($files as $order => $filename) {
$filename_md5 = md5($filename);
// Insert file into the advagg_files table if it doesn't exist.
$checksum = db_result(db_query("SELECT checksum FROM {advagg_files} WHERE filename_md5 = '%s'", $filename_md5));
if (empty($checksum)) {
$checksum = advagg_checksum($filename);
db_query("INSERT INTO {advagg_files} (filename, filename_md5, checksum, filetype, filesize) VALUES ('%s', '%s', '%s', '%s', %d)", $filename, $filename_md5, $checksum, $filetype, @filesize($filename));
}
// Create the entries in the advagg_bundles table.
db_query("INSERT INTO {advagg_bundles} (bundle_md5, filename_md5, counter, porder, root, timestamp) VALUES ('%s', '%s', '%d', '%d', '%d', '%d')", $bundle_md5, $filename_md5, 0, $order, $root, time());
}
lock_release($lock_name);
}