You are here

services_keyauth.install in Services 7

Same filename and directory in other branches
  1. 6.2 auth/services_keyauth/services_keyauth.install

@author Services Dev Team

Install, uninstall and update the module.

File

auth/services_keyauth/services_keyauth.install
View source
<?php

/**
 * @author Services Dev Team
 * @file
 *   Install, uninstall and update the module.
 */

/**
 * Implements hook_schema().
 */
function services_keyauth_schema() {
  $schema['services_keys'] = array(
    'description' => 'Stores all Service keys.',
    'fields' => array(
      'kid' => array(
        'description' => 'The service key ID.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'title' => array(
        'description' => 'The title of the service key.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'domain' => array(
        'description' => 'The domain of the service key.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'kid',
    ),
  );
  $schema['services_timestamp_nonce'] = array(
    'description' => 'Stores timestamp against nonce for repeat attacks.',
    'fields' => array(
      'timestamp' => array(
        'description' => 'The timestamp used with the Nonce.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'nonce' => array(
        'description' => 'The random string used on the request.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'domain' => array(
        'description' => 'The domain that submitted the request.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'indexes' => array(
      'timestamp' => array(
        'timestamp',
      ),
      'nonce' => array(
        'nonce',
      ),
    ),
  );
  $schema['services_key_permissions'] = array(
    'description' => 'Stores services method\'s access rights on a per API key basis.',
    'fields' => array(
      'kid' => array(
        'description' => 'The service key ID.',
        'type' => 'char',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'method' => array(
        'description' => 'Name of service method.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'indexes' => array(
      'api_key' => array(
        'kid',
      ),
      'method' => array(
        'method',
      ),
    ),
    'unique key' => array(
      'key_method' => array(
        'kid',
        'method',
      ),
    ),
  );
  return $schema;
}
function _services_key_auth_permissions() {
  $schema['services_key_permissions'] = array(
    'description' => 'Stores services method\'s access rights on a per API key basis.',
    'fields' => array(
      'kid' => array(
        'description' => 'The service key ID.',
        'type' => 'char',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'method' => array(
        'description' => 'Name of service method.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'indexes' => array(
      'api_key' => array(
        'kid',
      ),
      'method' => array(
        'method',
      ),
    ),
    'unique key' => array(
      'key_method' => array(
        'kid',
        'method',
      ),
    ),
  );
  db_create_table('services_key_permissions', $schema['services_key_permissions']);
}

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

  // Legacy tables exist so we just create the new table.
  if (!db_table_exists('services_keys')) {
    drupal_install_schema('services_keyauth');
  }
  else {
    $update = array();
    _services_key_auth_permissions();
  }
}

/**
 * Implements hook_uninstall().
 */
function services_keyauth_uninstall() {
  drupal_uninstall_schema('services_keyauth');
  variable_del('services_use_key');
  variable_del('services_use_sessid');
}
function services_keyauth_update_6001() {
  $update = array();
  _services_key_auth_permissions();
  return $update;
}
function services_keyauth_update_6002() {
  db_drop_primary_key('services_timestamp_nonce');
  db_add_index('services_timestamp_nonce', 'nonce', array(
    'nonce',
  ));
}
function services_keyauth_update_6003() {
  db_drop_index('services_timestamp_nonce', 'timestamp');
  db_change_field('services_timestamp_nonce', 'timestamp', 'timestamp', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_index('services_timestamp_nonce', 'timestamp', array(
    'timestamp',
  ));
}

/*
 * Update to ensure that new menu options are loaded.
 */
function services_keyauth_update_6004() {
}
function services_keyauth_update_6005() {

  // A table might fail to exist in certain circumstances due to an issue with the install.
  if (!db_table_exists('services_key_permissions')) {
    _services_key_auth_permissions();
  }
}