Closed (duplicate)
Project:
D7 Media
Version:
7.x-2.x-dev
Component:
Media field
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Mar 2012 at 23:27 UTC
Updated:
30 Jun 2012 at 18:56 UTC
I have code here that does the work for you
// Put this into an update.
if (!module_exists('mediafield')) {
return t('');
}
$field = 'field_local_audio'; // This is specific to me.
$display_sepc = array (
'description' => 'Flag to control whether this file should be displayed when viewing content.',
'type' => 'int',
'size' => 'tiny',
'default' => 1,
'unsigned' => TRUE,
'not null' => TRUE,
);
$description_sepc = array (
'description' => 'A description of the file.',
'type' => 'text',
'not null' => FALSE,
);
// Change the thingies
db_add_field("field_data_$field", $field_display, $display_sepc);
db_add_field("field_data_$field", $field_description, $description_sepc);
db_add_field("field_revision_$field", $field_display, $display_sepc);
db_add_field("field_revision_$field", $field_description, $description_sepc); //*/
// Add the data to config
$result = db_update('field_config')
->fields(array(
'type' => 'file',
'module' => 'file',
))
->condition('field_name', $field)
->execute();
module_disable(array('mediafield'));
Comments
Comment #1
aaron commentedshould this be part of the media module instead?
Comment #2
dave reidYeah I would welcome this to be fully supported in mediafield_uninstall().
Comment #3
philippejadin commentedNow that mediafield is deprecated, can we expect to have an "upgrade" path to filefield on 7.x-1.0?
This would be great !
Comment #4
dave reidIt's not too high on the list of priorities since we'll still be support the mediafield, but yes some time down the road we'll need a migration to move those fields to file fields. The code above is a start but it needs work to make it a more generic migration.
Comment #5
avillanueva-npr commentedThe code above is mostly hard coded but it's a start. I wanted to put it here for posterity so we don't need to remember how to do this later down the line and instead search for it. Either way it's not taking into account the field that needs to be replaced (I hard coded it for our implementation here at NPR) nor does it remove the old fields that exist from the previous field implementation from Media 1.0
Comment #6
adarkling commentedThanks avillanueva-npr !
That really came in handy! I adapted it a bit to handle the 2 issues you just spoke about.
Comment #7
dave reidRealizing we have two issues open for the same thing, so I need to mark this as a duplicate of #1349058: Convert 'Media' fields to 'File' fields that use the 'Media file selector' widget. I'm going to cross-reference it to ensure we don't lose the code that's been provided here if it can be useful.
Comment #7.0
dave reidMinor formatting changes