You are here

gotwo.install in Go - url redirects 7

Same filename and directory in other branches
  1. 5 gotwo.install
  2. 6 gotwo.install

Installation script for the gotwo.module

File

gotwo.install
View source
<?php

/**
 * @file
 * Installation script for the gotwo.module
 */

/**
 * Implements hook_uninstall().
 */
function gotwo_uninstall() {
  variable_del('gotwo_numeric');
  variable_del('gotwo_max_length');
  variable_del('gotwo_transliteration');
  variable_del('gotwo_separator');
  variable_del('gotwo_disclaimer_boolean');
  variable_del('gotwo_disclaimer_title');
  variable_del('gotwo_disclaimer_time');
  variable_del('gotwo_disclaimer_text');
}

/**
 * Implements hook_schema().
 */
function gotwo_schema() {
  $schema['gotwo'] = array(
    'description' => 'Stores gotwo settings.',
    'fields' => array(
      'gid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique gotwo ID.',
      ),
      'src' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The label used in the go url, this will automatically be made suitable.',
      ),
      'dst' => array(
        'type' => 'varchar',
        'length' => 2048,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The target url. Can be a relative drupal url or an absolute url.',
      ),
      'cnt' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Count clicks on the link.',
      ),
    ),
    'unique keys' => array(
      'src' => array(
        'src',
      ),
    ),
    'primary key' => array(
      'gid',
    ),
  );
  return $schema;
}

/**
 * Update the permissions table, to reflect changes to hook_perm.
 */
function gotwo_update_6100() {
  $permissions = array(
    'view gotwo entries' => 'view gotwo redirects',
    'edit gotwo entries' => 'edit gotwo redirects',
  );
  foreach ($permissions as $permission_old => $permission_new) {
    db_update('role_permission')
      ->fields(array(
      'permission' => $permission_new,
    ))
      ->condition('permission', $permission_old)
      ->condition('module', 'gotwo')
      ->execute();
  }
  return t('Gotwo permission have been renamed.');
}

/**
 * Change 'gid' column to auto increment.
 */
function gotwo_update_6101() {
  db_change_field('gotwo', 'gid', 'gid', array(
    'type' => 'serial',
    'not null' => TRUE,
  ));
  return t('GID database column has been altered to auto increment.');
}

/**
 * Extend the length of 'dst' column to 255.
 */
function gotwo_update_6102() {
  db_change_field('gotwo', 'dst', 'dst', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ));
  return t('URL length for destination has been extended to 255 chars.');
}

/**
 * Validate maximum length of target labels setting.
 */
function gotwo_update_7100() {
  $max_length = min(variable_get('gotwo_max_length', 128), 128);
  variable_set('gotwo_max_length', $max_length);
  return t('Maximum length of target labels setting may has been reduced to max 128.');
}

/**
 * Extend the length of 'dst' column to 2048.
 */
function gotwo_update_7101() {
  db_change_field('gotwo', 'dst', 'dst', array(
    'type' => 'varchar',
    'length' => 2048,
    'not null' => TRUE,
    'default' => '',
  ));
  return t('URL length for destination has been extended to 2048 chars.');
}

Functions

Namesort descending Description
gotwo_schema Implements hook_schema().
gotwo_uninstall Implements hook_uninstall().
gotwo_update_6100 Update the permissions table, to reflect changes to hook_perm.
gotwo_update_6101 Change 'gid' column to auto increment.
gotwo_update_6102 Extend the length of 'dst' column to 255.
gotwo_update_7100 Validate maximum length of target labels setting.
gotwo_update_7101 Extend the length of 'dst' column to 2048.