You are here

brightcove.install in Brightcove Video Connect 7.5

Installation file for Brightcove module.

File

brightcove.install
View source
<?php

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

/**
 * Implements hook_schema().
 */
function brightcove_schema() {
  $schema = array();
  $schema['brightcove_player'] = array(
    'description' => 'Stores brightcove players.',
    'export' => array(
      'key' => 'name',
      'key name' => 'Name',
      'primary key' => 'pid',
      'identifier' => 'preset',
      'default hook' => 'brightcove_player',
      'api' => array(
        'owner' => 'brightcove',
        'api' => 'brightcove',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'pid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'no export' => TRUE,
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'display_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'player_id' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'player_key' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'responsive' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'pid',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  $schema['cache_brightcove'] = drupal_get_schema_unprocessed('system', 'cache');
  return $schema;
}

/**
 * Adds brightcove_player table.
 */
function brightcove_update_7001() {
  db_create_table('brightcove_player', array(
    'description' => 'Stores brightcove players.',
    'fields' => array(
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'player_id' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'player_key' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'name',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
  ));
}

/**
 * Implements hook_requirements().
 */
function brightcove_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase != 'install') {
    if (!($path = variable_get('brightcove_mapi_path', FALSE))) {
      $files = drupal_system_listing('/^bc-mapi\\.php$/', 'libraries', 'filename', 0);
      if (isset($files['bc-mapi.php'])) {
        $path = dirname($files['bc-mapi.php']->uri);
        variable_set('brightcove_mapi_path', $path);
      }
    }
    if (!$path) {
      $requirements['bc_mapi']['title'] = $t('Brightcove MAPI SDK');
      $requirements['bc_mapi']['description'] = $t('Brightcove MAPI SDK is missing. Please install it to sites/all/libraries from !url and enable the module again.', array(
        '!url' => l('http://opensource.brightcove.com/project/PHP-MAPI-Wrapper/', 'http://opensource.brightcove.com/project/PHP-MAPI-Wrapper/'),
      ));
      $requirements['bc_mapi']['severity'] = REQUIREMENT_ERROR;
      $requirements['bc_mapi']['value'] = $t('Missing');
    }
    else {
      $requirements['bc_mapi']['title'] = $t('Brightcove MAPI SDK');
      $requirements['bc_mapi']['severity'] = REQUIREMENT_OK;
      $requirements['bc_mapi']['value'] = $t('Installed');
    }
  }
  if (!function_exists('curl_init')) {
    $requirements['curl']['title'] = $t('cURL');
    $requirements['curl']['description'] = $t('Brightcove MAPI SDK requires a cURL library. You should install it on your server.');
    $requirements['curl']['severity'] = REQUIREMENT_ERROR;
    $requirements['curl']['value'] = $t(': missing');
  }
  return $requirements;
}

/**
 * Implements hook_uninstall().
 */
function brightcove_uninstall() {
  variable_del('brightcove_allow_public');
  variable_del('brightcove_check_for_unavailable');
  variable_del('brightcove_create_multiple_renditions');
  variable_del('brightcove_custom_field_number');
  variable_del('brightcove_default_image');
  variable_del('brightcove_default_thumbnail');

  // Remove legacy library path too.
  variable_del('brightcove_echove_path');
  variable_del('brightcove_encode_to');
  variable_del('brightcove_mapi_path');
  variable_del('brightcove_player');
  variable_del('brightcove_player_full_api');
  variable_del('brightcove_player_pid');
  variable_del('brightcove_player_default');
  variable_del('brightcove_player_key');
  variable_del('brightcove_preserve_source_rendition');
  variable_del('brightcove_read_api_key');
  variable_del('brightcove_status_display_unavailable');
  variable_del('brightcove_user_field');
  variable_del('brightcove_write_api_key');

  // Cache variables.
  variable_del('brightcove_cache_enabled');
  variable_del('brightcove_cache_type');
  variable_del('brightcove_cache_db');
  variable_del('brightcove_cache_file');
  variable_del('brightcove_cache_memcached');
}

/**
 * Migrates old player id and key to the table.
 */
function brightcove_update_7002() {
  $t = get_t();
  $player_id = variable_get('brightcove_player');
  $player_key = variable_get('brightcove_player_key');
  brightcove_player_save((object) array(
    'name' => $t('Default'),
    'player_id' => $player_id,
    'player_key' => $player_key,
  ));
  variable_del('brightcove_player');
  variable_del('brightcove_player_key');
}

/**
 * Create individual primary key for players.
 */
function brightcove_update_7003() {
  $spec = array(
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  );
  db_drop_primary_key('brightcove_player');
  db_add_field('brightcove_player', 'pid', $spec, array(
    'primary key' => array(
      'pid',
    ),
  ));
}

/**
 * Make name column unique.
 */
function brightcove_update_7004() {
  db_add_unique_key('brightcove_player', 'name', array(
    'name',
  ));
}

/**
 * Adding a "Display name" column.  Move existing "Name" data into that and
 * make "Name" machine-readable.
 */
function brightcove_update_7005() {
  $default_player = variable_get('brightcove_player_pid', '');
  db_add_field('brightcove_player', 'display_name', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ));

  // We are not using brightcove_player_load_all() here because that, being
  // based on CTools Export, is using the table schema. But new fields might be
  // added to the table schema in future updates and that will break the
  // execution with an 'Unknown column' fatal error.
  $players = db_query("SELECT pid, name FROM {brightcove_player}")
    ->fetchAll();
  if (!empty($players)) {
    foreach ($players as $player) {

      // Make display name the name, and restrict the name to machine-readable.
      $player->display_name = $player->name;
      $player->name = preg_replace('/_+/', '_', preg_replace('/[^a-z0-9]+/', '_', strtolower($player->name)));

      // Save the new name. We are not using brightcove_player_save() because
      // $player is not a full CTools Export object.
      db_update('brightcove_player')
        ->fields(array(
        'name' => $player->name,
        'display_name' => $player->display_name,
      ))
        ->condition('pid', $player->pid)
        ->execute();

      //
      if ($player->pid == $default_player) {
        $default_player = $player->name;
      }
    }
  }
  variable_set('brightcove_player_default', $default_player);
}

/**
 * Create cache table for Brightcove objects.
 */
function brightcove_update_7006() {
  $cache_table = drupal_get_schema_unprocessed('system', 'cache');
  db_create_table('cache_brightcove', $cache_table);
}

/**
 * Fix default players for Brightcove field instances.
 */
function brightcove_update_7007() {
  $players = brightcove_player_load_all();

  // Get all of the brightcove fields.
  $fields = field_read_fields(array(
    'type' => 'brightcove_field',
  ));
  foreach ($fields as $field) {

    // Update the value of the default player for brightcove field instances.
    $instances = field_read_instances(array(
      'field_name' => $field['field_name'],
    ));
    foreach ($instances as $instance) {
      if (!empty($players)) {
        foreach ($players as $player) {
          if ($instance['settings']['brightcove_player'] == $player->pid) {
            $instance['settings']['brightcove_player'] = $player->name;
            field_update_instance($instance);
          }
        }
      }
    }
  }
}

/**
 * Add responsive flag to players.
 */
function brightcove_update_7008() {
  $spec = array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_field('brightcove_player', 'responsive', $spec);

  // Clear schema cache.
  cache_clear_all('schema', 'cache', TRUE);
}

Functions

Namesort descending Description
brightcove_requirements Implements hook_requirements().
brightcove_schema Implements hook_schema().
brightcove_uninstall Implements hook_uninstall().
brightcove_update_7001 Adds brightcove_player table.
brightcove_update_7002 Migrates old player id and key to the table.
brightcove_update_7003 Create individual primary key for players.
brightcove_update_7004 Make name column unique.
brightcove_update_7005 Adding a "Display name" column. Move existing "Name" data into that and make "Name" machine-readable.
brightcove_update_7006 Create cache table for Brightcove objects.
brightcove_update_7007 Fix default players for Brightcove field instances.
brightcove_update_7008 Add responsive flag to players.