2015-08-17 17:00:26 -07:00
<?php
/**
* @file
* Install and update functions for the Statistics module.
*/
/**
* Implements hook_uninstall().
*/
function statistics_uninstall() {
// Remove states.
\Drupal::state()->delete('statistics.node_counter_scale');
\Drupal::state()->delete('statistics.day_timestamp');
}
/**
* Implements hook_schema().
*/
function statistics_schema() {
2017-04-13 15:53:35 +01:00
$schema['node_counter'] = [
2015-08-17 17:00:26 -07:00
'description' => 'Access statistics for {node}s.',
2017-04-13 15:53:35 +01:00
'fields' => [
'nid' => [
2015-08-17 17:00:26 -07:00
'description' => 'The {node}.nid for these statistics.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
2017-04-13 15:53:35 +01:00
],
'totalcount' => [
2015-08-17 17:00:26 -07:00
'description' => 'The total number of times the {node} has been viewed.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'big',
2017-04-13 15:53:35 +01:00
],
'daycount' => [
2015-08-17 17:00:26 -07:00
'description' => 'The total number of times the {node} has been viewed today.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'medium',
2017-04-13 15:53:35 +01:00
],
'timestamp' => [
2015-08-17 17:00:26 -07:00
'description' => 'The most recent time the {node} has been viewed.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
2017-04-13 15:53:35 +01:00
],
],
'primary key' => ['nid'],
];
2015-08-17 17:00:26 -07:00
return $schema;
}
2015-09-04 13:20:09 -07:00
/**
* Disable the Statistics module if the node module is not enabled.
*/
function statistics_update_8001() {
if (!\Drupal::moduleHandler()->moduleExists('node')) {
2017-04-13 15:53:35 +01:00
if (\Drupal::service('module_installer')->uninstall(['statistics'], TRUE)) {
2015-09-04 13:20:09 -07:00
return 'The statistics module depends on the node module and has therefore been uninstalled.';
}
else {
return 'There was an error uninstalling the statistcs module.';
}
}
}
2015-10-08 11:40:12 -07:00
/**
* Disable the Statistics module if the node module is not enabled.
*/
function statistics_update_8002() {
// Set the new configuration setting for max age to the initial value.
\Drupal::configFactory()->getEditable('statistics.settings')->set('display_max_age', 3600)->save();
}
2017-04-13 15:53:35 +01:00
/**
* Remove access_log settings.
*/
function statistics_update_8300() {
\Drupal::configFactory()->getEditable('statistics.settings')->clear('access_log')->save();
}