function media_update_7002 in D7 Media 7.3
Same name and namespace in other branches
- 7.4 media.install \media_update_7002()
- 7 media.install \media_update_7002()
- 7.2 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 181 - 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);
db_merge('media_type')
->key(array(
'name' => $type->name,
))
->fields((array) $type)
->execute();
}
variable_del('media_types');
}