You are here

function flashnode_update_6000 in Flash Node 6.3

Same name and namespace in other branches
  1. 6.2 flashnode.install \flashnode_update_6000()

If this is an upgrade install (i.e. from Drupal 5) then update flashnode filepath entries in {files} to be consistent with Drupal 6 storage convention Also update schema to ensure it matches new specification

File

./flashnode.install, line 100

Code

function flashnode_update_6000() {

  // Initialise array for results
  $ret = array();

  // Retrieve the file_directory_path and append a slash
  $base = file_directory_path() . '/';

  // SQL string varies depending whether MySQL or Postgres
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $sql = "UPDATE {files} SET filepath = CONCAT('" . $base . "', filepath) WHERE filename = '_flashnode'";
      break;
    case 'pgsql':
      $sql = "UPDATE {files} SET filepath = '" . $base . "' || filepath WHERE filename = '_flashnode'";
  }

  // Run the update
  $ret[] = update_sql($sql);

  // Drop the existing primary key (nid)
  db_drop_primary_key($ret, 'flashnode');

  // Amend vid to match new schema
  db_change_field($ret, 'flashnode', 'vid', 'vid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'vid',
    ),
  ));

  // Amend fid to match new schema
  db_change_field($ret, 'flashnode', 'fid', 'fid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array());

  // Amend base to match new schema
  db_change_field($ret, 'flashnode', 'base', 'base', array(
    'type' => 'varchar',
    'length' => '255',
    'not null' => TRUE,
  ), array());

  // Amend nid to match new schema
  db_change_field($ret, 'flashnode', 'nid', 'nid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array());

  // Amend height to match new schema
  db_change_field($ret, 'flashnode', 'height', 'height', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array());

  // Amend height to match new schema
  db_change_field($ret, 'flashnode', 'width', 'width', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array());

  // Amend display to match new schema
  db_change_field($ret, 'flashnode', 'display', 'display', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'size' => 'tiny',
    'not null' => TRUE,
  ), array());

  // Amend substitution to match new schema
  db_change_field($ret, 'flashnode', 'substitution', 'substitution', array(
    'type' => 'text',
    'size' => 'big',
    'not null' => TRUE,
  ), array());

  // Amend flashvars to match new schema
  db_change_field($ret, 'flashnode', 'flashvars', 'flashvars', array(
    'type' => 'text',
    'size' => 'big',
    'not null' => TRUE,
  ), array());

  // Return results
  return $ret;
}