You are here

function system_cron in Drupal 8

Same name and namespace in other branches
  1. 6 modules/system/system.module \system_cron()
  2. 7 modules/system/system.module \system_cron()
  3. 9 core/modules/system/system.module \system_cron()

Implements hook_cron().

Remove older rows from flood, batch cache and expirable keyvalue tables. Also ensure files directories have .htaccess files.

2 calls to system_cron()
DirectoryTest::testFileCheckDirectoryHandling in core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php
Test directory handling functions.
GarbageCollectionTest::testGarbageCollection in core/tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php
Tests garbage collection.

File

core/modules/system/system.module, line 1206
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 any garbage in the queue service.
  $queue_worker_manager = \Drupal::service('plugin.manager.queue_worker');
  $queue_factory = \Drupal::service('queue');
  foreach (array_keys($queue_worker_manager
    ->getDefinitions()) as $queue_name) {
    $queue = $queue_factory
      ->get($queue_name);
    if ($queue instanceof QueueGarbageCollectionInterface) {
      $queue
        ->garbageCollection();
    }
  }

  // Ensure that all of Drupal's standard directories (e.g., the public files
  // directory and config directory) have appropriate .htaccess files.
  \Drupal::service('file.htaccess_writer')
    ->ensure();
}