diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php index 528611e..dfae39f 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php @@ -22,7 +22,7 @@ class StatisticsAdminTest extends WebTestBase { public static $modules = array('node', 'statistics'); /** - * A user that has permission to administer and access statistics. + * A user that has permission to administer statistics. * * @var object|FALSE * @@ -31,7 +31,7 @@ class StatisticsAdminTest extends WebTestBase { protected $privileged_user; /** - * A page node for which to check access statistics. + * A page node for which to check content statistics. * * @var object */ @@ -52,7 +52,7 @@ function setUp() { if ($this->profile != 'standard') { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); } - $this->privileged_user = $this->drupalCreateUser(array('access statistics', 'administer statistics', 'view post access counter', 'create page content')); + $this->privileged_user = $this->drupalCreateUser(array('administer statistics', 'view post access counter', 'create page content')); $this->drupalLogin($this->privileged_user); $this->test_node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->privileged_user->uid)); } @@ -62,18 +62,12 @@ function setUp() { */ function testStatisticsSettings() { $config = config('statistics.settings'); - $this->assertFalse($config->get('access_log.enabled'), 'Access log is disabled by default.'); $this->assertFalse($config->get('count_content_views'), 'Count content view log is disabled by default.'); - $this->drupalGet('admin/reports/pages'); - $this->assertRaw(t('No statistics available.'), 'Verifying text shown when no statistics is available.'); - - // Enable access log and counter on content view. - $edit['statistics_enable_access_log'] = 1; + // Enable counter on content view. $edit['statistics_count_content_views'] = 1; $this->drupalPost('admin/config/system/statistics', $edit, t('Save configuration')); $config = config('statistics.settings'); - $this->assertTrue($config->get('access_log.enabled'), 'Access log is enabled.'); $this->assertTrue($config->get('count_content_views'), 'Count content view log is enabled.'); // Hit the node. @@ -86,9 +80,6 @@ function testStatisticsSettings() { $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); - $this->drupalGet('admin/reports/pages'); - $this->assertText('node/1', 'Test node found.'); - // Hit the node again (the counter is incremented after the hit, so // "1 view" will actually be shown when the node is hit the second time). $this->drupalGet('node/' . $this->test_node->nid); @@ -133,44 +124,11 @@ function testDeleteNode() { } /** - * Tests that accesslog reflects when a user is deleted. - */ - function testDeleteUser() { - config('statistics.settings')->set('access_log.enabled', 1)->save(); - - config('user.settings')->set('cancel_method', 'user_cancel_delete')->save(); - $this->drupalLogout($this->privileged_user); - $account = $this->drupalCreateUser(array('access content', 'cancel account')); - $this->drupalLogin($account); - $this->drupalGet('node/' . $this->test_node->nid); - - $account = user_load($account->uid, TRUE); - - $this->drupalGet('user/' . $account->uid . '/edit'); - $this->drupalPost(NULL, NULL, t('Cancel account')); - - $timestamp = time(); - $this->drupalPost(NULL, NULL, t('Cancel account')); - // Confirm account cancellation request. - $mails = $this->drupalGetMails(); - $mail = end($mails); - preg_match('@http.+?(user/\d+/cancel/confirm/\d+/[^\s]+)@', $mail['body'], $matches); - $path = $matches[1]; - $this->drupalGet($path); - $this->assertFalse(user_load($account->uid, TRUE), 'User is not found in the database.'); - - $this->drupalGet('admin/reports/visitors'); - $this->assertNoText($account->name, 'Did not find user in visitor statistics.'); - } - - /** * Tests that cron clears day counts and expired access logs. */ function testExpiredLogs() { config('statistics.settings') - ->set('access_log.enabled', 1) ->set('count_content_views', 1) - ->set('access_log.max_lifetime', 1) ->save(); state()->set('statistics.day_timestamp', 8640000); @@ -186,9 +144,6 @@ function testExpiredLogs() { drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); $this->assertText('1 view', 'Node is viewed once.'); - $this->drupalGet('admin/reports/pages'); - $this->assertText('node/' . $this->test_node->nid, 'Hit URL found.'); - // statistics_cron() will subtract // statistics.settings:accesslog.max_lifetime config from REQUEST_TIME in // the delete query, so wait two secs here to make sure the access log will diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsBlockVisitorsTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsBlockVisitorsTest.php deleted file mode 100644 index 82990e3..0000000 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsBlockVisitorsTest.php +++ /dev/null @@ -1,58 +0,0 @@ - 'Top visitor banning', - 'description' => 'Tests banning of IP addresses via the top visitors report.', - 'group' => 'Statistics' - ); - } - - /** - * Blocks an IP address via the top visitors report and then unblocks it. - */ - function testIPAddressBlocking() { - // IP address for testing. - $test_ip_address = '192.168.1.1'; - - // Verify the IP address from accesslog appears on the top visitors page - // and that a 'ban IP address' link is displayed. - $this->drupalLogin($this->blocking_user); - $this->drupalGet('admin/reports/visitors'); - $this->assertText($test_ip_address, 'IP address found.'); - $this->assertText(t('ban IP address'), 'Ban IP link displayed'); - - // Block the IP address. - $this->clickLink('ban IP address'); - $this->assertText(t('IP address bans'), 'IP banning page displayed.'); - $edit = array(); - $edit['ip'] = $test_ip_address; - $this->drupalPost('admin/config/people/ban', $edit, t('Add')); - $ip = db_query("SELECT iid from {ban_ip} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField(); - $this->assertNotEqual($ip, FALSE, 'IP address found in database'); - $this->assertRaw(t('The IP address %ip has been banned.', array('%ip' => $edit['ip'])), 'IP address was banned.'); - - // Verify that the block/unblock link on the top visitors page has been - // altered. - $this->drupalGet('admin/reports/visitors'); - $this->assertText(t('unban IP address'), 'Unban IP address link displayed'); - - // Unblock the IP address. - $this->clickLink('unban IP address'); - $this->assertRaw(t('Are you sure you want to unblock %ip?', array('%ip' => $test_ip_address)), 'IP address deletion confirmation found.'); - $edit = array(); - $this->drupalPost('admin/config/people/ban/delete/1', NULL, t('Delete')); - $this->assertRaw(t('The IP address %ip was deleted.', array('%ip' => $test_ip_address)), 'IP address deleted.'); - } -} diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php index 7a6a79a..4cb7053 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php @@ -53,12 +53,10 @@ function setUp() { // Enable access logging. config('statistics.settings') - ->set('access_log.enabled', 1) ->set('count_content_views', 1) ->save(); // Clear the logs. - db_truncate('accesslog'); db_truncate('node_counter'); } @@ -82,9 +80,6 @@ function testLogging() { $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Testing an uncached page.'); - $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC); - $this->assertTrue(is_array($log) && count($log) == 1, 'Page request was logged.'); - $this->assertEqual(array_intersect_key($log[0], $expected), $expected); $node_counter = statistics_get($this->node->nid); $this->assertIdentical($node_counter['totalcount'], '1'); @@ -93,9 +88,6 @@ function testLogging() { // Manually calling statistics.php, simulating ajax behavior. drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Testing a cached page.'); - $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC); - $this->assertTrue(is_array($log) && count($log) == 2, 'Page request was logged.'); - $this->assertEqual(array_intersect_key($log[1], $expected), $expected); $node_counter = statistics_get($this->node->nid); $this->assertIdentical($node_counter['totalcount'], '2'); @@ -104,37 +96,8 @@ function testLogging() { $this->drupalGet($path); // Manually calling statistics.php, simulating ajax behavior. drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); - $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC); - // Check the 6th item since login and account pages are also logged - $this->assertTrue(is_array($log) && count($log) == 6, 'Page request was logged.'); - $this->assertEqual(array_intersect_key($log[5], $expected), $expected); $node_counter = statistics_get($this->node->nid); $this->assertIdentical($node_counter['totalcount'], '3'); - // Visit edit page to generate a title greater than 255. - $path = 'node/' . $this->node->nid . '/edit'; - $expected = array( - 'title' => truncate_utf8(t('Edit Basic page') . ' ' . $this->node->label(), 255), - 'path' => $path, - ); - $this->drupalGet($path); - $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC); - $this->assertTrue(is_array($log) && count($log) == 7, 'Page request was logged.'); - $this->assertEqual(array_intersect_key($log[6], $expected), $expected); - - // Create a path longer than 255 characters. Drupal's .htaccess file - // instructs Apache to test paths against the file system before routing to - // index.php. Many file systems restrict file names to 255 characters - // (http://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits), and - // Apache returns a 403 when testing longer file names, but the total path - // length is not restricted. - $long_path = $this->randomName(127) . '/' . $this->randomName(128); - - // Test that the long path is properly truncated when logged. - $this->drupalGet($long_path); - $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC); - $this->assertTrue(is_array($log) && count($log) == 8, 'Page request was logged for a path over 255 characters.'); - $this->assertEqual($log[7]['path'], truncate_utf8($long_path, 255)); - } } diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php index 3454e35..9ab16a1 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php @@ -14,59 +14,12 @@ class StatisticsReportsTest extends StatisticsTestBase { public static function getInfo() { return array( 'name' => 'Statistics reports tests', - 'description' => 'Tests display of statistics report pages and access logging.', + 'description' => 'Tests display of statistics report blocks.', 'group' => 'Statistics' ); } /** - * Verifies that 'Recent hits' renders properly and displays the added hit. - */ - function testRecentHits() { - $this->drupalGet('admin/reports/hits'); - $this->assertText('test', 'Hit title found.'); - $this->assertText('node/1', 'Hit URL found.'); - $this->assertText('Anonymous', 'Hit user found.'); - } - - /** - * Verifies that 'Top pages' renders properly and displays the added hit. - */ - function testTopPages() { - $this->drupalGet('admin/reports/pages'); - $this->assertText('test', 'Hit title found.'); - $this->assertText('node/1', 'Hit URL found.'); - } - - /** - * Verifies that 'Top referrers' renders properly and displays the added hit. - */ - function testTopReferrers() { - $this->drupalGet('admin/reports/referrers'); - $this->assertText('http://example.com', 'Hit referrer found.'); - } - - /** - * Verifies that 'Details' page renders properly and displays the added hit. - */ - function testDetails() { - $this->drupalGet('admin/reports/access/1'); - $this->assertText('test', 'Hit title found.'); - $this->assertText('node/1', 'Hit URL found.'); - $this->assertText('Anonymous', 'Hit user found.'); - } - - /** - * Verifies that access logging is working and is reported correctly. - */ - function testAccessLogging() { - $this->drupalGet('admin/reports/referrers'); - $this->drupalGet('admin/reports/hits'); - $this->assertText('Top referrers in the past 3 days', 'Hit title found.'); - $this->assertText('admin/reports/referrers', 'Hit URL found.'); - } - - /** * Tests the "popular content" block. */ function testPopularContentBlock() { diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTestBase.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTestBase.php index 2ed8b6f..f4d75f4 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTestBase.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTestBase.php @@ -33,7 +33,6 @@ function setUp() { $this->blocking_user = $this->drupalCreateUser(array( 'access administration pages', 'access site reports', - 'access statistics', 'ban IP addresses', 'administer blocks', 'administer statistics', @@ -41,23 +40,9 @@ function setUp() { )); $this->drupalLogin($this->blocking_user); - // Enable access logging. + // Enable logging. config('statistics.settings') - ->set('access_log.enabled', 1) ->set('count_content_views', 1) ->save(); - // Insert dummy access by anonymous user into access log. - db_insert('accesslog') - ->fields(array( - 'title' => 'test', - 'path' => 'node/1', - 'url' => 'http://example.com', - 'hostname' => '192.168.1.1', - 'uid' => 0, - 'sid' => 10, - 'timer' => 10, - 'timestamp' => REQUEST_TIME, - )) - ->execute(); } } diff --git a/core/modules/statistics/statistics.admin.inc b/core/modules/statistics/statistics.admin.inc index d1563cb..d454321c 100644 --- a/core/modules/statistics/statistics.admin.inc +++ b/core/modules/statistics/statistics.admin.inc @@ -8,320 +8,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** - * Page callback: Displays the "recent hits" page. - * - * This displays the pages with recent hits in a given time interval that - * haven't been flushed yet. The flush interval is set on the statistics - * settings form, but is dependent on cron running. - * - * @return array - * A render array containing information about the most recent hits. - */ -function statistics_recent_hits() { - $header = array( - array('data' => t('Timestamp'), 'field' => 'a.timestamp', 'sort' => 'desc'), - array('data' => t('Page'), 'field' => 'a.path'), - array('data' => t('User'), 'field' => 'u.name'), - t('Operations'), - ); - - $query = db_select('accesslog', 'a', array('target' => 'slave')) - ->extend('Drupal\Core\Database\Query\PagerSelectExtender') - ->extend('Drupal\Core\Database\Query\TableSortExtender'); - $query->join('users', 'u', 'a.uid = u.uid'); - $query - ->fields('a', array('aid', 'timestamp', 'path', 'title', 'uid')) - ->fields('u', array('name')) - ->limit(30) - ->orderByHeader($header); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $log) { - $row = array(); - $row[] = array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')); - $row[] = _statistics_format_item($log->title, $log->path); - $row[] = theme('username', array('account' => $log)); - $links = array(); - $links['details'] = array( - 'title' => t('details'), - 'href' => "admin/reports/access/$log->aid", - ); - $row[] = array( - 'data' => array( - '#type' => 'operations', - '#links' => $links, - ), - ); - $rows[] = $row; - } - - $build['statistics_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_pager'] = array('#theme' => 'pager'); - return $build; -} - -/** - * Page callback: Displays statistics for the "top pages" (most accesses). - * - * This displays the pages with the most hits (the "top pages") within a given - * time period that haven't been flushed yet. The flush interval is set on the - * statistics settings form, but is dependent on cron running. - * - * @return array - * A render array containing information about the the top pages. - */ -function statistics_top_pages() { - $header = array( - array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), - array('data' => t('Page'), 'field' => 'path'), - array('data' => t('Average page generation time'), 'field' => 'average_time'), - array('data' => t('Total page generation time'), 'field' => 'total_time') - ); - - $query = db_select('accesslog', 'a', array('target' => 'slave')) - ->extend('Drupal\Core\Database\Query\PagerSelectExtender') - ->extend('Drupal\Core\Database\Query\TableSortExtender'); - $query->addExpression('COUNT(path)', 'hits'); - // MAX(title) avoids having empty node titles which otherwise causes - // duplicates in the top pages list. - $query->addExpression('MAX(title)', 'title'); - $query->addExpression('AVG(timer)', 'average_time'); - $query->addExpression('SUM(timer)', 'total_time'); - - $query - ->fields('a', array('path')) - ->groupBy('path') - ->limit(30) - ->orderByHeader($header); - - $count_query = db_select('accesslog', 'a', array('target' => 'slave')); - $count_query->addExpression('COUNT(DISTINCT path)'); - $query->setCountQuery($count_query); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $page) { - $rows[] = array($page->hits, _statistics_format_item($page->title, $page->path), t('%time ms', array('%time' => round($page->average_time))), format_interval(round($page->total_time / 1000))); - } - - drupal_set_title(t('Top pages in the past %interval', array('%interval' => format_interval(config('statistics.settings')->get('access_log.max_lifetime')))), PASS_THROUGH); - $build['statistics_top_pages_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_top_pages_pager'] = array('#theme' => 'pager'); - return $build; -} - -/** - * Page callback: Displays the "top visitors" page. - * - * This displays the pages with the top number of visitors in a given time - * interval that haven't been flushed yet. The flush interval is set on the - * statistics settings form, but is dependent on cron running. - * - * @return array - * A render array containing the top visitors information. - */ -function statistics_top_visitors() { - $ban_exists = module_exists('ban'); - - $header = array( - array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), - array('data' => t('Visitor'), 'field' => 'u.name'), - array('data' => t('Total page generation time'), 'field' => 'total'), - $ban_exists && user_access('Ban IP addresses') ? t('Operations') : '', - ); - $query = db_select('accesslog', 'a', array('target' => 'slave')) - ->extend('Drupal\Core\Database\Query\PagerSelectExtender') - ->extend('Drupal\Core\Database\Query\TableSortExtender'); - if ($ban_exists) { - $query->leftJoin('ban_ip', 'b', 'a.hostname = b.ip'); - } - $query->leftJoin('users', 'u', 'a.uid = u.uid'); - - $query->addExpression('COUNT(a.uid)', 'hits'); - $query->addExpression('SUM(a.timer)', 'total'); - $query - ->fields('a', array('uid', 'hostname')) - ->fields('u', array('name')) - ->groupBy('a.hostname') - ->groupBy('a.uid') - ->groupBy('u.name') - ->limit(30); - if ($ban_exists) { - $query - ->fields('b', array('iid')) - ->groupBy('b.iid'); - } - $query->orderByHeader($header); - - $uniques_query = db_select('accesslog')->distinct(); - $uniques_query->fields('accesslog', array('uid', 'hostname')); - $count_query = db_select($uniques_query); - $count_query->addExpression('COUNT(*)'); - $query->setCountQuery($count_query); - - $result = $query->execute(); - $rows = array(); - $destination = drupal_get_destination(); - foreach ($result as $account) { - $links = array(); - if ($ban_exists && user_access('ban IP addresses') && !$account->uid) { - if ($account->iid) { - $links['unban'] = array( - 'title' => t('unban IP address'), - 'href' => "admin/config/people/ban/delete/$account->iid", - 'query' => $destination, - ); - } - else { - $links['ban'] = array( - 'title' => t('ban IP address'), - 'href' => "admin/config/people/ban/$account->hostname", - 'query' => $destination, - ); - } - } - $row = array(); - $row[] = $account->hits; - $row[] = ($account->uid ? theme('username', array('account' => $account)) : $account->hostname); - $row[] = format_interval(round($account->total / 1000)); - $row[] = array( - 'data' => array( - '#type' => 'operations', - '#links' => $links, - ), - ); - $rows[] = $row; - } - - drupal_set_title(t('Top visitors in the past %interval', array('%interval' => format_interval(config('statistics.settings')->get('access_log.max_lifetime')))), PASS_THROUGH); - $build['statistics_top_visitors_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_top_visitors_pager'] = array('#theme' => 'pager'); - return $build; -} - -/** - * Page callback: Displays the "top referrers" in the access logs. - * - * This displays the pages with the top referrers in a given time interval that - * haven't been flushed yet. The flush interval is set on the statistics - * settings form, but is dependent on cron running. - * - * @return array - * A render array containing the top referrers information. - */ -function statistics_top_referrers() { - drupal_set_title(t('Top referrers in the past %interval', array('%interval' => format_interval(config('statistics.settings')->get('access_log.max_lifetime')))), PASS_THROUGH); - - $header = array( - array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), - array('data' => t('Url'), 'field' => 'url'), - array('data' => t('Last visit'), 'field' => 'last'), - ); - $query = db_select('accesslog', 'a') - ->extend('Drupal\Core\Database\Query\PagerSelectExtender') - ->extend('Drupal\Core\Database\Query\TableSortExtender'); - - $query->addExpression('COUNT(url)', 'hits'); - $query->addExpression('MAX(timestamp)', 'last'); - $query - ->fields('a', array('url')) - ->condition('url', '%' . $_SERVER['HTTP_HOST'] . '%', 'NOT LIKE') - ->condition('url', '', '<>') - ->groupBy('url') - ->limit(30) - ->orderByHeader($header); - - $count_query = db_select('accesslog', 'a', array('target' => 'slave')); - $count_query->addExpression('COUNT(DISTINCT url)'); - $count_query - ->condition('url', '%' . $_SERVER['HTTP_HOST'] . '%', 'NOT LIKE') - ->condition('url', '', '<>'); - $query->setCountQuery($count_query); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $referrer) { - $rows[] = array($referrer->hits, _statistics_link($referrer->url), t('@time ago', array('@time' => format_interval(REQUEST_TIME - $referrer->last)))); - } - - $build['statistics_top_referrers_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_top_referrers_pager'] = array('#theme' => 'pager'); - return $build; -} - -/** - * Page callback: Gathers page access statistics suitable for rendering. - * - * @param int $aid - * The unique accesslog ID. - * - * @return array - * A render array containing page access statistics. If information for the - * page was not found, a NotFoundHttpException is thrown. - */ -function statistics_access_log($aid) { - $access = db_query('SELECT a.*, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE aid = :aid', array(':aid' => $aid))->fetch(); - if ($access) { - $rows[] = array( - array('data' => t('URL'), 'header' => TRUE), - l(url($access->path, array('absolute' => TRUE)), $access->path) - ); - // It is safe to avoid filtering $access->title through check_plain because - // it comes from drupal_get_title(). - $rows[] = array( - array('data' => t('Title'), 'header' => TRUE), - $access->title - ); - $rows[] = array( - array('data' => t('Referrer'), 'header' => TRUE), - ($access->url ? l($access->url, $access->url) : '') - ); - $rows[] = array( - array('data' => t('Date'), 'header' => TRUE), - format_date($access->timestamp, 'long') - ); - $rows[] = array( - array('data' => t('User'), 'header' => TRUE), - theme('username', array('account' => $access)) - ); - $rows[] = array( - array('data' => t('Hostname'), 'header' => TRUE), - check_plain($access->hostname) - ); - - $build['statistics_table'] = array( - '#theme' => 'table', - '#rows' => $rows, - ); - return $build; - } - else { - throw new NotFoundHttpException(); - } -} - -/** * Form constructor for the statistics administration form. * * @ingroup forms @@ -329,24 +15,6 @@ function statistics_access_log($aid) { */ function statistics_settings_form($form, &$form_state) { $config = config('statistics.settings'); - // Access log settings. - $form['access'] = array( - '#type' => 'details', - '#title' => t('Access log settings'), - ); - $form['access']['statistics_enable_access_log'] = array( - '#type' => 'checkbox', - '#title' => t('Enable access log'), - '#default_value' => $config->get('access_log.enabled'), - '#description' => t('Log each page access. Required for referrer statistics.'), - ); - $form['access']['statistics_flush_accesslog_timer'] = array( - '#type' => 'select', - '#title' => t('Discard access logs older than'), - '#default_value' => $config->get('access_log.max_lifetime'), - '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'), - '#description' => t('Older access log entries (including referrer statistics) will be automatically discarded. (Requires a correctly configured cron maintenance task.)', array('@cron' => url('admin/reports/status'))), - ); // Content counter settings. $form['content'] = array( @@ -368,8 +36,6 @@ function statistics_settings_form($form, &$form_state) { */ function statistics_settings_form_submit($form, &$form_state) { config('statistics.settings') - ->set('access_log.enabled', $form_state['values']['statistics_enable_access_log']) - ->set('access_log.max_lifetime', $form_state['values']['statistics_flush_accesslog_timer']) ->set('count_content_views', $form_state['values']['statistics_count_content_views']) ->save(); // The popular statistics block is dependent on these settings, so clear the diff --git a/core/modules/statistics/statistics.info b/core/modules/statistics/statistics.info index 4b18b8a..6c1b76d 100644 --- a/core/modules/statistics/statistics.info +++ b/core/modules/statistics/statistics.info @@ -1,5 +1,5 @@ name = Statistics -description = Logs access statistics for your site. +description = Logs content statistics for your site. package = Core version = VERSION core = 8.x diff --git a/core/modules/statistics/statistics.install b/core/modules/statistics/statistics.install index 5f2b7dd..6732eb0 100644 --- a/core/modules/statistics/statistics.install +++ b/core/modules/statistics/statistics.install @@ -18,79 +18,6 @@ function statistics_uninstall() { * Implements hook_schema(). */ function statistics_schema() { - $schema['accesslog'] = array( - 'description' => 'Stores site access information for statistics.', - 'fields' => array( - 'aid' => array( - 'type' => 'serial', - 'not null' => TRUE, - 'description' => 'Primary Key: Unique accesslog ID.', - ), - 'sid' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Browser session ID of user that visited page.', - ), - 'title' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'description' => 'Title of page visited.', - ), - 'path' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'description' => 'Internal path to page visited (relative to Drupal root.)', - ), - 'url' => array( - 'type' => 'text', - 'not null' => FALSE, - 'description' => 'Referrer URI.', - ), - 'hostname' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - 'description' => 'Hostname of user that visited the page.', - ), - 'uid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => FALSE, - 'default' => 0, - 'description' => 'User {users}.uid that visited the page.', - ), - 'timer' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Time in milliseconds that the page took to load.', - ), - 'timestamp' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Timestamp of when the page was visited.', - ), - ), - 'indexes' => array( - 'accesslog_timestamp' => array('timestamp'), - 'uid' => array('uid'), - ), - 'primary key' => array('aid'), - 'foreign keys' => array( - 'visitor' => array( - 'table' => 'users', - 'columns' => array('uid' => 'uid'), - ), - ), - ); - $schema['node_counter'] = array( 'description' => 'Access statistics for {node}s.', 'fields' => array( @@ -139,8 +66,6 @@ function statistics_schema() { function statistics_update_8000() { update_variables_to_config('statistics.settings', array( 'statistics_count_content_views' => 'count_content_views', - 'statistics_enable_access_log' => 'access_log.enabled', - 'statistics_flush_accesslog_timer' => 'access_log.max_lifetime', 'statistics_block_top_day_num' => 'block.popular.top_day_limit', 'statistics_block_top_all_num' => 'block.popular.top_all_limit', 'statistics_block_top_last_num' => 'block.popular.top_recent_limit', diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 2142be4..f356af1 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -2,7 +2,7 @@ /** * @file - * Logs and displays access statistics for a site. + * Logs and displays content statistics for a site. */ use Drupal\node\Plugin\Core\Entity\Node; @@ -15,17 +15,9 @@ function statistics_help($path, $arg) { case 'admin/help#statistics': $output = ''; $output .= '

' . t('About') . '

'; - $output .= '

' . t('The Statistics module shows you how often a given page is viewed, who viewed it, the previous page the user visited (referrer URL), and when it was viewed. These statistics are useful in determining how users are visiting and navigating your site. For more information, see the online handbook entry for the Statistics module.', array('@statistics' => url('http://drupal.org/documentation/modules/statistics/'))) . '

'; + $output .= '

' . t('The Statistics module shows you how often content is viewed. This is useful in determining which pages of your site are most popular. For more information, see the online handbook entry for the Statistics module.', array('@statistics' => url('http://drupal.org/documentation/modules/statistics/'))) . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; - $output .= '
' . t('Managing logs') . '
'; - $output .= '
' . t('To enable collection of statistics, the Enable access log checkbox on the Statistics settings page must be checked. The Discard access logs older than setting on the settings page specifies the length of time entries are kept in the log before they are deleted. This setting requires a correctly configured cron maintenance task to run.', array('@statistics-settings' => url('admin/config/system/statistics'), '@cron' => 'http://drupal.org/cron')) . '
'; - $output .= '
' . t('Viewing site usage') . '
'; - $output .= '
' . t('The Statistics module can help you break down details about your users and how they are using the site. The module offers four reports:'); - $output .= ''; $output .= '
' . t('Displaying popular content') . '
'; $output .= '
' . t('The module includes a Popular content block that displays the most viewed pages today and for all time, and the last content viewed. To use the block, enable Count content views on the statistics settings page, and then you can enable and configure the block on the blocks administration page.', array('@statistics-settings' => url('admin/config/system/statistics'), '@blocks' => url('admin/structure/block'))) . '
'; $output .= '
' . t('Page view counter') . '
'; @@ -34,50 +26,6 @@ function statistics_help($path, $arg) { return $output; case 'admin/config/system/statistics': return '

' . t('Settings for the statistical information that Drupal will keep about the site. See site statistics for the actual information.', array('@statistics' => url('admin/reports/hits'))) . '

'; - case 'admin/reports/hits': - return '

' . t("This page displays the site's most recent hits.") . '

'; - case 'admin/reports/referrers': - return '

' . t('This page displays all external referrers, or external references to your website.') . '

'; - case 'admin/reports/visitors': - return '

' . t("When you ban a visitor, you prevent the visitor's IP address from accessing your site. Unlike blocking a user, banning a visitor works even for anonymous users. This is most commonly used to block resource-intensive bots or web crawlers.") . '

'; - } -} - -/** - * Implements hook_exit(). - * - * Gathers statistics for page accesses. - */ -function statistics_exit() { - global $user; - - // When serving cached pages with the 'page_cache_without_database' - // configuration, system variables need to be loaded. This is a major - // performance decrease for non-database page caches, but with Statistics - // module, it is likely to also have 'statistics.settings:access_log.enabled' - // enabled, in which case we need to bootstrap to the session phase anyway. - drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); - - if (config('statistics.settings')->get('access_log.enabled')) { - drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); - - // For anonymous users unicode.inc will not have been loaded. - include_once DRUPAL_ROOT . '/core/includes/unicode.inc'; - // Log this page access. - db_insert('accesslog') - ->fields(array( - 'title' => truncate_utf8(strip_tags(drupal_get_title()), 255), - // @todo The public function current_path() is not available on a cache - // hit. - 'path' => truncate_utf8(_current_path(), 255), - 'url' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', - 'hostname' => ip_address(), - 'uid' => $user->uid, - 'sid' => session_id(), - 'timer' => (int) timer_read('page'), - 'timestamp' => REQUEST_TIME, - )) - ->execute(); } } @@ -89,9 +37,6 @@ function statistics_permission() { 'administer statistics' => array( 'title' => t('Administer statistics'), ), - 'access statistics' => array( - 'title' => t('View content access statistics'), - ), 'view post access counter' => array( 'title' => t('View content hits'), ), @@ -130,99 +75,19 @@ function statistics_node_view(Node $node, $view_mode) { * Implements hook_menu(). */ function statistics_menu() { - $items['admin/reports/hits'] = array( - 'title' => 'Recent hits', - 'description' => 'View pages that have recently been visited.', - 'page callback' => 'statistics_recent_hits', - 'access arguments' => array('access statistics'), - 'file' => 'statistics.admin.inc', - ); - $items['admin/reports/pages'] = array( - 'title' => 'Top pages', - 'description' => 'View pages that have been hit frequently.', - 'page callback' => 'statistics_top_pages', - 'access arguments' => array('access statistics'), - 'weight' => 1, - 'file' => 'statistics.admin.inc', - ); - $items['admin/reports/visitors'] = array( - 'title' => 'Top visitors', - 'description' => 'View visitors that hit many pages.', - 'page callback' => 'statistics_top_visitors', - 'access arguments' => array('access statistics'), - 'weight' => 2, - 'file' => 'statistics.admin.inc', - ); - $items['admin/reports/referrers'] = array( - 'title' => 'Top referrers', - 'description' => 'View top referrers.', - 'page callback' => 'statistics_top_referrers', - 'access arguments' => array('access statistics'), - 'file' => 'statistics.admin.inc', - ); - $items['admin/reports/access/%'] = array( - 'title' => 'Details', - 'description' => 'View access log.', - 'page callback' => 'statistics_access_log', - 'page arguments' => array(3), - 'access arguments' => array('access statistics'), - 'file' => 'statistics.admin.inc', - ); $items['admin/config/system/statistics'] = array( 'title' => 'Statistics', - 'description' => 'Control details about what and how your site logs access statistics.', + 'description' => 'Control details about what and how your site logs content statistics.', 'page callback' => 'drupal_get_form', 'page arguments' => array('statistics_settings_form'), 'access arguments' => array('administer statistics'), 'file' => 'statistics.admin.inc', 'weight' => -15, ); - $items['user/%user/track/navigation'] = array( - 'title' => 'Page visits', - 'page callback' => 'statistics_user_tracker', - 'access callback' => 'user_access', - 'access arguments' => array('access statistics'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'statistics.pages.inc', - ); - $items['node/%node/track'] = array( - 'title' => 'Track', - 'page callback' => 'statistics_node_tracker', - 'access callback' => 'user_access', - 'access arguments' => array('access statistics'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'statistics.pages.inc', - ); - return $items; } /** - * Implements hook_user_cancel(). - */ -function statistics_user_cancel($edit, $account, $method) { - switch ($method) { - case 'user_cancel_reassign': - db_update('accesslog') - ->fields(array('uid' => 0)) - ->condition('uid', $account->uid) - ->execute(); - break; - } -} - -/** - * Implements hook_user_predelete(). - */ -function statistics_user_predelete($account) { - db_delete('accesslog') - ->condition('uid', $account->uid) - ->execute(); -} - -/** * Implements hook_cron(). */ function statistics_cron() { @@ -235,14 +100,6 @@ function statistics_cron() { ->execute(); state()->set('statistics.day_timestamp', REQUEST_TIME); } - - // Delete access logs (if applicable). - $max_lifetime = config('statistics.settings')->get('access_log.max_lifetime'); - if ($max_lifetime > 0) { - db_delete('accesslog') - ->condition('timestamp', REQUEST_TIME - $max_lifetime, '<') - ->execute(); - } } /** diff --git a/core/modules/statistics/statistics.pages.inc b/core/modules/statistics/statistics.pages.inc deleted file mode 100644 index 6cf110c..0000000 --- a/core/modules/statistics/statistics.pages.inc +++ /dev/null @@ -1,138 +0,0 @@ - t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'), - array('data' => t('Referrer'), 'field' => 'a.url'), - array('data' => t('User'), 'field' => 'u.name'), - t('Operations'), - ); - - $query = db_select('accesslog', 'a', array('target' => 'slave')) - ->extend('Drupal\Core\Database\Query\PagerSelectExtender') - ->extend('Drupal\Core\Database\Query\TableSortExtender'); - $query->join('users', 'u', 'a.uid = u.uid'); - - $query - ->fields('a', array('aid', 'timestamp', 'url', 'uid')) - ->fields('u', array('name')) - ->condition(db_or() - ->condition('a.path', 'node/' . $node->nid) - ->condition('a.path', 'node/' . $node->nid . '/%', 'LIKE')) - ->limit(30) - ->orderByHeader($header); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $log) { - $row = array(); - $row[] = array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')); - $row[] = _statistics_link($log->url); - $row[] = theme('username', array('account' => $log)); - $links = array(); - $links['details'] = array( - 'title' => t('details'), - 'href' => "admin/reports/access/$log->aid", - ); - $row[] = array( - 'data' => array( - '#type' => 'operations', - '#links' => $links, - ), - ); - $rows[] = $row; - } - - // Do not use $node->label() here, because $node comes from the database. - drupal_set_title($node->title); - $build['statistics_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_pager'] = array('#theme' => 'pager'); - return $build; - } - else { - throw new NotFoundHttpException(); - } -} - -/** - * Page callback: Displays statistics for a user. - * - * @return array - * A render array containing user statistics. If information for the user was - * not found, this will throw a NotFoundHttpException. - * - * @see statistics_menu() - */ -function statistics_user_tracker() { - if ($account = user_load(arg(1))) { - - $header = array( - array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'), - array('data' => t('Page'), 'field' => 'path'), - t('Operations'), - ); - $query = db_select('accesslog', 'a', array('target' => 'slave')) - ->extend('Drupal\Core\Database\Query\PagerSelectExtender') - ->extend('Drupal\Core\Database\Query\TableSortExtender'); - $query - ->fields('a', array('aid', 'timestamp', 'path', 'title')) - ->condition('uid', $account->uid) - ->limit(30) - ->orderByHeader($header); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $log) { - $row = array(); - $row[] = array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')); - $row[] = _statistics_format_item($log->title, $log->path); - $links = array(); - $links['details'] = array( - 'title' => t('details'), - 'href' => "admin/reports/access/$log->aid", - ); - $row[] = array( - 'data' => array( - '#type' => 'operations', - '#links' => $links, - ), - ); - $rows[] = $row; - } - - drupal_set_title(user_format_name($account)); - $build['statistics_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_pager'] = array('#theme' => 'pager'); - return $build; - } - else { - throw new NotFoundHttpException(); - } -}