You are here

function brightcove_update_7600 in Brightcove Video Connect 7.7

Same name and namespace in other branches
  1. 7.6 brightcove.install \brightcove_update_7600()

Update to the 7.x-6.x version.

  • creates tables for the new entities
  • updates field definitions
  • updates field config (brightcove_field -> brightcove module merge)
  • enables additional dependencies

File

./brightcove.install, line 296
Installation file for Brightcove module.

Code

function brightcove_update_7600() {
  db_delete('cache')
    ->condition('cid', 'ctools_plugin%', 'LIKE')
    ->execute();
  $schema = [];
  $schema['brightcove_client'] = [
    'description' => 'The base table for brightcove clients.',
    'fields' => [
      'bcid' => [
        'description' => 'The primary identifier for a brightcove client, used internally only.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'label' => [
        'description' => 'The label of this client.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'account_id' => [
        'description' => 'The ID of the account this client belongs to.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ],
      'client_id' => [
        'description' => 'The client ID.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ],
      'client_secret' => [
        'description' => 'The client secret key.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ],
      'uid' => [
        'description' => 'The {users}.uid that created this client.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'created' => [
        'description' => 'The Unix timestamp when the client was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'changed' => [
        'description' => 'The Unix timestamp when the client was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'data' => [
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'A serialized array of additional data.',
      ],
      'status' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0x1,
        'size' => 'tiny',
        'description' => 'The exportable status of the entity.',
      ],
      'module' => [
        'description' => 'The name of the providing module if the entity has been defined in code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ],
    ],
    'primary key' => [
      'bcid',
    ],
    'unique keys' => [
      'client_id' => [
        'client_id',
      ],
    ],
    'creator' => [
      'table' => 'users',
      'columns' => [
        'uid' => 'uid',
      ],
    ],
  ];
  $schema['brightcove_callback'] = [
    'fields' => [
      'id' => [
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ],
      'fid' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
      'expires' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
    ],
    'primary key' => [
      'id',
    ],
  ];
  $schema['brightcove_video'] = [
    'description' => 'Stores information about brightcove video.',
    'fields' => [
      'bvid' => [
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique key for brightcove video.',
      ],
      'type' => [
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ],
      'video_id' => [
        'description' => 'The ID of the video.',
        'type' => 'int',
        'not null' => TRUE,
        'size' => 'big',
      ],
      'account_id' => [
        'description' => 'The ID of the brightcove account this video belongs to.',
        'type' => 'int',
        'not null' => TRUE,
        'size' => 'big',
      ],
    ],
    'primary key' => [
      'bvid',
    ],
    'unique keys' => [
      'client_video' => [
        'video_id',
      ],
    ],
  ];
  foreach ($schema as $table => $def) {
    db_create_table($table, $def);
  }
  db_drop_table('brightcove_player');
  variable_del('brightcove_default_player');
  if (module_exists('field_sql_storage')) {
    $coldef = [
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
    ];
    foreach (field_info_fields() as $name => $def) {
      if ($def['type'] == 'brightcove_field' && $def['storage']['type'] == 'field_sql_storage') {
        $tablename = _field_sql_storage_tablename($def);
        $revtablename = _field_sql_storage_revision_tablename($def);
        $bcid_col = _field_sql_storage_columnname($name, 'bcid');
        db_add_field($tablename, $bcid_col, $coldef);
        db_add_field($revtablename, $bcid_col, $coldef);
      }
    }
    db_update('field_config')
      ->fields([
      'module' => 'brightcove',
    ])
      ->condition('module', 'brightcove_field')
      ->execute();
  }
  module_enable([
    'date_api',
    'libraries',
  ], TRUE);
  cache_clear_all();
  module_load_include('inc', 'brightcove', 'brightcove.playlist');
  _brightcove_configure_playlist_entity();
  drupal_set_message(t('The brightcove module has been updated. Because of the changes in the API, please visit the !admin-link to add your credentials.', [
    '!admin-link' => l(t('API Client page'), 'admin/config/media/brightcove/client'),
  ]));
}