You are here

function mediafront_update_6003 in MediaFront 6.2

Same name and namespace in other branches
  1. 6 mediafront.install \mediafront_update_6003()

Add the mediafront_filefield table, and remove the mediafront_imagecache module.

File

./mediafront.install, line 123

Code

function mediafront_update_6003() {
  $update = array();

  // Create the mediafront_filefield table.
  db_create_table($update, 'mediafront_filefield', array(
    'description' => 'Table used to tell the MediaFront module how each FileField should be handled.',
    'fields' => array(
      'fid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'node_type' => array(
        'type' => 'text',
        'not null' => FALSE,
      ),
      'field_name' => array(
        'type' => 'text',
        'not null' => FALSE,
      ),
      'media_type' => array(
        'type' => 'text',
        'not null' => FALSE,
      ),
      'node_preset' => array(
        'type' => 'text',
        'not null' => FALSE,
      ),
      'thumb_preset' => array(
        'type' => 'text',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'fid',
    ),
  ));

  // We now need to iterate through all of the current settings of
  // the obsolete MediaFront ImageCache module and transfer those settings to this module.
  $presets = db_query("SELECT * FROM {mediafront_imagecache}");
  while ($preset = db_fetch_object($presets)) {
    $sql = "INSERT INTO {mediafront_filefield} (node_type, field_name, node_preset, thumb_preset) ";
    $sql .= "VALUES ( '{$preset->node_type}', '{$preset->field_name}', '{$preset->node_preset}', '{$preset->thumb_preset}' )";
    $update[] = update_sql($sql);
  }
  $dir = getcwd() . '/' . drupal_get_path('module', 'mediafront_imagecache');

  // Now disable and uninstall the mediafront_imagecache module.
  module_disable(array(
    'mediafront_imagecache',
  ));
  drupal_uninstall_module('mediafront_imagecache');

  // Now delete the old files we don't need.
  file_delete($dir . '/mediafront_imagecache.module');
  file_delete($dir . '/mediafront_imagecache.info');
  file_delete($dir . '/mediafront_imagecache.install');
  return $update;
}