You are here

file_download_counter.install in File Download 8

Install and update functions for the Statistics module.

File

modules/file_download_counter/file_download_counter.install
View source
<?php

/**
 * @file
 * Install and update functions for the Statistics module.
 */

/**
 * Implements hook_uninstall().
 */
function file_download_counter_uninstall() {

  // Remove states.
  \Drupal::state()
    ->delete('file_download.node_counter_scale');
  \Drupal::state()
    ->delete('file_download.day_timestamp');
}

/**
 * Implements hook_schema().
 */
function file_download_counter_schema() {
  $schema['file_download_counter'] = [
    'description' => 'Access statistics for {node}s.',
    'fields' => [
      'fid' => [
        'description' => 'The {file}.fid for these statistics.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'totalcount' => [
        'description' => 'The total number of times the {file} has been downloaded.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ],
      'daycount' => [
        'description' => 'The total number of times the {file} has been downloaded today.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'medium',
      ],
      'timestamp' => [
        'description' => 'The most recent time the {file} has been downloaded.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'fid',
    ],
  ];
  return $schema;
}

/**
 * Disable the Statistics module if the node module is not enabled.
 */
function file_download_counter_update_8001() {
  if (!\Drupal::moduleHandler()
    ->moduleExists('node')) {
    if (\Drupal::service('module_installer')
      ->uninstall([
      'file_download_counter',
    ], TRUE)) {
      return 'The statistics module depends on the node module and has therefore been uninstalled.';
    }
    else {
      return 'There was an error uninstalling the file download counter module.';
    }
  }
}

/**
 * Disable the Statistics module if the node module is not enabled.
 */
function file_download_counter_update_8002() {

  // Set the new configuration setting for max age to the initial value.
  \Drupal::configFactory()
    ->getEditable('file_download_counter.settings')
    ->set('display_max_age', 3600)
    ->save();
}

Functions

Namesort descending Description
file_download_counter_schema Implements hook_schema().
file_download_counter_uninstall Implements hook_uninstall().
file_download_counter_update_8001 Disable the Statistics module if the node module is not enabled.
file_download_counter_update_8002 Disable the Statistics module if the node module is not enabled.