You are here

commerce_file.install in Commerce File 7.2

Same filename and directory in other branches
  1. 8.2 commerce_file.install
  2. 7 commerce_file.install

File

commerce_file.install
View source
<?php

/**
 * Implements hook_requirements().
 */
function commerce_file_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $int64_ok = PHP_INT_MAX === 9223372036854775807;
    $requirements['commerce_file_int64'] = array(
      'title' => t('Support for files larger than 2GB'),
      'value' => $int64_ok ? t('Available') : t('Unavailable'),
      'description' => t('A 64-bit PHP installation is required in order to support files larger than 2GB.'),
      'severity' => $int64_ok ? REQUIREMENT_OK : REQUIREMENT_WARNING,
    );
  }
  return $requirements;
}

/**
 * Implements hook_schema().
 */
function commerce_file_schema() {

  // Provides a temporary download log, used for setting download limits.
  // Not meant to be user viewable.
  $schema['commerce_file_download_log'] = array(
    'fields' => array(
      'log_id' => array(
        'description' => 'The primary key.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'license_id' => array(
        'description' => 'The {commerce_license}.license_id of the downloaded file.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'fid' => array(
        'description' => 'The {file_managed}.fid of the downloaded file.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => 'The {users}.uid of the user that downloaded the file.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'timestamp' => array(
        'description' => 'The UNIX timestamp of the date the file was downloaded.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'ip_address' => array(
        'description' => 'The IP address of the user that downloaded the file.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'log_id',
    ),
    'indexes' => array(
      'license_id' => array(
        'license_id',
      ),
      'fid' => array(
        'fid',
      ),
      'uid' => array(
        'uid',
      ),
    ),
    'foreign keys' => array(
      'licenses' => array(
        'table' => 'commerce_license',
        'columns' => array(
          'license_id' => 'license_id',
        ),
      ),
      'file_managed' => array(
        'table' => 'file_managed',
        'columns' => array(
          'fid' => 'fid',
        ),
      ),
      'users' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function commerce_file_install() {

  // Convert the filesize column to a bigint in order to remove the 4GB limit.
  $spec = array(
    'description' => 'The size of the file in bytes.',
    'type' => 'int',
    'size' => 'big',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_change_field('file_managed', 'filesize', 'filesize', $spec);
}

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

  // Delete the fields created and attached to this module's bundles.
  field_attach_delete_bundle('commerce_license', 'file');

  // Delete the product field.
  field_delete_field('commerce_file');

  // Delete variable settings.
  variable_del('commerce_file_product_types');
  variable_del('commerce_file_enable_download_limit');
  variable_del('commerce_file_download_limit');
}

/**
 * Create the download log table.
 */
function commerce_file_update_7200() {
  $schema = commerce_file_schema();
  db_create_table('commerce_file_download_log', $schema['commerce_file_download_log']);
}

Functions