function views_data_export_garbage_collect in Views data export 7.4
Same name and namespace in other branches
- 6.3 views_data_export.module \views_data_export_garbage_collect()
- 6 views_data_export.module \views_data_export_garbage_collect()
- 6.2 views_data_export.module \views_data_export_garbage_collect()
- 7 views_data_export.module \views_data_export_garbage_collect()
- 7.3 views_data_export.module \views_data_export_garbage_collect()
Removes any temporary index tables that have been left behind. This is caused by batch processes which are started but never finished.
Removes all trace of exports from the database that were created more than $expires seconds ago
Parameters
$expires: Seconds ago. Defaults to that given in the settings.
$chunk: The number of tables to test for and delete. Defaults to that given in the settings. Pass -1 for this setting to remove any restriction and to garbage collect all exports.
2 calls to views_data_export_garbage_collect()
- views_data_export_cron in ./
views_data_export.module - Implementation of hook_cron().
- views_data_export_uninstall in ./
views_data_export.install - Implementation of hook_uninstall()
File
- ./
views_data_export.module, line 95 - Provides the ability to export to specific
Code
function views_data_export_garbage_collect($expires = NULL, $chunk = NULL) {
if (lock_acquire('views_data_export_gc')) {
if (!isset($expires)) {
$expires = variable_get('views_data_export_gc_expires', 604800);
// one week
}
if (!isset($chunk)) {
$chunk = variable_get('views_data_export_gc_chunk', 30);
}
if ($chunk == -1) {
$result = db_query("SELECT eid FROM {views_data_export} WHERE time_stamp <= :timestamp ORDER BY time_stamp ASC", array(
':timestamp' => REQUEST_TIME - $expires,
));
}
else {
$result = db_query_range("SELECT eid FROM {views_data_export} WHERE time_stamp <= :timestamp ORDER BY time_stamp ASC", 0, $chunk, array(
':timestamp' => REQUEST_TIME - $expires,
));
}
$eids_to_clear = array();
foreach ($result as $row) {
$eids_to_clear[] = $row->eid;
}
// We do two things to exports we want to garbage collect
// 1. Delete the index table for it, if it is still around
// 2. Delete the row from the exports table
// 3. Delete the view from the object_cache
if (count($eids_to_clear)) {
foreach ($eids_to_clear as $eid) {
// 1. Delete index table, if it is still around for some reason
$table = VIEWS_DATA_EXPORT_INDEX_TABLE_PREFIX . $eid;
if (db_table_exists($table)) {
db_drop_table($table);
}
}
// 2. Delete the entries in the exports table.
db_delete('views_data_export')
->condition('eid', $eids_to_clear, 'IN')
->execute();
// 3. Clear the cached views
views_data_export_view_clear($eids_to_clear);
}
lock_release('views_data_export_gc');
}
}