function NodeSearchHooks::cron
Implements hook_cron().
Attributes
File
-
core/
modules/ node/ src/ Hook/ NodeSearchHooks.php, line 31
Class
- NodeSearchHooks
- Search related hook implementations for node module.
Namespace
Drupal\node\HookCode
public function cron() : void {
// Calculate the oldest and newest node created times, for use in search
// rankings. (Note that field aliases have to be variables passed by
// reference.)
if ($this->moduleHandler
->moduleExists('search')) {
$min_alias = 'min_created';
$max_alias = 'max_created';
$result = $this->entityTypeManager
->getStorage('node')
->getAggregateQuery()
->accessCheck(FALSE)
->aggregate('created', 'MIN', NULL, $min_alias)
->aggregate('created', 'MAX', NULL, $max_alias)
->execute();
if (isset($result[0])) {
// Make an array with definite keys and store it in the state system.
$array = [
'min_created' => $result[0][$min_alias],
'max_created' => $result[0][$max_alias],
];
$this->state
->set('node.min_max_update_time', $array);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.