You are here

function file_entity_update_7210 in File Entity (fieldable files) 7.3

Same name and namespace in other branches
  1. 7.2 file_entity.install \file_entity_update_7210()

Merge MIME types into the {file_type} table.

File

./file_entity.install, line 904
Install, update and uninstall functions for the file_entity module.

Code

function file_entity_update_7210() {

  // Add the new mimetypes field if it doesn't already exist.
  if (!db_field_exists('file_type', 'mimetypes')) {
    $field = array(
      'description' => 'Mimetypes mapped to this file type.',
      'type' => 'blob',
      'size' => 'big',
      'not null' => FALSE,
      'serialize' => TRUE,
    );
    db_add_field('file_type', 'mimetypes', $field);
  }

  // Migrate any existing MIME type information into {file_type}.
  if (db_table_exists('file_type_mimetypes')) {
    module_load_include('inc', 'file_entity', 'file_entity.file_api');
    $types = file_type_load_all(TRUE);
    foreach ($types as $type) {
      $mimetypes = db_select('file_type_mimetypes', 'ftm')
        ->fields('ftm', array(
        'mimetype',
      ))
        ->condition('type', $type->type)
        ->execute()
        ->fetchCol();
      if (!empty($mimetypes)) {
        $type->mimetypes = $mimetypes;
        file_type_save($type);
      }
    }

    // Remove {file_type_mimetypes} after the information is migrated.
    db_drop_table('file_type_mimetypes');
  }
}