You are here

ip_login.install in IP Login 6.2

Same filename and directory in other branches
  1. 7.3 ip_login.install
  2. 7.2 ip_login.install

Install file of the IP Login module.

File

ip_login.install
View source
<?php

/**
 * @file
 * Install file of the IP Login module.
 */

/**
 * Implementation of hook_install().
 */
function ip_login_install() {
  drupal_install_schema('ip_login');
  drupal_set_message(st('IP Login settings are available under <a href="@link">Administer > Site configuration > IP Login settings</a>.', array(
    '@link' => 'admin/settings/ip_login',
  )));
  variable_set('ip_login_enabled', 1);
}

/**
 * Implementation of hook_schema().
 */
function ip_login_schema() {
  $schema['ip_login_user'] = array(
    'description' => t('Stores the IP Login address and range matches for users'),
    'fields' => array(
      'uid' => array(
        'description' => t('ID of user for IP Login'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'ip_match' => array(
        'description' => t('IP ranges and addresses'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'uid',
    ),
  );
  return $schema;
}

/*
 * Implementation of hook_uninstall().
 */
function ip_login_uninstall() {
  drupal_uninstall_schema('ip_login');
  variable_del('ip_login_active_pages');
  variable_del('ip_login_enabled');
  variable_del('ip_login_destination');
  variable_del('ip_login_link_login_block');
  variable_del('ip_login_link_login_block_weight');
  variable_del('ip_login_link_login_page');
  variable_del('ip_login_link_login_page_help');
  variable_del('ip_login_link_login_page_weight');
  variable_del('ip_login_suppress_messages');
}

/**
 * Drupal 6.x-1x to 2x (Profile field -> IP Login User table) update.
 */
function ip_login_update_6200() {

  // this update function needs it's own copy of the schema! http://drupal.org/node/150220
  $schema['ip_login_user'] = array(
    'description' => t('Stores the IP Login address and range matches for users'),
    'fields' => array(
      'uid' => array(
        'description' => t('ID of user for IP Login'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'ip_match' => array(
        'description' => t('IP ranges and addresses'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
  );

  // add table
  $ret = array();
  db_create_table($ret, 'ip_login_user', $schema['ip_login_user']);
  db_add_index($ret, 'ip_login_user', 'uid', array(
    'uid',
  ));

  // import old profile values into new ip_login_user table
  $profile_ranges = db_query("SELECT pv.uid, pv.value FROM {profile_values} pv\n     INNER JOIN {profile_fields} pf ON pv.fid = pf.fid\n     WHERE pf.name = '%s' AND pv.value", variable_get('ip_login_profile_ip_field', 'profile_ip'));
  while ($row = db_fetch_object($profile_ranges)) {
    _ip_login_set_user_range($row->uid, $row->value);
  }

  // tell user
  $ret[] = array(
    'success' => TRUE,
    'query' => t('Imported the user IP ranges from Profile field %fieldname. You may remove this field - and also disable the Profile module IF you are not using it for anything else.', array(
      '%fieldname' => variable_get('ip_login_profile_ip_field', 'profile_ip'),
    )),
  );

  // remove old IP login 6.x-1.x variables not needed, done
  variable_del('ip_login_profile_ip_field');
  return $ret;
}

Functions

Namesort descending Description
ip_login_install Implementation of hook_install().
ip_login_schema Implementation of hook_schema().
ip_login_uninstall
ip_login_update_6200 Drupal 6.x-1x to 2x (Profile field -> IP Login User table) update.