You are here

gauth.install in Google Auth 7

Same filename and directory in other branches
  1. 8 gauth.install
  2. 7.2 gauth.install

Install and uninstall functions for the Google OAuth module.

File

gauth.install
View source
<?php

/**
 * @file
 * Install and uninstall functions for the Google OAuth module.
 */

/**
 * Implements hook_schema().
 */
function gauth_schema() {
  $schema['gauth_accounts'] = array(
    'description' => 'Google OAuth2 api information.',
    'fields' => array(
      'id' => array(
        'description' => 'A unique identifier for the google api.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'The account name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'developer_key' => array(
        'description' => 'The api key for Google Access.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'client_id' => array(
        'description' => 'The Client Id of Google Account.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'client_secret' => array(
        'description' => 'The Client Secret Id of Google Account.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'services' => array(
        'description' => 'The OAuth account is used for which services.',
        'type' => 'text',
      ),
      'access_token' => array(
        'description' => 'The OAuth access token.',
        'type' => 'text',
      ),
      'access_type' => array(
        'description' => 'Stores the access type of the account',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'offline',
      ),
      'is_authenticated' => array(
        'description' => 'Is the account authenticated and ready to use?.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The users uid of the user who created the gauth account.',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  $schema['cache_gauth_scopes'] = drupal_get_schema_unprocessed('system', 'cache');
  return $schema;
}

/**
 * Implements hook_install().
 */
function gauth_install() {
  drupal_install_schema('gauth');
}

/**
 * Implements hook_uninstall().
 */
function gauth_uninstall() {
  drupal_uninstall_schema('gauth');
  variable_del('gauth_google_api_services');
}

/**
 * Implements hook_requirements().
 */
function gauth_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $t = get_t();
    $requirements['gauth'] = array(
      'title' => $t('Google OAuth2'),
      'value' => '',
      'description' => '',
      'severity' => REQUIREMENT_OK,
    );
    $info = libraries_detect('google-api-php-client');
    if (!$info['installed']) {
      $url = l($t('here'), $info['download url']);
      $documentation = l($t('google api php client installation'), 'https://github.com/google/google-api-php-client#installation');
      $version = isset($info['versions']) && !empty($info['versions']) ? array_keys($info['versions']) : array(
        '2.0.0',
      );
      $requirements['gauth']['description'] = $t('Install version "@version" or latest version of the Google api php client library code (from !here) in a libraries directory such as "sites/all/libraries/google-api-php-client". You can also use composer to install, read more at !documentation.  The path should be "sites/all/libraries/google-api-php-client"', array(
        '@version' => $version[0],
        '!here' => $url,
        '!documentation' => $documentation,
      ));
      $requirements['gauth']['severity'] = REQUIREMENT_ERROR;
    }
    else {
      $requirements['gauth']['value'] = $t($info['version']);
    }
  }
  return $requirements;
}

/**
 * Add the gauth_accounts.uid field.
 */
function gauth_update_7002() {
  $field = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
    'description' => 'The {users}.uid of the user who created the redirect.',
  );
  db_add_field('gauth_accounts', 'uid', $field);
  db_update('gauth_accounts')
    ->fields(array(
    'uid' => 1,
  ))
    ->execute();
}

/**
 * Add the gauth_accounts.access_type field.
 */
function gauth_update_7003() {
  $field = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => 'offline',
    'description' => 'Stores the access type of the account.',
  );
  db_add_field('gauth_accounts', 'access_type', $field);
  db_update('gauth_accounts')
    ->fields(array(
    'access_type' => 'offline',
  ))
    ->execute();
}

/**
 * Add the Gauth scopes cache table.
 */
function gauth_update_7004() {
  $module = 'gauth';
  $schema = drupal_get_schema_unprocessed($module);
  _drupal_schema_initialize($schema, $module, FALSE);
  unset($schema['gauth_accounts']);
  foreach ($schema as $name => $table) {
    db_create_table($name, $table);
  }
}

Functions

Namesort descending Description
gauth_install Implements hook_install().
gauth_requirements Implements hook_requirements().
gauth_schema Implements hook_schema().
gauth_uninstall Implements hook_uninstall().
gauth_update_7002 Add the gauth_accounts.uid field.
gauth_update_7003 Add the gauth_accounts.access_type field.
gauth_update_7004 Add the Gauth scopes cache table.