diff --git a/core/modules/statistics/src/StatisticsDatabaseStorage.php b/core/modules/statistics/src/StatisticsDatabaseStorage.php index f7c317b..a8ea5ef 100644 --- a/core/modules/statistics/src/StatisticsDatabaseStorage.php +++ b/core/modules/statistics/src/StatisticsDatabaseStorage.php @@ -53,10 +53,10 @@ public function __construct(Connection $connection, StateInterface $state, Reque /** * {@inheritdoc} */ - public function recordHit($nid) { + public function recordHit($id) { return (bool) $this->connection ->merge('node_counter') - ->key('nid', $nid) + ->key('nid', $id) ->fields([ 'daycount' => 1, 'totalcount' => 1, @@ -70,11 +70,11 @@ public function recordHit($nid) { /** * {@inheritdoc} */ - public function fetchViews($nid) { + public function fetchViews($id) { $views = $this->connection ->select('node_counter', 'nc') ->fields('nc', ['totalcount', 'daycount', 'timestamp']) - ->condition('nid', $nid, '=') + ->condition('nid', $id, '=') ->execute() ->fetchAssoc(); return new StatisticsViews($views['totalcount'], $views['daycount'], $views['timestamp']); @@ -101,10 +101,10 @@ public function fetchAll($order = 'totalcount', $limit = 5) { /** * {@inheritdoc} */ - public function clean($nid) { + public function clean($id) { return (bool) $this->connection ->delete('node_counter') - ->condition('nid', $nid) + ->condition('nid', $id) ->execute(); } diff --git a/core/modules/statistics/src/StatisticsStorageInterface.php b/core/modules/statistics/src/StatisticsStorageInterface.php index eeb1e7e..d287d2b 100644 --- a/core/modules/statistics/src/StatisticsStorageInterface.php +++ b/core/modules/statistics/src/StatisticsStorageInterface.php @@ -11,33 +11,33 @@ * Provides an interface defining Statistics Storage. * * Stores the views per day, total views and timestamp of last view - * for all nodes on the site. + * for entities. */ interface StatisticsStorageInterface { /** - * Count a node view. + * Count a entity view. * - * @param int $nid - * The ID of the node to count. + * @param int $id + * The ID of the entity to count. * * @return bool - * TRUE if the node view has been counted. + * TRUE if the entity view has been counted. */ - public function recordHit($nid); + public function recordHit($id); /** - * Returns the number of times a node has been viewed. + * Returns the number of times a entity has been viewed. * - * @param int $nid - * The ID of the node to fetch the views for. + * @param int $id + * The ID of the entity to fetch the views for. * * @return \Drupal\statistics\StatisticsViewsInterface */ - public function fetchViews($nid); + public function fetchViews($id); /** - * Returns the number of times a node has been viewed. + * Returns the number of times a entity has been viewed. * * @param string $order * The counter name to order by: @@ -46,23 +46,23 @@ public function fetchViews($nid); * - 'timestamp' The unix timestamp of the last view. * * @param int $limit - * The number of node IDs to return. + * The number of entity IDs to return. * * @return array - * An ordered array of node IDs. + * An ordered array of entity IDs. */ public function fetchAll($order = 'totalcount', $limit = 5); /** - * Delete counts for a specific node. + * Delete counts for a specific entity. * - * @param int $nid - * The ID of the node which views to delete. + * @param int $id + * The ID of the entity which views to delete. * * @return bool - * TRUE if the node views have been deleted. + * TRUE if the entity views have been deleted. */ - public function clean($nid); + public function clean($id); /** * A reset is performed daily. @@ -77,7 +77,7 @@ public function clean($nid); public function needsReset(); /** - * Resets the day count for all nodes. + * Resets the day count for all entities. * * @return bool * TRUE if the day count is reset. diff --git a/core/modules/statistics/src/StatisticsViews.php b/core/modules/statistics/src/StatisticsViews.php index 8f64d3d..e107955 100644 --- a/core/modules/statistics/src/StatisticsViews.php +++ b/core/modules/statistics/src/StatisticsViews.php @@ -45,4 +45,4 @@ public function getDayCount() { public function getTimestamp() { return $this->timestamp; } -} \ No newline at end of file +} diff --git a/core/modules/statistics/src/StatisticsViewsInterface.php b/core/modules/statistics/src/StatisticsViewsInterface.php index 2db24d3..2c72184 100644 --- a/core/modules/statistics/src/StatisticsViewsInterface.php +++ b/core/modules/statistics/src/StatisticsViewsInterface.php @@ -5,21 +5,21 @@ interface StatisticsViewsInterface { /** - * Total number of times the node has been viewed. + * Total number of times the entity has been viewed. * * @return int */ public function getTotalCount(); /** - * Total number of times the node has been viewed "today". + * Total number of times the entity has been viewed "today". * * @return int */ public function getDayCount(); /** - * Timestamp of when the node was last viewed. + * Timestamp of when the entity was last viewed. * * @return int */ diff --git a/core/modules/statistics/src/Tests/StatisticsAdminTest.php b/core/modules/statistics/src/Tests/StatisticsAdminTest.php index 565925c..a8bdba7 100644 --- a/core/modules/statistics/src/Tests/StatisticsAdminTest.php +++ b/core/modules/statistics/src/Tests/StatisticsAdminTest.php @@ -73,7 +73,7 @@ function testStatisticsSettings() { $this->drupalGet('node/' . $this->testNode->id()); // Manually calling statistics.php, simulating ajax behavior. $nid = $this->testNode->id(); - $post = array('nid' => $nid); + $post = array('id' => $nid); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $this->client->post($stats_path, array('form_params' => $post)); @@ -108,7 +108,7 @@ function testDeleteNode() { $this->drupalGet('node/' . $this->testNode->id()); // Manually calling statistics.php, simulating ajax behavior. $nid = $this->testNode->id(); - $post = array('nid' => $nid); + $post = array('id' => $nid); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $this->client->post($stats_path, array('form_params' => $post)); @@ -142,7 +142,7 @@ function testExpiredLogs() { $this->drupalGet('node/' . $this->testNode->id()); // Manually calling statistics.php, simulating ajax behavior. $nid = $this->testNode->id(); - $post = array('nid' => $nid); + $post = array('id' => $nid); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $this->client->post($stats_path, array('form_params' => $post)); diff --git a/core/modules/statistics/src/Tests/StatisticsLoggingTest.php b/core/modules/statistics/src/Tests/StatisticsLoggingTest.php index 7cfec7c..81c917f 100644 --- a/core/modules/statistics/src/Tests/StatisticsLoggingTest.php +++ b/core/modules/statistics/src/Tests/StatisticsLoggingTest.php @@ -113,17 +113,17 @@ function testLogging() { $this->drupalGet($path); $settings = $this->getDrupalSettings(); $this->assertPattern($expected_library, 'Found statistics library JS on node page.'); - $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on node page.'); + $this->assertIdentical($this->node->id(), $settings['statistics']['data']['id'], 'Found statistics settings on node page.'); // Verify the same when loading the site in a non-default language. $this->drupalGet($this->language['langcode'] . '/' . $path); $settings = $this->getDrupalSettings(); $this->assertPattern($expected_library, 'Found statistics library JS on a valid node page in a non-default language.'); - $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on valid node page in a non-default language.'); + $this->assertIdentical($this->node->id(), $settings['statistics']['data']['id'], 'Found statistics settings on valid node page in a non-default language.'); // Manually call statistics.php to simulate ajax data collection behavior. global $base_root; - $post = array('nid' => $this->node->id()); + $post = array('id' => $this->node->id()); $this->client->post($base_root . $stats_path, array('form_params' => $post)); $node_counter = statistics_get($this->node->id()); $this->assertIdentical($node_counter['totalcount'], '1'); diff --git a/core/modules/statistics/src/Tests/StatisticsReportsTest.php b/core/modules/statistics/src/Tests/StatisticsReportsTest.php index 0fe2e28..ada5e10 100644 --- a/core/modules/statistics/src/Tests/StatisticsReportsTest.php +++ b/core/modules/statistics/src/Tests/StatisticsReportsTest.php @@ -26,7 +26,7 @@ function testPopularContentBlock() { $this->drupalGet('node/' . $node->id()); // Manually calling statistics.php, simulating ajax behavior. $nid = $node->id(); - $post = http_build_query(array('nid' => $nid)); + $post = http_build_query(array('id' => $nid)); $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; diff --git a/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php b/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php index b7d22b8..2a0ce86 100644 --- a/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php +++ b/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php @@ -24,7 +24,7 @@ function testStatisticsTokenReplacement() { $this->drupalGet('node/' . $node->id()); // Manually calling statistics.php, simulating ajax behavior. $nid = $node->id(); - $post = http_build_query(array('nid' => $nid)); + $post = http_build_query(array('id' => $nid)); $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; diff --git a/core/modules/statistics/src/Tests/Views/IntegrationTest.php b/core/modules/statistics/src/Tests/Views/IntegrationTest.php index 4882fd2..26b2b68 100644 --- a/core/modules/statistics/src/Tests/Views/IntegrationTest.php +++ b/core/modules/statistics/src/Tests/Views/IntegrationTest.php @@ -72,7 +72,7 @@ public function testNodeCounterIntegration() { global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $client = \Drupal::service('http_client_factory')->fromOptions(['config/curl', array(CURLOPT_TIMEOUT => 10)]); - $client->post($stats_path, array('form_params' => array('nid' => $this->node->id()))); + $client->post($stats_path, array('form_params' => array('id' => $this->node->id()))); $this->drupalGet('test_statistics_integration'); $expected = statistics_get($this->node->id()); diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 056f04e..6fdf3b5 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -40,7 +40,7 @@ function statistics_help($route_name, RouteMatchInterface $route_match) { function statistics_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) { if (!$node->isNew() && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) { $build['#attached']['library'][] = 'statistics/drupal.statistics'; - $settings = ['data' => ['nid' => $node->id()], 'url' => Url::fromUri('base:' . drupal_get_path('module', 'statistics') . '/statistics.php')->toString()]; + $settings = ['data' => ['id' => $node->id()], 'url' => Url::fromUri('base:' . drupal_get_path('module', 'statistics') . '/statistics.php')->toString()]; $build['#attached']['drupalSettings']['statistics'] = $settings; } } @@ -81,12 +81,12 @@ function statistics_cron() { * Retrieves a node's "view statistics". * * @deprecated in Drupal 8.2.x, will be removed before Drupal 9.0.0. - * Use \Drupal::service('statistics.storage')->fetchViews($nid). + * Use \Drupal::service('statistics.storage')->fetchViews($id). */ -function statistics_get($nid) { - if ($nid > 0) { +function statistics_get($id) { + if ($id > 0) { /** @var \Drupal\statistics\StatisticsViewsInterface $statistics */ - $statistics = \Drupal::service('statistics.storage')->fetchViews($nid); + $statistics = \Drupal::service('statistics.storage')->fetchViews($id); return [ 'totalcount' => $statistics->getTotalCount(), 'daycount' => $statistics->getDayCount(), @@ -100,8 +100,8 @@ function statistics_get($nid) { */ function statistics_node_predelete(EntityInterface $node) { // Clean up statistics table when node is deleted. - $nid = $node->id(); - return \Drupal::service('statistics.storage')->clean($nid); + $id = $node->id(); + return \Drupal::service('statistics.storage')->clean($id); } /** diff --git a/core/modules/statistics/statistics.php b/core/modules/statistics/statistics.php index edb1cc4..9b861e8 100644 --- a/core/modules/statistics/statistics.php +++ b/core/modules/statistics/statistics.php @@ -22,9 +22,9 @@ ->get('count_content_views'); if ($views) { - $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT); - if ($nid) { + $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT); + if ($id) { $container->get('request_stack')->push(Request::createFromGlobals()); - $container->get('statistics.storage')->recordHit($nid); + $container->get('statistics.storage')->recordHit($id); } }