You are here

session_api.install in Session API 7

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

Install file for Session API.

File

session_api.install
View source
<?php

/**
 * @file
 * Install file for Session API.
 */

/**
 * Implements hook_schema().
 */
function session_api_schema() {
  $schema['session_api'] = array(
    'description' => 'Map Session API IDs to the {sessions} sid field.',
    'fields' => array(
      'sid' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'session_id' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'sid',
    ),
    'unique keys' => array(
      'session_id' => array(
        'session_id',
      ),
    ),
    'indexes' => array(
      'timestamp' => array(
        'timestamp',
      ),
    ),
  );
  return $schema;
}

/**
 * Remove cleanup variables.
 */
function session_api_update_6100() {
  $ret = array();
  $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'session_api_run_cron_%'");
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Adds timestamp field.
 */
function session_api_update_7101() {
  db_add_field('session_api', 'timestamp', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_index('session_api', 'timestamp', array(
    'timestamp',
  ));
  return t('Added a timestamp field and index to the session_api table.');
}

/**
 * Implements hook_update_N().
 *
 * Lengthens the session_id field to match core {sessions}.sid field.
 */
function session_api_update_7102() {
  db_change_field('session_api', 'session_id', 'session_id', array(
    'type' => 'varchar',
    'length' => 128,
    'not null' => TRUE,
  ));
}

/**
 * Implements hook_update_N().
 *
 * Sets the expire time to 0 if it was previously set to -1.
 */
function session_api_update_7103() {
  if (variable_get('session_api_cookie_expire_time', 2592000) == -1) {
    variable_set('session_api_cookie_expire_time', 0);
  }
}

Functions