You are here

feeds_oauth.install in Feeds OAuth 7

Same filename and directory in other branches
  1. 6 feeds_oauth.install

Install schema and updates.

File

feeds_oauth.install
View source
<?php

/**
 * @file
 * Install schema and updates.
 */

/**
 * Implements hook_requirements().
 */
function feeds_oauth_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'runtime') {

    // php-proauth library.
    $path = rtrim(variable_get('feeds_oauth_library_path', FEEDS_OAUTH_LIBRARY_PATH_DEFAULT), '/');
    $satisfied = is_file($path . '/lib/oauth/OAuthClient.php');
    $requirements['php-proauth'] = array(
      'title' => 'php-proauth library',
      'value' => $satisfied ? $t('php-proauth found at %path.', array(
        '%path' => empty($path) ? $t('[empty path]') : $path,
      )) : $t('php-proauth NOT found at %path. If you haven\'t done so already, please <a href="@url">download it</a>. You can also <a href="@setting">modify the library path setting</a>.', array(
        '%path' => $path,
        '@url' => 'https://code.google.com/p/php-proauth/',
        '@setting' => url('admin/config/services/feeds-oauth'),
      )),
      'severity' => $satisfied ? REQUIREMENT_OK : REQUIREMENT_ERROR,
    );

    // php-curl library.
    $satisfied = function_exists('curl_init');
    $requirements['php-curl'] = array(
      'title' => 'cURL',
      'value' => $satisfied ? $t('Enabled') : $t('Missing'),
      'severity' => $satisfied ? REQUIREMENT_OK : REQUIREMENT_ERROR,
    );
  }
  return $requirements;
}

/**
 * Implements hook_schema().
 */
function feeds_oauth_schema() {
  $schema = array();
  $schema['feeds_oauth_access_tokens'] = array(
    'description' => 'OAuth access tokens per user per site.',
    'fields' => array(
      'uid' => array(
        'description' => 'User identifier for this token.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'oauth_token' => array(
        'description' => 'OAuth access token.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
      ),
      'oauth_token_secret' => array(
        'description' => 'OAuth access token secret.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
      ),
      'site_id' => array(
        'description' => 'Site identifier for this token.',
        'type' => 'varchar',
        'length' => '50',
        'not null' => TRUE,
      ),
      'timestamp' => array(
        'description' => 'The UNIX timestamp when this token was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'expires' => array(
        'description' => 'The UNIX timestamp when this token will expire.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'oauth_refresh_token' => array(
        'description' => 'OAuth refresh token.',
        'type' => 'varchar',
        'length' => '100',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'uid',
      'site_id',
    ),
  );
  return $schema;
}

/**
 * Add extra columns to 'feeds_oauth_access_token' for OAuth 2.0.
 */
function feeds_oauth_update_7001() {
  db_add_field('feeds_oauth_access_tokens', 'timestamp', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'initial' => time(),
  ));
  db_add_field('feeds_oauth_access_tokens', 'expires', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field('feeds_oauth_access_tokens', 'oauth_refresh_token', array(
    'description' => t('OAuth refresh token.'),
    'type' => 'varchar',
    'length' => '100',
    'not null' => TRUE,
  ));
}

/**
 * Enlarge size of oauth_token and oauth_token_secret.
 */
function feeds_oauth_update_7003() {
  $schema = feeds_oauth_schema();
  db_change_field('feeds_oauth_access_tokens', 'oauth_token', 'oauth_token', $schema['feeds_oauth_access_tokens']['fields']['oauth_token']);
  db_change_field('feeds_oauth_access_tokens', 'oauth_token_secret', 'oauth_token_secret', $schema['feeds_oauth_access_tokens']['fields']['oauth_token_secret']);
}

Functions

Namesort descending Description
feeds_oauth_requirements Implements hook_requirements().
feeds_oauth_schema Implements hook_schema().
feeds_oauth_update_7001 Add extra columns to 'feeds_oauth_access_token' for OAuth 2.0.
feeds_oauth_update_7003 Enlarge size of oauth_token and oauth_token_secret.