Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -19,13 +19,13 @@ function statistics_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.statistics':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . 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 <a href=":statistics_do">online documentation for the Statistics module</a>.', array(':statistics_do' => 'https://www.drupal.org/documentation/modules/statistics/')) . '</p>';
$output .= '<p>' . 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 <a href=":statistics_do">online documentation for the Statistics module</a>.', [':statistics_do' => 'https://www.drupal.org/documentation/modules/statistics/']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Displaying popular content') . '</dt>';
$output .= '<dd>' . t('The module includes a <em>Popular content</em> block that displays the most viewed pages today and for all time, and the last content viewed. To use the block, enable <em>Count content views</em> on the <a href=":statistics-settings">Statistics page</a>, and then you can enable and configure the block on the <a href=":blocks">Block layout page</a>.', array(':statistics-settings' => \Drupal::url('statistics.settings'), ':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#')) . '</dd>';
$output .= '<dd>' . t('The module includes a <em>Popular content</em> block that displays the most viewed pages today and for all time, and the last content viewed. To use the block, enable <em>Count content views</em> on the <a href=":statistics-settings">Statistics page</a>, and then you can enable and configure the block on the <a href=":blocks">Block layout page</a>.', [':statistics-settings' => \Drupal::url('statistics.settings'), ':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#']) . '</dd>';
$output .= '<dt>' . t('Page view counter') . '</dt>';
$output .= '<dd>' . t('The Statistics module includes a counter for each page that increases whenever the page is viewed. To use the counter, enable <em>Count content views</em> on the <a href=":statistics-settings">Statistics page</a>, and set the necessary <a href=":permissions">permissions</a> (<em>View content hits</em>) so that the counter is visible to the users.', array(':statistics-settings' => \Drupal::url('statistics.settings'), ':permissions' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-statistics')))) . '</dd>';
$output .= '<dd>' . t('The Statistics module includes a counter for each page that increases whenever the page is viewed. To use the counter, enable <em>Count content views</em> on the <a href=":statistics-settings">Statistics page</a>, and set the necessary <a href=":permissions">permissions</a> (<em>View content hits</em>) so that the counter is visible to the users.', [':statistics-settings' => \Drupal::url('statistics.settings'), ':permissions' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-statistics'])]) . '</dd>';
$output .= '</dl>';
return $output;
@ -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 = array('data' => array('nid' => $node->id()), 'url' => Url::fromUri('base:' . drupal_get_path('module', 'statistics') . '/statistics.php')->toString());
$settings = ['data' => ['nid' => $node->id()], 'url' => Url::fromUri('base:' . drupal_get_path('module', 'statistics') . '/statistics.php')->toString()];
$build['#attached']['drupalSettings']['statistics'] = $settings;
}
}
@ -52,14 +52,14 @@ function statistics_node_links_alter(array &$links, NodeInterface $entity, array
if ($context['view_mode'] != 'rss') {
$links['#cache']['contexts'][] = 'user.permissions';
if (\Drupal::currentUser()->hasPermission('view post access counter')) {
$statistics = statistics_get($entity->id());
$statistics = \Drupal::service('statistics.storage.node')->fetchView($entity->id());
if ($statistics) {
$statistics_links['statistics_counter']['title'] = \Drupal::translation()->formatPlural($statistics['totalcount'], '1 view', '@count views');
$links['statistics'] = array(
$statistics_links['statistics_counter']['title'] = \Drupal::translation()->formatPlural($statistics->getTotalCount(), '1 view', '@count views');
$links['statistics'] = [
'#theme' => 'links__node__statistics',
'#links' => $statistics_links,
'#attributes' => array('class' => array('links', 'inline')),
);
'#attributes' => ['class' => ['links', 'inline']],
];
}
$links['#cache']['max-age'] = \Drupal::config('statistics.settings')->get('display_max_age');
}
@ -70,18 +70,10 @@ function statistics_node_links_alter(array &$links, NodeInterface $entity, array
* Implements hook_cron().
*/
function statistics_cron() {
$statistics_timestamp = \Drupal::state()->get('statistics.day_timestamp') ?: 0;
if ((REQUEST_TIME - $statistics_timestamp) >= 86400) {
// Reset day counts.
db_update('node_counter')
->fields(array('daycount' => 0))
->execute();
\Drupal::state()->set('statistics.day_timestamp', REQUEST_TIME);
}
// Calculate the maximum of node views, for node search ranking.
\Drupal::state()->set('statistics.node_counter_scale', 1.0 / max(1.0, db_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchField()));
$storage = \Drupal::service('statistics.storage.node');
$storage->resetDayCount();
$max_total_count = $storage->maxTotalCount();
\Drupal::state()->set('statistics.node_counter_scale', 1.0 / max(1.0, $max_total_count));
}
/**
@ -101,15 +93,15 @@ function statistics_cron() {
* be executed correctly.
*/
function statistics_title_list($dbfield, $dbrows) {
if (in_array($dbfield, array('totalcount', 'daycount', 'timestamp'))) {
if (in_array($dbfield, ['totalcount', 'daycount', 'timestamp'])) {
$query = db_select('node_field_data', 'n');
$query->addTag('node_access');
$query->join('node_counter', 's', 'n.nid = s.nid');
$query->join('users_field_data', 'u', 'n.uid = u.uid');
return $query
->fields('n', array('nid', 'title'))
->fields('u', array('uid', 'name'))
->fields('n', ['nid', 'title'])
->fields('u', ['uid', 'name'])
->condition($dbfield, 0, '<>')
->condition('n.status', 1)
// @todo This should be actually filtering on the desired node status
@ -123,26 +115,21 @@ function statistics_title_list($dbfield, $dbrows) {
return FALSE;
}
/**
* Retrieves a node's "view statistics".
*
* @param int $nid
* The node ID.
*
* @return array
* An associative array containing:
* - totalcount: Integer for the total number of times the node has been
* viewed.
* - daycount: Integer for the total number of times the node has been viewed
* "today". For the daycount to be reset, cron must be enabled.
* - timestamp: Integer for the timestamp of when the node was last viewed.
* @deprecated in Drupal 8.2.x, will be removed before Drupal 9.0.0.
* Use \Drupal::service('statistics.storage.node')->fetchView($id).
*/
function statistics_get($nid) {
if ($nid > 0) {
// Retrieve an array with both totalcount and daycount.
return db_query('SELECT totalcount, daycount, timestamp FROM {node_counter} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'replica'))->fetchAssoc();
function statistics_get($id) {
if ($id > 0) {
/** @var \Drupal\statistics\StatisticsViewsResult $statistics */
$statistics = \Drupal::service('statistics.storage.node')->fetchView($id);
return [
'totalcount' => $statistics->getTotalCount(),
'daycount' => $statistics->getDayCount(),
'timestamp' => $statistics->getTimestamp(),
];
}
}
@ -151,9 +138,8 @@ function statistics_get($nid) {
*/
function statistics_node_predelete(EntityInterface $node) {
// Clean up statistics table when node is deleted.
db_delete('node_counter')
->condition('nid', $node->id())
->execute();
$id = $node->id();
return \Drupal::service('statistics.storage.node')->deleteViews($id);
}
/**
@ -161,15 +147,15 @@ function statistics_node_predelete(EntityInterface $node) {
*/
function statistics_ranking() {
if (\Drupal::config('statistics.settings')->get('count_content_views')) {
return array(
'views' => array(
return [
'views' => [
'title' => t('Number of views'),
'join' => array(
'join' => [
'type' => 'LEFT',
'table' => 'node_counter',
'alias' => 'node_counter',
'on' => 'node_counter.nid = i.sid',
),
],
// Inverse law that maps the highest view count on the site to 1 and 0
// to 0. Note that the ROUND here is necessary for PostgreSQL and SQLite
// in order to ensure that the :statistics_scale argument is treated as
@ -177,9 +163,9 @@ function statistics_ranking() {
// values in as strings instead of numbers in complex expressions like
// this.
'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * (ROUND(:statistics_scale, 4)))',
'arguments' => array(':statistics_scale' => \Drupal::state()->get('statistics.node_counter_scale') ?: 0),
),
);
'arguments' => [':statistics_scale' => \Drupal::state()->get('statistics.node_counter_scale') ?: 0],
],
];
}
}