function SystemHooks::cron
Implements hook_cron().
Remove older rows from flood, batch cache and expirable keyvalue tables. Also ensure files directories have .htaccess files.
File
-
core/
modules/ system/ src/ Hook/ SystemHooks.php, line 309
Class
- SystemHooks
- Hook implementations for system.
Namespace
Drupal\system\HookCode
public function cron() : void {
// 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();
if (\Drupal::config('system.advisories')->get('enabled')) {
// Fetch the security advisories so that they will be pre-fetched during
// _system_advisories_requirements() and system_page_top().
/** @var \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher $fetcher */
$fetcher = \Drupal::service('system.sa_fetcher');
$fetcher->getSecurityAdvisories();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.