You are here

services_client.install in Services Client 7

Same filename and directory in other branches
  1. 7.2 services_client.install

Installation file for services_client module.

File

services_client.install
View source
<?php

/**
 * @file
 * Installation file for services_client module.
 */

/**
 * Implements hook_requirements().
 */
function services_client_requirements($phase) {
  $requirements = array();
  $t = get_t();

  // In case oauth_common is installed, skip the check.
  // Because oauth_common does this check already.
  if (!module_exists('oauth_common')) {
    $curl_available = function_exists('curl_init');
    $requirements['services_client_curl'] = array(
      'title' => $t('Services client'),
      'value' => $curl_available ? $t('cURL library Enabled') : $t('cURL library not found'),
    );
    if (!$curl_available) {
      $requirements['services_client_curl'] += array(
        'severity' => REQUIREMENT_ERROR,
        'description' => $t("ServicesClientConnectionCurlRequest requires the PHP <a href='!curl_url'>cURL</a> library.", array(
          '!curl_url' => 'http://php.net/manual/en/curl.setup.php',
        )),
      );
    }
  }
  return $requirements;
}

/**
 * Implementation of hook_schema().
 */
function services_client_schema() {
  $schema = array();
  $schema['services_client_connection_hook'] = array(
    'description' => 'Connection hooks',
    'export' => array(
      // Unique key of the connection hooks
      'key' => 'name',
      // Description of key.
      'key name' => 'Primary ID Field for connection hooks',
      // For now, we don't allow to disable this.
      'can disable' => FALSE,
      // Variable name to use in exported code.
      'identifier' => 'connection_hook',
      // Use the same hook as the API name below.
      'default hook' => 'default_services_client_connection_hook_myobj',
      // CTools API implementation.
      'api' => array(
        'owner' => 'services_client',
        'api' => 'default_services_client_connection_hook',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'hid' => array(
        'type' => 'serial',
        'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'no export' => TRUE,
      ),
      'conn_name' => array(
        'description' => 'The name of the connection.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'The name of the hook.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'title' => array(
        'description' => 'The title of the hook.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'hook' => array(
        'description' => 'The name of the hook.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'config' => array(
        'type' => 'text',
        'serialize' => TRUE,
        'description' => 'Services client plugins configuration',
        'object default' => array(
          'mapping' => array(
            'plugin' => '',
            'config' => array(),
          ),
          'condition' => array(
            'plugin' => '',
            'config' => array(),
          ),
        ),
      ),
    ),
    'primary key' => array(
      'hid',
    ),
    'unique key' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  $schema['services_client_connection_id'] = array(
    'description' => 'Holds ids of remote clients',
    'export' => array(
      // Connection ID Name
      'key' => 'name',
      // Description of key.
      'key name' => 'Name of the connection',
      // For now, we don't allow to disable this.
      'can disable' => FALSE,
      // Variable name to use in exported code.
      'identifier' => 'connection_id',
      // Use the same hook as the API name below.
      'default hook' => 'default_services_client_connection_id_myobj',
      // CTools API implementation.
      'api' => array(
        'owner' => 'services_client',
        'api' => 'default_services_client_connection_id',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'name' => array(
        'description' => 'The name of the connection.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'services_client_id' => array(
        'description' => 'ID of remote client.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_uninstall().
 */
function services_client_uninstall() {

  // Remove all tables on uninstall
  foreach (array_keys(services_client_schema()) as $table) {
    db_drop_table($table);
  }
}

/**
 * Remove old {services_client_connection} table which has been moved to
 * services_client_connection module.
 */
function services_client_update_7001() {
  db_drop_table('services_client_connection');
}

/**
 * Add new {services_client_connection_id} which can store remote client id
 * with each connection.
 */
function services_client_update_7002() {
  $schema['services_client_connection_id'] = array(
    'description' => 'Holds ids of remote clients',
    'fields' => array(
      'name' => array(
        'description' => 'The name of the connection.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'services_client_id' => array(
        'description' => 'ID of remote client.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  db_create_table('services_client_connection_id', $schema['services_client_connection_id']);
}

/**
 * Add ctools support and move data around
 */
function services_client_update_7003() {
  ctools_include('export');
  if (db_table_exists('services_client_connection_hook') && !db_field_exists('services_client_connection_hook', 'config')) {

    // Use what's already defined in uuid schema in order to be consistent.
    $schema = services_client_schema();
    $spec = $schema['services_client_connection_hook']['fields']['config'];
    db_add_field('services_client_connection_hook', 'config', $spec);
  }
  $hooks = ctools_export_crud_load_all('services_client_connection_hook');
  foreach ($hooks as $hook) {

    // Copy over the settings from hook_mappings
    if (isset($hook->hook_mappings)) {
      $hook->config['mapping']['config'] = $hook->hook_mappings;
    }

    // Copy over the settings from hook_conditions
    if (isset($hook->hook_conditions)) {
      $hook->config['condition']['config'] = $hook->hook_conditions;
    }
    ctools_export_crud_save('services_client_connection_hook', $hook);
  }
  if (db_table_exists('services_client_connection_hook')) {

    // Use what's already defined in uuid schema in order to be consistent.
    db_drop_field('services_client_connection_hook', 'hook_mappings');
    db_drop_field('services_client_connection_hook', 'hook_conditions');
  }
}

Functions

Namesort descending Description
services_client_requirements Implements hook_requirements().
services_client_schema Implementation of hook_schema().
services_client_uninstall Implementation of hook_uninstall().
services_client_update_7001 Remove old {services_client_connection} table which has been moved to services_client_connection module.
services_client_update_7002 Add new {services_client_connection_id} which can store remote client id with each connection.
services_client_update_7003 Add ctools support and move data around