diff --git a/core/modules/statistics/src/NodeStatisticsDatabaseStorage.php b/core/modules/statistics/src/NodeStatisticsDatabaseStorage.php index a86024b..a9b6530 100644 --- a/core/modules/statistics/src/NodeStatisticsDatabaseStorage.php +++ b/core/modules/statistics/src/NodeStatisticsDatabaseStorage.php @@ -51,6 +51,52 @@ public function __construct(Connection $connection, StateInterface $state, Reque } /** + * The node_counter table schema definition. + * + * @return array + */ + public function schemaDefinition() { + $schema['node_counter'] = [ + 'description' => 'Access statistics for {node}s.', + 'fields' => [ + 'nid' => [ + 'description' => 'The {node}.nid for these statistics.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ], + 'totalcount' => [ + 'description' => 'The total number of times the {node} has been viewed.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'size' => 'big', + ], + 'daycount' => [ + 'description' => 'The total number of times the {node} has been viewed today.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'size' => 'medium', + ], + 'timestamp' => [ + 'description' => 'The most recent time the {node} has been viewed.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ], + ], + 'primary key' => ['nid'], + ]; + + return $schema; + } + + /** * {@inheritdoc} */ public function recordView($id) { diff --git a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php index a8746d6..df07c81 100644 --- a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php +++ b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php @@ -154,24 +154,24 @@ public function build() { $content = array(); if ($this->configuration['top_day_num'] > 0) { - $result = $this->statisticsStorage->fetchAll('daycount', $this->configuration['top_day_num']); - if ($result) { - $content['top_day'] = $this->nodeTitleList($result, $this->t("Today's:")); + $nids = $this->statisticsStorage->fetchAll('daycount', $this->configuration['top_day_num']); + if ($nids) { + $content['top_day'] = $this->nodeTitleList($nids, $this->t("Today's:")); $content['top_day']['#suffix'] = '
'; } } if ($this->configuration['top_all_num'] > 0) { - $result = $this->statisticsStorage->fetchAll('totalcount', $this->configuration['top_all_num']); - if ($result) { - $content['top_all'] = $this->nodeTitleList($result, $this->t('All time:')); + $nids = $this->statisticsStorage->fetchAll('totalcount', $this->configuration['top_all_num']); + if ($nids) { + $content['top_all'] = $this->nodeTitleList($nids, $this->t('All time:')); $content['top_all']['#suffix'] = '
'; } } if ($this->configuration['top_last_num'] > 0) { - $result = $this->statisticsStorage->fetchAll('timestamp', $this->configuration['top_last_num']); - $content['top_last'] = $this->nodeTitleList($result, $this->t('Last viewed:')); + $nids = $this->statisticsStorage->fetchAll('timestamp', $this->configuration['top_last_num']); + $content['top_last'] = $this->nodeTitleList($nids, $this->t('Last viewed:')); $content['top_last']['#suffix'] = '
'; } diff --git a/core/modules/statistics/statistics.install b/core/modules/statistics/statistics.install index 11c72f4..f97507b 100644 --- a/core/modules/statistics/statistics.install +++ b/core/modules/statistics/statistics.install @@ -18,44 +18,7 @@ function statistics_uninstall() { * Implements hook_schema(). */ function statistics_schema() { - $schema['node_counter'] = array( - 'description' => 'Access statistics for {node}s.', - 'fields' => array( - 'nid' => array( - 'description' => 'The {node}.nid for these statistics.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - 'totalcount' => array( - 'description' => 'The total number of times the {node} has been viewed.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'size' => 'big', - ), - 'daycount' => array( - 'description' => 'The total number of times the {node} has been viewed today.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'size' => 'medium', - ), - 'timestamp' => array( - 'description' => 'The most recent time the {node} has been viewed.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'primary key' => array('nid'), - ); - - return $schema; + return \Drupal::service('statistics.storage.node')->schemaDefinition(); } /**