You are here

video.install in Video 5

File

video.install
View source
<?php

// ex: set syntax=php tabstop=2 expandtab shiftwidth=2 softtabstop=2:
function video_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {video} (\n        vid int(10) unsigned NOT NULL default '0',\n        nid int(10) unsigned NOT NULL default '0',\n        vtype varchar(32) NOT NULL default '',\n        vidfile text NOT NULL default '',\n        videox smallint(4) unsigned NOT NULL default '0',\n        videoy smallint(4) unsigned NOT NULL default '0',\n        size bigint(13) unsigned default NULL,\n        download_counter int(10) unsigned NOT NULL default '0',\n        play_counter int(10) unsigned NOT NULL default '0',\n        video_bitrate int(10) unsigned default NULL,\n        audio_bitrate int(10) unsigned default NULL,\n        audio_sampling_rate int(10) unsigned default NULL,\n        audio_channels enum('','5.1','stereo','mono') default NULL,\n        playtime_seconds int(10) unsigned default NULL,\n        download_folder varchar(255) NULL default NULL,\n        disable_multidownload tinyint(1) unsigned NOT NULL default '0',\n        use_play_folder tinyint(1) unsigned NOT NULL default '0',\n        serialized_data text NULL default NULL,\n        PRIMARY KEY  (vid)\n      ) TYPE=MyISAM COMMENT='size is in bytes' /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {video} (\n        vid integer NOT NULL default '0',\n        nid integer NOT NULL default '0',\n        vtype varchar(32) NOT NULL default '',\n        vidfile text NOT NULL default '',\n        videox smallint NOT NULL default '0',\n        videoy smallint NOT NULL default '0',\n        size bigint default NULL,\n        download_counter integer NOT NULL default '0',\n        play_counter integer NOT NULL default '0',\n        video_bitrate integer default NULL,\n        audio_bitrate integer default NULL,\n        audio_sampling_rate integer default NULL,\n        audio_channels varchar(10) default NULL,\n        playtime_seconds integer default NULL,\n        download_folder varchar(255) NULL default NULL,\n        disable_multidownload smallint NOT NULL default '0',\n        use_play_folder smallint NOT NULL default '0',\n        serialized_data text NULL default NULL,\n        PRIMARY KEY  (vid)\n      );");
  }

  // default values for some variables use for resolution stuff
  variable_set('video_resolution_1_name', '4:3 - Television');
  variable_set('video_resolution_1_value', '400x300');
  variable_set('video_resolution_2_name', '16:9 - Widescreen');
  variable_set('video_resolution_2_value', '400x226');
}

/**
 * Uninstall video module
 *
 * @return array
 */
function video_uninstall() {
  db_query('DROP TABLE {video}');
  variable_del('video_resolution_1_name');
  variable_del('video_resolution_1_value');
  variable_del('video_resolution_2_name');
  variable_del('video_resolution_2_value');
}

/**
 * Add audio details
 *
 * @return array
 */
function video_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {video} CHANGE videox videox smallint(4) NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {video} CHANGE videoy videoy smallint(4) NOT NULL default '0'");
      $ret[] = update_sql('ALTER TABLE {video} CHANGE size size bigint(13) default NULL');
      $ret[] = update_sql('ALTER TABLE {video} ADD video_bitrate int(11) default NULL');
      $ret[] = update_sql('ALTER TABLE {video} ADD audio_bitrate int(11) default NULL');
      $ret[] = update_sql('ALTER TABLE {video} ADD audio_sampling_rate int(11) default NULL');
      $ret[] = update_sql("ALTER TABLE {video} ADD audio_channels enum('','stereo','mono') default NULL");
      $ret[] = update_sql('ALTER TABLE {video} ADD playtime_seconds int(11) default NULL');
  }
  return $ret;
}

/**
 * Rename counter, add custom fields, for video.module version 1.9
 *
 * @return array
 */
