download_count.install in Open Social 8
Same filename and directory in other branches
- 8.9 modules/custom/download_count/download_count.install
- 8.2 modules/custom/download_count/download_count.install
- 8.3 modules/custom/download_count/download_count.install
- 8.4 modules/custom/download_count/download_count.install
- 8.5 modules/custom/download_count/download_count.install
- 8.6 modules/custom/download_count/download_count.install
- 8.7 modules/custom/download_count/download_count.install
- 8.8 modules/custom/download_count/download_count.install
- 10.3.x modules/custom/download_count/download_count.install
- 10.0.x modules/custom/download_count/download_count.install
- 10.1.x modules/custom/download_count/download_count.install
- 10.2.x modules/custom/download_count/download_count.install
Installation code for the download_count module.
File
modules/custom/download_count/download_count.installView source
<?php
/**
* @file
* Installation code for the download_count module.
*/
use Drupal\user\Entity\Role;
/**
* Implements hook_schema().
*/
function download_count_schema() {
$schema['download_count'] = [
'fields' => [
'dcid' => [
'description' => 'Primary Key: Unique download count id.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'fid' => [
'description' => 'The {file_managed}.fid of the file downloaded.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'uid' => [
'description' => 'The {user}.uid of user who downloaded the file.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'type' => [
'description' => 'The name of the entity type to which the file was attached when downloaded.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
],
'id' => [
'description' => 'The primary key of the entity to which the file was attached when downloaded.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'ip_address' => [
'description' => 'The IP address of the downloading user.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
],
'referrer' => [
'description' => 'Referrer URI.',
'type' => 'text',
'not null' => TRUE,
],
'timestamp' => [
'description' => 'The date-time the file was downloaded.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => [
'dcid',
],
'indexes' => [
'dc_fid' => [
'fid',
],
'dc_uid' => [
'uid',
],
'dc_type' => [
'type',
],
'dc_id' => [
'id',
],
'dc_ip' => [
'ip_address',
],
'dc_timestamp' => [
'timestamp',
],
'dc_fid_type_id' => [
'fid',
'type',
'id',
],
],
];
return $schema;
}
/**
* Implements hook_uninstall().
*/
function download_count_uninstall() {
\Drupal::service('config.factory')
->getEditable('download_count.settings')
->delete();
drupal_set_message(t('The download count module has been uninstalled.'));
}
/**
* Implements hook_install().
*
* Perform actions related to the installation of download_count.
*/
function download_count_install() {
// Set some default permissions.
_download_count_set_permissions();
}
/**
* Function to set permissions.
*/
function _download_count_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'administrator') {
continue;
}
$permissions = [
'view download counts',
];
user_role_grant_permissions($role
->id(), $permissions);
}
}
/**
* Increase download count flood window from 2 to 5 seconds.
*/
function download_count_update_8001(&$sandbox) {
$config = \Drupal::service('config.factory')
->getEditable('download_count.settings');
$config
->set('download_count_flood_window', 5);
$config
->save();
}
Functions
Name | Description |
---|---|
download_count_install | Implements hook_install(). |
download_count_schema | Implements hook_schema(). |
download_count_uninstall | Implements hook_uninstall(). |
download_count_update_8001 | Increase download count flood window from 2 to 5 seconds. |
_download_count_set_permissions | Function to set permissions. |