function batch_cron
Search API
| 7.x batch.module | batch_cron() |
| 6.x batch.module | batch_cron() |
| 5.x batch.module | batch_cron() |
Implementation of hook_cron
Delete old batches from the batch_queue table. These would be normal "old" batches we no longer need, or ones that never finished for some reason and are just taking up space.
File
- modules/
batch/ batch.module, line 294
Code
function batch_cron() {
$older_than = strtotime("2 HOURS AGO");
db_query("DELETE FROM batch_queue WHERE created <= ? ", $older_than);
// Should we check to see if there are any temp files to delete?
if (time() > variable_get("batch_check_to_delete_temp_files", 0)) {
// Also look for any "batch_" files which are too old.
$private_path = fp_get_files_path() . "/private";
$files = scandir($private_path);
foreach ($files as $file) {
if (str_starts_with($file, "batch_") && str_ends_with($file, ".tmp")) {
$temp = explode("__", $file);
$temp2 = explode(".", $temp [1]);
$ts = intval($temp2 [0]);
if ($ts > 999) { // hopefully this is a valid timestamp
if ($ts <= $older_than) {
// Yes, we can delete now.
watchdog("batch", "Delete old temp file: " . $file, array(), WATCHDOG_DEBUG);
unlink($private_path . '/' . $file);
}
}
}
} // foreach file
// Set a new time to check to delete temp files...
variable_set("batch_check_to_delete_temp_files", strtotime("NOW + 2 HOURS"));
} // if time > variable_get....
}
