You are here

oauth.install in OAuth 1.0 8.2

Same filename and directory in other branches
  1. 8 oauth.install
  2. 6 oauth.install

Installation and schema related functions for the OAuth module.

File

oauth.install
View source
<?php

/**
 * @file
 * Installation and schema related functions for the OAuth module.
 */
use Drupal\Core\Database\Database;

/**
 * Implements hook_requirements().
 */
function oauth_requirements($phase) {
  $requirements = array();
  $oauth_available = class_exists('\\OauthProvider');
  if ($oauth_available) {
    $requirements['oauth_pecl'] = array(
      'title' => t('OAuth'),
      'value' => t('OAuth PECL library installed'),
    );
  }
  else {
    $requirements['oauth_pecl'] = array(
      'title' => t('OAuth'),
      'severity' => REQUIREMENT_ERROR,
      'description' => t("OAuth module requires the <a href='@oauth_url' target='_blank'>PECL OAuth</a> library.", array(
        '@oauth_url' => 'http://www.php.net/manual/en/book.oauth.php',
      )),
    );
    if ($phase == 'runtime') {
      $requirements['oauth_pecl'] += array(
        'value' => t('OAuth PECL library not installed'),
      );
    }
  }
  return $requirements;
}

/**
 * Move any existing oauth data to UserData and remove 'oauth_consumers' table.
 */
function oauth_update_8100(&$sandbox) {

  // Fetch any current consumer data.
  $result = Database::getConnection()
    ->query('select * from {oauth_consumer}');
  $user_data = \Drupal::service('user.data');
  foreach ($result as $row) {

    // Insert each row in to Userdata.
    $user_data
      ->set('oauth', $row->uid, $row->consumer_key, [
      'consumer_secret' => $row->consumer_secret,
      'key_hash' => $row->key_hash,
    ]);
  }

  // Remove the oauth_consumer table.
  Database::getConnection()
    ->schema()
    ->dropTable('oauth_consumer');
}

Functions

Namesort descending Description
oauth_requirements Implements hook_requirements().
oauth_update_8100 Move any existing oauth data to UserData and remove 'oauth_consumers' table.