function advagg_update_6108 in Advanced CSS/JS Aggregation 6
Update 6108 - Add new field & add indexes to advagg_bundles table.
File
- ./
advagg.install, line 879 - Handles Advanced Aggregation installation and upgrade tasks.
Code
function advagg_update_6108() {
$ret = array();
// Make sure the advagg_get_root_files_dir function is available.
drupal_load('module', 'advagg');
// Add in timestamp column.
db_add_field($ret, 'advagg_bundles', 'timestamp', array(
'description' => 'Last used timestamp of the bundle.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
// Add in indexes.
db_add_index($ret, 'advagg_bundles', 'root', array(
'root',
));
db_add_index($ret, 'advagg_bundles', 'timestamp', array(
'timestamp',
));
db_add_index($ret, 'advagg_bundles', 'counter', array(
'counter',
));
// Populate timestamps.
list($css_path, $js_path) = advagg_get_root_files_dir();
$results = db_query("\n SELECT\n ab.bundle_md5,\n ab.counter,\n af.filetype\n FROM {advagg_bundles} AS ab\n INNER JOIN {advagg_files} AS af USING ( filename_md5 )\n GROUP BY bundle_md5 , ab.counter, af.filetype");
while ($row = db_fetch_array($results)) {
$filename = advagg_build_filename($row['filetype'], $row['bundle_md5'], $row['counter']);
if ($row['filetype'] == 'css') {
$file_type_path = $css_path;
}
else {
$file_type_path = $js_path;
}
$filepath = $file_type_path . '/' . $filename;
$data = cache_get($filepath, 'cache_advagg');
if (!empty($data->data)) {
// Set timestamp if it exists in the cache.
// Not using update_sql() so we can pass in % arguments.
db_query("UPDATE {advagg_bundles} SET timestamp = %d WHERE bundle_md5 = '%s'", $data->data, $row['bundle_md5']);
$ret[] = array(
'success' => TRUE,
'query' => 'Timestamp added for: ' . $filename . '.',
);
}
else {
$ret[] = array(
'success' => TRUE,
'query' => 'No timestamp found for: ' . $filename . '.',
);
}
}
$cache_tables = advagg_flush_caches();
foreach ($cache_tables as $table) {
cache_clear_all('*', $table, TRUE);
}
$ret[] = array(
'success' => TRUE,
'query' => 'AdvAgg Caches Flushed.',
);
return $ret;
}