You are here

public function NodeStatisticsDatabaseStorage::resetDayCount in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/statistics/src/NodeStatisticsDatabaseStorage.php \Drupal\statistics\NodeStatisticsDatabaseStorage::resetDayCount()
  2. 10 core/modules/statistics/src/NodeStatisticsDatabaseStorage.php \Drupal\statistics\NodeStatisticsDatabaseStorage::resetDayCount()

Reset the day counter for all entities once every day.

Overrides StatisticsStorageInterface::resetDayCount

File

core/modules/statistics/src/NodeStatisticsDatabaseStorage.php, line 118

Class

NodeStatisticsDatabaseStorage
Provides the default database storage backend for statistics.

Namespace

Drupal\statistics

Code

public function resetDayCount() {
  $statistics_timestamp = $this->state
    ->get('statistics.day_timestamp') ?: 0;
  if ($this
    ->getRequestTime() - $statistics_timestamp >= 86400) {
    $this->state
      ->set('statistics.day_timestamp', $this
      ->getRequestTime());
    $this->connection
      ->update('node_counter')
      ->fields([
      'daycount' => 0,
    ])
      ->execute();
  }
}