function system_cron

Implements hook_cron().

Remove older rows from flood and batch table. Remove old temporary files.

File

drupal/core/modules/system/system.module, line 3451
Configuration system that lets administrators modify the workings of the site.

Code

function system_cron() {

  // Cleanup the flood.
  drupal_container()
    ->get('flood')
    ->garbageCollection();
  $cache_bins = array_merge(module_invoke_all('cache_flush'), array(
    'form',
    'menu',
  ));
  foreach ($cache_bins as $bin) {
    cache($bin)
      ->deleteExpired();
  }

  // Cleanup the batch table and the queue for failed batches.
  db_delete('batch')
    ->condition('timestamp', REQUEST_TIME - 864000, '<')
    ->execute();
  db_delete('queue')
    ->condition('created', REQUEST_TIME - 864000, '<')
    ->condition('name', 'drupal_batch:%', 'LIKE')
    ->execute();

  // 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', 0, '<>')
    ->condition('expire', REQUEST_TIME, '<')
    ->execute();
}