You are here

function statistics_cron in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/statistics/statistics.module \statistics_cron()

Implements hook_cron().

File

core/modules/statistics/statistics.module, line 72
Logs and displays content statistics for a site.

Code

function statistics_cron() {
  $statistics_timestamp = \Drupal::state()
    ->get('statistics.day_timestamp') ?: 0;
  if (REQUEST_TIME - $statistics_timestamp >= 86400) {

    // Reset day counts.
    db_update('node_counter')
      ->fields(array(
      'daycount' => 0,
    ))
      ->execute();
    \Drupal::state()
      ->set('statistics.day_timestamp', REQUEST_TIME);
  }

  // Calculate the maximum of node views, for node search ranking.
  \Drupal::state()
    ->set('statistics.node_counter_scale', 1.0 / max(1.0, db_query('SELECT MAX(totalcount) FROM {node_counter}')
    ->fetchField()));
}