You are here

function media_update_7002 in D7 Media 7

Same name and namespace in other branches
  1. 7.4 media.install \media_update_7002()
  2. 7.2 media.install \media_update_7002()
  3. 7.3 media.install \media_update_7002()

Create the media_type table from the media_types variable.

1 call to media_update_7002()
media_update_7021 in ./media.install
Rerun media_update_7002() due to a typo that would prevent table creation.

File

./media.install, line 302
Install, update and uninstall functions for the Media module.

Code

function media_update_7002() {
  if (db_table_exists('media_type')) {
    return;
  }
  $schema['media_type'] = array(
    'description' => 'Stores the settings for media types.',
    'fields' => array(
      'name' => array(
        'description' => 'The machine name of the media type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'label' => array(
        'description' => 'The label of the media type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'base' => array(
        'description' => 'If this is a base type (i.e. cannot be deleted)',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'weight' => array(
        'description' => 'Weight of media type. Determines which one wins when claiming a piece of media (first wins)',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'normal',
      ),
      'type_callback' => array(
        'description' => 'Callback to determine if provided media is of this type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ),
      'type_callback_args' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'A serialized array of name value pairs that will be passed to the callback function',
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  db_create_table('media_type', $schema['media_type']);
  drupal_load('module', 'media');
  $old_types = variable_get('media_types', array());
  foreach ($old_types as $type) {

    // Was an error in the original creation
    if (isset($type->callbacks)) {
      unset($type->callbacks);
    }
    $type->name = $type->machine_name;
    unset($type->machine_name);
    media_type_save($type);
  }
  variable_del('media_types');
}