system_cron
- Versions
- 6 – 7
system_cron()
Implements hook_cron().
Remove older rows from flood and batch table. Remove old temporary files.
Code
modules/system/system.module, line 2680
<?php
function system_cron() {
// Cleanup the flood.
db_delete('flood')
->condition('expiration', REQUEST_TIME, '<')
->execute();
// Cleanup the batch table.
db_delete('batch')
->condition('timestamp', REQUEST_TIME - 864000, '<')
->execute();
// Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
// Use separate placeholders for the status to avoid a bug in some versions
// of PHP. See http://drupal.org/node/352956
$result = db_query('SELECT fid FROM {file} WHERE status & :permanent1 <> :permanent2 AND timestamp < :timestamp', array(
':permanent1' => FILE_STATUS_PERMANENT,
':permanent2' => FILE_STATUS_PERMANENT,
':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE
));
foreach ($result as $row) {
if ($file = file_load($row->fid)) {
if (!file_delete($file)) {
watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->uri), WATCHDOG_ERROR);
}
}
}
$core = array('cache', 'cache_filter', 'cache_page', 'cache_form', 'cache_menu');
$cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
foreach ($cache_tables as $table) {
cache_clear_all(NULL, $table);
}
// Reset expired items in the default queue implementation table. If that's
// not used, this will simply be a no-op.
db_update('queue')
->fields(array(
'expire' => 0,
))
->condition('expire', REQUEST_TIME, '<')
->execute();
}
?>Login or register to post comments 