You are here

function node_cron in Drupal 8

Same name and namespace in other branches
  1. 4 modules/node.module \node_cron()
  2. 5 modules/node/node.module \node_cron()
  3. 6 modules/node/node.module \node_cron()
  4. 7 modules/node/node.module \node_cron()
  5. 9 core/modules/node/node.module \node_cron()

Implements hook_cron().

File

core/modules/node/node.module, line 699
The core module that allows content to be submitted to the site.

Code

function node_cron() {

  // 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 (\Drupal::moduleHandler()
    ->moduleExists('search')) {
    $min_alias = 'min_created';
    $max_alias = 'max_created';
    $result = \Drupal::entityQueryAggregate('node')
      ->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],
      ];
      \Drupal::state()
        ->set('node.min_max_update_time', $array);
    }
  }
}