You are here

kaltura.install in Kaltura 7.3

Installation process for kaltura core module.

File

kaltura.install
View source
<?php

/**
 * @file
 * Installation process for kaltura core module.
 */

/**
 * Implements hook_schema().
 *
 * Defines the tables and fields in each table that we add to the database
 * to store kaltura data (nodes/notifications...).
 */
function kaltura_schema() {
  $schema['node_kaltura'] = array(
    'description' => 'The base table for Kaltura nodes.',
    'fields' => array(
      'eid' => array(
        'description' => 'The primary identifier for an entity.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'kaltura_entryid' => array(
        'description' => 'Kaltura entry id',
        'type' => 'varchar',
        'length' => 10,
        'default' => '',
        'not null' => TRUE,
      ),
      'kaltura_tags' => array(
        'description' => 'tags from kaltura CW',
        'type' => 'text',
        'default' => NULL,
        'not null' => FALSE,
      ),
      'kaltura_admin_tags' => array(
        'description' => 'admin tags from kaltura CMS',
        'type' => 'text',
        'default' => NULL,
        'not null' => FALSE,
      ),
      'kstatus' => array(
        'description' => 'The status of the entry/roughcut',
        'type' => 'int',
        'size' => 'small',
        'default' => 0,
        'not null' => TRUE,
      ),
      'kaltura_media_type' => array(
        'description' => 'Media type of the entry/mix. see kaltura API documentation for values',
        'type' => 'int',
        'size' => 'small',
        'not null' => FALSE,
      ),
      'kaltura_duration' => array(
        'description' => 'The duration of the entry(msecs)/mix(secs) in seconds',
        'type' => 'int',
        'not null' => FALSE,
      ),
      'kaltura_thumbnail_url' => array(
        'description' => 'The url of the thumbnail for the entry',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'kaltura_partner_data' => array(
        'description' => 'partner data that was sent in addentry',
        'type' => 'varchar',
        'length' => 4096,
        'not null' => FALSE,
      ),
      'kaltura_source' => array(
        'description' => 'The source of the media (file,webcam,youtube etc.), see kaltura API documentation for values',
        'type' => 'int',
        'size' => 'small',
        'not null' => FALSE,
      ),
      // @todo This field is not used and not even fetched from remote. Remove?
      'kaltura_source_id' => array(
        'description' => 'The id of the media in the source (e.g. youtube video id)',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      // @todo This field is not used and not even fetched from remote. Remove?
      'kaltura_source_link' => array(
        'description' => 'The link of the media source',
        'type' => 'varchar',
        'length' => 1024,
        'not null' => FALSE,
      ),
      'kaltura_width' => array(
        'description' => 'if item is image - the width of the image',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      'kaltura_height' => array(
        'description' => 'if item is image - the height of the image',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      'kaltura_download_url' => array(
        'description' => 'The direct download url for the entry/mix. available if item was flattened',
        'type' => 'varchar',
        'length' => 1024,
        'not null' => FALSE,
      ),
      'kaltura_media_date' => array(
        'description' => 'Date of the image from exif data',
        'type' => 'int',
        'not null' => FALSE,
      ),
      // A-sync data fields which should be updated by cron.
      'kaltura_views' => array(
        'description' => 'The number of times this item was viewed not necessarily played',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      'kaltura_plays' => array(
        'description' => 'The number of times this item was played',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      'kaltura_votes' => array(
        'description' => 'The number of votes on the entry/mix',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      'kaltura_rank' => array(
        'description' => 'the calculated rank of the entry/mix - multiplied by 1000',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      'kaltura_total_rank' => array(
        'description' => 'total rank of the entry/mix',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      // @todo This field is not used and not even fetched from remote. Remove?
      'kaltura_entry_data' => array(
        'description' => 'All the entry/kshow data (serialized) from kaltura received from notification or API call',
        'type' => 'text',
        'default' => NULL,
        'not null' => FALSE,
      ),
      // @todo This field is not used and not even fetched from remote. Remove?
      'kaltura_video_comment' => array(
        'description' => 'was the entry added as a comment for another node or not',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      'kaltura_created_date' => array(
        'description' => 'The date and time the entry was created',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      'kaltura_updated_date' => array(
        'description' => 'The date and time the entry was updated',
        'type' => 'int',
        'default' => 0,
        'not null' => FALSE,
      ),
      'kaltura_title' => array(
        'description' => 'The entry title',
        'type' => 'text',
        'default' => NULL,
        'not null' => FALSE,
      ),
      'kaltura_description' => array(
        'description' => 'The entry description',
        'type' => 'text',
        'default' => NULL,
        'not null' => FALSE,
      ),
      'kaltura_puser_id' => array(
        'description' => 'Uploader user id',
        'type' => 'int',
        'default' => 1,
        'not null' => TRUE,
      ),
      'categories' => array(
        'description' => 'Categories the media belongs to',
        'type' => 'text',
        'default' => NULL,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'eid',
    ),
    'unique keys' => array(
      'kaltura_entryid' => array(
        'kaltura_entryid',
      ),
    ),
    'foreign keys' => array(
      'owner' => array(
        'table' => 'users',
        'columns' => array(
          'kaltura_puser_id' => 'uid',
        ),
      ),
    ),
  );
  $schema['kaltura_notifications'] = array(
    'description' => 'table to "log" kaltura notifications, to ignore double notifications',
    'fields' => array(
      'notification_id' => array(
        'description' => 'notification Id from kaltura',
        'type' => 'int',
        'size' => 'normal',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'data' => array(
        'description' => 'notification REQUEST params',
        'type' => 'text',
        'default' => NULL,
        'not null' => FALSE,
      ),
      'received_at' => array(
        'type' => 'int',
      ),
    ),
    'primary key' => array(
      'notification_id',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function kaltura_install() {
  $t = get_t();
  if (!libraries_get_path('KalturaClient')) {
    drupal_set_message($t('Kaltura client library is not detected. You have to download it to use the Kaltura module. You can do this using Drush command "drush kaltura-client-install".'), 'warning');
  }
  $link_path = 'admin/config/media/kaltura';
  drupal_set_message($t('To !complete_link of the Kaltura Video Module installation, you must !partner_id_link', array(
    '!complete_link' => l($t('complete installation'), $link_path),
    '!partner_id_link' => l($t('associate it with a Kaltura Partner ID'), $link_path),
  )));
}

/**
 * Implemens hook_uninstall().
 */
function kaltura_uninstall() {
  variable_del('kaltura_admin_secret');
  variable_del('kaltura_fields_map');
  variable_del('kaltura_last_imported');
  variable_del('kaltura_local_registration');
  variable_del('kaltura_notification_status');
  variable_del('kaltura_notification_type');
  variable_del('kaltura_partner_id');
  variable_del('kaltura_partner_url2');
  variable_del('kaltura_secret');
  variable_del('kaltura_server_url');
  variable_del('kaltura_subp_id');
  $t = get_t();
  drupal_set_message($t('Kaltura module was successfully uninstalled.'));
}

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

    // First check if Libraries module exists.
    if (!drupal_get_path('module', 'libraries')) {
      $requirements['kaltura'] = array(
        'title' => $t('Kaltura module'),
        'severity' => REQUIREMENT_ERROR,
        'value' => $t('Libraries module missing'),
        'description' => $t('Kaltura module requires the <a href="!url">Libraries module</a> to be installed.', array(
          '!url' => 'http://drupal.org/project/libraries',
        )),
      );
    }
    else {

      // Libraries module exists but may not be installed, even if it is listed
      // as a dependency in .info file. For example, during installation from an
      // installation profile Libraries will *not* be installed when
      // hook_requirements gets called.
      if (!function_exists('libraries_get_path')) {
        include_once drupal_get_path('module', 'libraries') . '/libraries.module';
      }
      if (!libraries_get_path('KalturaClient')) {

        // KalturaClient is not installed.
        $requirements['kaltura_client'] = array(
          'title' => $t('Kaltura client library'),
          'value' => $t('Not detected'),
          'severity' => REQUIREMENT_ERROR,
          'description' => $t('Kaltura module requires Kaltura client library to be installed. You can download it using Drush command "drush kaltura-client-install" or manually from !url.', array(
            '!url' => l($t('this url'), 'http://cdnbakmi.kaltura.com/content/clientlibs/php5_16-12-2014.tar.gz', array(
              'attributes' => array(
                'target' => '_blank',
              ),
            )),
          )),
        );
      }
      else {

        // KalturaClient is installed.
        $library = libraries_detect('KalturaClient');
        $requirements['kaltura_client'] = array(
          'title' => $t('Kaltura client library'),
          'value' => $library['version'],
          'severity' => REQUIREMENT_OK,
        );
        if (module_exists('kaltura')) {

          // If modules enabled, check if it was configured yet.
          $status = variable_get('kaltura_partner_id');
          if (!empty($status)) {
            $requirements['kaltura'] = array(
              'title' => $t('Kaltura module'),
              'value' => $t('Configured'),
              'severity' => REQUIREMENT_OK,
            );
          }
          else {
            $requirements['kaltura'] = array(
              'title' => $t('Kaltura module'),
              'value' => $t('Not configured'),
              'severity' => REQUIREMENT_ERROR,
              'description' => $t('You did not complete the module configuration. You must configure the module with valid kaltura partner details or perform registration. Go to !settings_link to complete configuration.', array(
                '!settings_link' => l($t('kaltura module settings'), 'admin/config/media/kaltura'),
              )),
            );
          }
        }
      }
    }
  }
  return $requirements;
}

/**
 * Change the primary ID field for an entity from Kaltura entry ID to a serial
 * number.
 */
function kaltura_update_7300() {

  // Add new primary ID field and change keys. Values of serial field are filled
  // in automatically.
  $spec = array(
    'description' => 'The primary identifier for an entity.',
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  );
  $keys_new = array(
    'primary key' => array(
      'eid',
    ),
    'unique keys' => array(
      'kaltura_entryid' => array(
        'kaltura_entryid',
      ),
    ),
  );
  db_drop_primary_key('node_kaltura');
  db_add_field('node_kaltura', 'eid', $spec, $keys_new);

  // This var is not used anymore.
  variable_del('kaltura_last_update');
}

/**
 * Remove redundant insecure configuration variables.
 */
function kaltura_update_7301() {
  variable_del('kaltura_partner_cms_email');
  variable_del('kaltura_partner_cms_password');
}

/**
 * Remove variable indicated to use HTML5 player as now it is always used.
 */
function kaltura_update_7302() {
  variable_del('kaltura_add_html5');
}

/**
 * Add new entity property - Categories.
 */
function kaltura_update_7303() {
  $spec = array(
    'description' => 'Categories the media belongs to',
    'type' => 'text',
    'default' => NULL,
    'not null' => FALSE,
  );
  db_add_field('node_kaltura', 'categories', $spec);

  // Unset the timestamp of last imported entries so next cron run will also
  // fetch categories.
  variable_del('kaltura_last_imported');
}

Functions

Namesort descending Description
kaltura_install Implements hook_install().
kaltura_requirements Implements hook_requirements().
kaltura_schema Implements hook_schema().
kaltura_uninstall Implemens hook_uninstall().
kaltura_update_7300 Change the primary ID field for an entity from Kaltura entry ID to a serial number.
kaltura_update_7301 Remove redundant insecure configuration variables.
kaltura_update_7302 Remove variable indicated to use HTML5 player as now it is always used.
kaltura_update_7303 Add new entity property - Categories.