diff --git a/core/modules/statistics/src/StatisticsDatabaseStorage.php b/core/modules/statistics/src/StatisticsDatabaseStorage.php index a8ea5ef..8cb3dce 100644 --- a/core/modules/statistics/src/StatisticsDatabaseStorage.php +++ b/core/modules/statistics/src/StatisticsDatabaseStorage.php @@ -84,9 +84,8 @@ public function fetchViews($id) { * {@inheritdoc} */ public function fetchAll($order = 'totalcount', $limit = 5) { - // @todo replace exception with assert() - #2408013. if (!in_array($order, ['totalcount', 'daycount', 'timestamp'])) { - throw new \InvalidArgumentException(); + assert(false, "Invalid order argument."); } return $this->connection @@ -111,19 +110,15 @@ public function clean($id) { /** * {@inheritdoc} */ - public function needsReset() { - $statistics_timestamp = $this->state->get('statistics.day_timestamp') ?: 0; - return ($this->getRequestTime() - $statistics_timestamp) >= 86400; - } - - /** - * {@inheritdoc} - */ public function resetDayCount() { - $this->state->set('statistics.day_timestamp', $this->getRequestTime()); - return (bool) $this->connection->update('node_counter') - ->fields(['daycount' => 0]) - ->execute(); + $statistics_timestamp = $this->state->get('statistics.day_timestamp') ?: 0; + if (($this->getRequestTime() - $statistics_timestamp) >= 86400) { + $this->state->set('statistics.day_timestamp', $this->getRequestTime()); + return (bool) $this->connection->update('node_counter') + ->fields(['daycount' => 0]) + ->execute(); + } + return FALSE; } /** diff --git a/core/modules/statistics/src/StatisticsStorageInterface.php b/core/modules/statistics/src/StatisticsStorageInterface.php index d287d2b..b12165b 100644 --- a/core/modules/statistics/src/StatisticsStorageInterface.php +++ b/core/modules/statistics/src/StatisticsStorageInterface.php @@ -65,18 +65,6 @@ public function fetchAll($order = 'totalcount', $limit = 5); public function clean($id); /** - * A reset is performed daily. - * - * Returns true if more than 24 hours since daily totals have been reset. - * - * @see StatisticsStorageInterface::resetDayCount() To perform the reset. - * - * @return bool - * TRUE if reset is needed. - */ - public function needsReset(); - - /** * Resets the day count for all entities. * * @return bool diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 6fdf3b5..fe55853 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -71,9 +71,7 @@ function statistics_node_links_alter(array &$links, NodeInterface $entity, array */ function statistics_cron() { $storage = \Drupal::service('statistics.storage'); - if ($storage->needsReset()) { - $storage->resetDayCount(); - } + $storage->resetDayCount(); $storage->maxTotalCount(); }