You are here

function system_cron in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/system.module \system_cron()

Implements hook_cron().

Remove older rows from flood, batch cache and expirable keyvalue tables.

1 call to system_cron()
GarbageCollectionTest::testGarbageCollection in core/modules/system/src/Tests/KeyValueStore/GarbageCollectionTest.php
Tests garbage collection.

File

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

Code

function system_cron() {

  // Clean up the flood.
  \Drupal::flood()
    ->garbageCollection();
  foreach (Cache::getBins() as $cache_backend) {
    $cache_backend
      ->garbageCollection();
  }

  // Clean up the expirable key value database store.
  if (\Drupal::service('keyvalue.expirable.database') instanceof KeyValueDatabaseExpirableFactory) {
    \Drupal::service('keyvalue.expirable.database')
      ->garbageCollection();
  }

  // Clean up the queue for failed batches.
  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();

  // Clean up PHP storage.
  PhpStorageFactory::get('container')
    ->garbageCollection();
  PhpStorageFactory::get('service_container')
    ->garbageCollection();
}