function video_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {video} CHANGE clicks download_counter int(10) unsigned NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {video} ADD play_counter int(10) unsigned NOT NULL default '0' AFTER download_counter");
      $ret[] = update_sql("ALTER TABLE {video} CHANGE audio_channels audio_channels enum('','5.1','stereo','mono') default NULL");
      $ret[] = update_sql('ALTER TABLE {video} ADD download_folder varchar(255) NULL default NULL');
      $ret[] = update_sql("ALTER TABLE {video} ADD disable_multidownload tinyint(1) NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {video} ADD use_play_folder tinyint(1) NOT NULL default '0'");
      $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_1 varchar(255) NULL default NULL');
      $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_2 varchar(255) NULL default NULL');
      $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_3 varchar(255) NULL default NULL');
      $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_4 varchar(255) NULL default NULL');
      $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_5 text NULL default NULL');
      $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_6 text NULL default NULL');
  }
  return $ret;
}

/**
 * Add unsigned to all int fields
 *
 * @return array
 */
function video_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {video} CHANGE videox videox smallint(4) unsigned NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {video} CHANGE videoy videoy smallint(4) unsigned NOT NULL default '0'");
      $ret[] = update_sql('ALTER TABLE {video} CHANGE size size bigint(13) unsigned default NULL');
      $ret[] = update_sql('ALTER TABLE {video} CHANGE video_bitrate video_bitrate int(11) unsigned default NULL');
      $ret[] = update_sql('ALTER TABLE {video} CHANGE audio_bitrate audio_bitrate int(11) unsigned default NULL');
      $ret[] = update_sql('ALTER TABLE {video} CHANGE audio_sampling_rate audio_sampling_rate int(11) unsigned default NULL');
      $ret[] = update_sql('ALTER TABLE {video} CHANGE playtime_seconds playtime_seconds int(11) unsigned default NULL');
      $ret[] = update_sql("ALTER TABLE {video} CHANGE disable_multidownload disable_multidownload tinyint(1) unsigned NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {video} CHANGE use_play_folder use_play_folder tinyint(1) unsigned NOT NULL default '0'");
  }
  return $ret;
}

/**
 * Start of Drupal 4.7 support in video.module issue #40005, version 1.25
 * updated revisions, db schema, forms api, form validation, permissions, added .swf and image support
 *
 * @return array
 */
function video_update_4() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {video} ADD vid int(10) unsigned NOT NULL default '0' FIRST");
      $ret[] = update_sql('UPDATE {video} SET vid = nid');
      $ret[] = update_sql('ALTER TABLE {video} CHANGE video_bitrate video_bitrate int(10) unsigned default NULL');
      $ret[] = update_sql('ALTER TABLE {video} CHANGE audio_bitrate audio_bitrate int(10) unsigned default NULL');
      $ret[] = update_sql('ALTER TABLE {video} CHANGE audio_sampling_rate audio_sampling_rate int(10) unsigned default NULL');
      $ret[] = update_sql('ALTER TABLE {video} CHANGE playtime_seconds playtime_seconds int(10) unsigned default NULL');
      $ret[] = update_sql('ALTER TABLE {video} ADD serialized_data text NULL default NULL');
      $ret[] = update_sql('ALTER TABLE {video} DROP PRIMARY KEY, ADD PRIMARY KEY ( `vid` )');
  }
  return $ret;
}

/**
 * Add the vtype field for video module subtypes
 *
 * @return array
 */
function video_update_5() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {video} ADD vtype varchar(32) NOT NULL default ''");
  }
  return $ret;
}

/* used for update 6 */
function _video_update_6_get_vtype($node) {
  $file_type = '';
  $vidfile = $node->vidfile;

  //If the filename doesn't contain a ".", "/", or "\" and is exactly 11 characters then consider it a youtube video ID.
  if (!strpos($vidfile, '.') and !strpos($vidfile, '/') and !strpos($vidfile, '\\') and strlen($vidfile) == 11) {
    $file_type = 'youtube';
  }
  else {
    if (strpos($vidfile, 'google:') === 0) {
      $file_type = 'google';
    }
    else {
      if (db_result(db_query("SELECT count(fid) FROM {files} WHERE nid=%d", $node->nid)) > 0) {
        $file_type = 'upload';
      }
      else {
        if ($vidfile != '') {

          // enable absolute urls and relative paths
          $file_type = 'url';
        }
        else {
          drupal_set_message(t('Could not determine video type of node %nid', array(
            '%nid' => $node->nid,
          )), 'error');
        }
      }
    }
  }
  return $file_type;
}

