You are here

video_zencoder.install in Video 6.5

Same filename and directory in other branches
  1. 6.4 plugins/video_zencoder/video_zencoder.install

Provides installation functions for video_s3.module.

File

plugins/video_zencoder/video_zencoder.install
View source
<?php

/**
 * @file
 * Provides installation functions for video_s3.module.
 */

/**
 * Implementation of hook_schema().
 */
function video_zencoder_schema() {
  $schema['video_zencoder'] = array(
    'description' => t('Store video s3 cdn and convert with zencoder webservice'),
    'fields' => array(
      'vid' => array(
        'description' => t('Auto Increment id'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'fid' => array(
        'description' => t('Original file id'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'description' => t('Node id'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'jobid' => array(
        'description' => t('Job id'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => t('Status of the cdn transfer'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'dimensions' => array(
        'type' => 'varchar',
        'length' => '255',
        'default' => '',
        'description' => t('The dimensions of the video.'),
      ),
      'completed' => array(
        'description' => t('Time of successful completion to amazon.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'data' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'description' => 'A serialized array of converted files. Use of this field is discouraged and it will likely disappear in a future version of Drupal.',
      ),
    ),
    'indexes' => array(
      'status' => array(
        'status',
      ),
      'file' => array(
        'fid',
      ),
    ),
    'primary key' => array(
      'vid',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function video_zencoder_install() {
  drupal_install_schema('video_zencoder');

  // set the module weight to low since we need this to load later time than in S3
  db_query("UPDATE {system} SET weight = 50 WHERE name = 'video_zencoder'");
}

/**
 * Implementation of hook_uninstall().
 */
function video_zencoder_uninstall() {
  drupal_uninstall_schema('video_zencoder');

  // @todo Delete our variables.
}

/**
 * Implementation of hook_requirements().
 */
function video_zencoder_requirements($phase) {
  $t = get_t();
  $requirements = array();
  if (!module_exists('libraries')) {
    $requirements['video_zencoder_libraries'] = array(
      'title' => $t('Video Zencoder requirements'),
      'description' => $t('The <a href="@libraries-url">Libraries API</a> module is required to use the Video Zencoder module since version 4.8.', array(
        '@libraries-url' => 'http://drupal.org/project/libraries',
      )),
      'value' => l($t('Download'), 'http://drupal.org/project/libraries'),
      'severity' => REQUIREMENT_ERROR,
    );
  }
  else {
    $path = libraries_get_path('zencoder');
    $file = $path . '/Services/Zencoder.php';
    if (!is_dir($path)) {
      $requirements['video_zencoder_librarys'] = array(
        'title' => $t('Video Zencoder library'),
        'description' => $t('The <a href="@zencoder-library-url">Zencoder API library</a> must be installed to %libpath to use Zencoder to transcode videos.', array(
          '@zencoder-library-url' => 'https://github.com/zencoder/zencoder-php',
          '%libpath' => $path,
        )),
        'value' => l($t('Download'), 'https://github.com/zencoder/zencoder-php'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    elseif (!is_file($file)) {
      $requirements['video_zencoder_librariy'] = array(
        'title' => $t('Video Zencoder library'),
        'description' => $t('The directory %libpath is found, but the <a href="@zencoder-library-url">Zencoder API library</a> does not appear to be installed correctly, as the file %libfile is not found. Check if the library archive has been extracted correctly.', array(
          '@zencoder-library-url' => 'https://github.com/zencoder/zencoder-php',
          '%libpath' => $path,
          '%libfile' => $file,
        )),
        'value' => l($t('Download'), 'https://github.com/zencoder/zencoder-php'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    else {
      require_once $file;

      // Instantiate the Zencoder API to catch errors during initialization
      try {
        $temp = new Services_Zencoder();
        $version = str_replace('ZencoderPHP v', '', Services_Zencoder::USER_AGENT);
        $requirements['video_zencoder_library'] = array(
          'title' => $t('Video Zencoder library'),
          'value' => check_plain($version),
          'severity' => REQUIREMENT_OK,
        );
      } catch (Exception $e) {
        $requirements['video_zencoder_library'] = array(
          'title' => $t('Video Zencoder library'),
          'value' => $e
            ->getMessage(),
          'severity' => REQUIREMENT_ERROR,
        );
      }
    }
  }
  return $requirements;
}

/**
 * Implementation of hook_update_N().
 *
 * Adding new dimensions column to the table
 */
function video_zencoder_update_6401() {
  $ret = array();

  // set settings column to accept larger values
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql('ALTER TABLE {video_zencoder} ADD dimensions VARCHAR( 255 ) NULL NULL AFTER filesize');
      break;
    case 'pgsql':
      db_add_column($ret, 'video_zencoder', 'dimensions', 'VARCHAR', array(
        'null' => TRUE,
      ));
      break;
  }
  return $ret;
}

/**
 * Implementation of hook_update_N().
 *
 * Adding data field and remove unwanted fields from the table
 */
function video_zencoder_update_6402() {
  $ret = array();

  // drop un wanted fields in video zencoder
  db_drop_field($ret, 'video_zencoder', 'filesize');
  db_drop_field($ret, 'video_zencoder', 'outputid');
  db_drop_field($ret, 'video_zencoder', 'bucket');
  db_drop_field($ret, 'video_zencoder', 'filename');
  db_drop_field($ret, 'video_zencoder', 'filepath');
  db_drop_field($ret, 'video_zencoder', 'filemime');
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_add_column($ret, 'video_zencoder', 'data', 'longtext', array(
        'null' => TRUE,
      ));
      break;
    case 'pgsql':
      db_add_column($ret, 'video_zencoder', 'data', 'text', array(
        'null' => TRUE,
      ));
      break;
  }
  return $ret;
}

Functions