/**
 * Set vtype for all the videos
*/
function video_update_6() {

  /* this function should be able to be run again and again until
   * all the videos have been updated */
  $videos = db_query("SELECT nid,vidfile FROM {video} WHERE vtype=''");
  while ($video = db_fetch_object($videos)) {
    db_query("UPDATE {video} SET vtype='%s' WHERE nid=%d", _video_update_6_get_vtype($video), $video->nid);
  }
  return array();
}

/**
 * Set default values of resolutions
*/
function video_update_7() {
  variable_set('video_resolution_1_name', '4:3 - Television');
  variable_set('video_resolution_1_value', '400x300');
  variable_set('video_resolution_2_name', '16:9 - Widescreen');
  variable_set('video_resolution_2_value', '400x226');
  return array();
}

/**
 * Video_upload changes from relying on files table to locate
 * video file to saving it in serialized_data as video_fid
*/
function video_update_8() {

  /* select all the video upload video nodes */
  $vnodes = db_query("SELECT n.nid,n.vid,serialized_data FROM {node} n INNER JOIN {video} v on n.nid = v.nid WHERE n.type = 'video' AND v.vtype = 'upload' AND v.serialized_data NOT LIKE '%video_fid%'");
  while ($node = db_fetch_object($vnodes)) {

    /* load the video file info */
    if ($node->vid) {
      $result = db_query('SELECT * FROM {files} f INNER JOIN {file_revisions} r ON f.fid = r.fid WHERE r.vid = %d ORDER BY f.fid DESC', $node->vid);
      if (!$result) {
        continue;
      }
      $result = db_fetch_object($result);

      /* save the new serialized_data */
      $data = unserialize($node->serialized_data);
      $data['video_fid'] = $result->fid;
      $data = serialize($data);
      $res = db_query("UPDATE {video} SET serialized_data='%s' WHERE nid=%d", $data, $node->nid);
    }
  }
  return array();
}

/**
 * Update the vidfile for youtube videos so they will work again
 */
function video_update_9() {
  $res[] = update_sql("UPDATE {video} SET vidfile=CONCAT('http://www.youtube.com/watch?v=',vidfile) WHERE vtype='youtube' AND vidfile NOT LIKE '%youtube.com/watch%'");
  return $res;
}

/**
 * Update vidfile for google videos -- they play, but they are not editable
 * in the current form because validation fails upon submit
 */
function video_update_10() {
  $res[] = update_sql("UPDATE {video} SET vidfile=CONCAT('http://video.google.com/videoplay?docid=',SUBSTR(vidfile,8)) WHERE vtype='google' AND vidfile LIKE 'google:%'");
  return $res;
}

/**
 * Update database schema by removing custom fields - #419802
 * in the current setting conflict with the CCK
 */
function video_update_11() {
  $res[] = update_sql('ALTER TABLE {video} DROP custom_field_1');
  $res[] = update_sql('ALTER TABLE {video} DROP custom_field_2');
  $res[] = update_sql('ALTER TABLE {video} DROP custom_field_3');
  $res[] = update_sql('ALTER TABLE {video} DROP custom_field_4');
  $res[] = update_sql('ALTER TABLE {video} DROP custom_field_5');
  $res[] = update_sql('ALTER TABLE {video} DROP custom_field_6');
  return $res;
}

Functions

Namesort descending Description
video_install
video_uninstall Uninstall video module
video_update_1 Add audio details
video_update_10 Update vidfile for google videos -- they play, but they are not editable in the current form because validation fails upon submit
video_update_11 Update database schema by removing custom fields - #419802 in the current setting conflict with the CCK
video_update_2 Rename counter, add custom fields, for video.module version 1.9
video_update_3 Add unsigned to all int fields
video_update_4 Start of Drupal 4.7 support in video.module issue #40005, version 1.25 updated revisions, db schema, forms api, form validation, permissions, added .swf and image support
video_update_5 Add the vtype field for video module subtypes
video_update_6 Set vtype for all the videos
video_update_7 Set default values of resolutions
video_update_8 Video_upload changes from relying on files table to locate video file to saving it in serialized_data as video_fid
video_update_9 Update the vidfile for youtube videos so they will work again
_video_update_6_get_vtype