Remove upload module and provide upgrade path to file: http://drupal.org/node/563000 From: andrew morton --- modules/field_ui/field_ui.admin.inc | 2 - modules/system/system.install | 139 +++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 1 deletions(-) diff --git modules/field_ui/field_ui.admin.inc modules/field_ui/field_ui.admin.inc index 792b642..72cd112 100644 --- modules/field_ui/field_ui.admin.inc +++ modules/field_ui/field_ui.admin.inc @@ -839,7 +839,7 @@ function field_ui_field_settings_form($form, &$form_state, $obj_type, $bundle, $ '#options' => array(TRUE => t('Translatable field'), FALSE => t('Language neutral field')), '#default_value' => $field['translatable'], '#description' => t("Translatable fields can have a different value for each available language. An example of a translatable field is an article's body. Language neutral fields will retain the same value across all translations. An example of a language neutral field is a user profile's first name."), - ); + ); // Add settings provided by the field module. $form['field']['settings'] = array(); diff --git modules/system/system.install modules/system/system.install index 1242daa..0dfcca3 100644 --- modules/system/system.install +++ modules/system/system.install @@ -2493,6 +2493,145 @@ function system_update_7037() { } /** + * Migrate the upload module's data to a file field. + * + * TODO: Determine if we should move the updates done in upload_update_7000() into this update. + * TODO: Turn this into a batch operation to avoid timeouts. + * TODO: Test the translateabiltiy + */ +function system_update_7038() { + $ret = array(); + + $upload_types = array(); + + // Check for the existance of the table rather than using module_exists() + // so we migrate even if the module is disabled. + if (db_table_exists('upload')) { + // Install the file module if itn't already. + if (!module_exists('file')) { + drupal_install_modules(array('file')); + } + + // Figure out which node types allow uploads. + foreach (node_type_get_types() as $node_type => $node_info) { + if (variable_get("upload_$node_type", TRUE)) { + $upload_types[] = $node_type; + } + } + } + + // If there are any active node types create a field and migrate the file + // ids. + if (count($upload_types)) { + module_load_include('inc', 'field', 'field.crud'); +# Based off of output from: +#var_export(field_read_field('field_upload')); + $field = array( + 'field_name' => 'field_upload', + 'type' => 'file', + 'locked' => FALSE, + 'module' => 'file', + 'cardinality' => '-1', + 'translatable' => FALSE, + 'settings' => array( + 'display_field' => 1, + 'display_default' => 1, + 'uri_scheme' => variable_get('file_default_scheme', 'public'), + 'default_file' => 0, + ), + ); + field_create_field($field); + +# Based off of output from: +#var_export(field_read_instance('field_upload', 'page')); + $instance = array( + 'field_name' => 'field_upload', + 'bundle' => NULL, # TODO: set this while looping over the types. + 'label' => 'File attachments', + 'required' => 0, + 'description' => '', + 'widget' => array( + 'weight' => '1', + 'module' => 'file', + 'active' => '1', + 'settings' => array( + 'progress_indicator' => 'throbber', + 'description_field' => 1, + ), + 'type' => 'file_generic', + ), + 'display' => array( + 'full' => array( + 'label' => 'above', + 'type' => 'file_table', + 'settings' => array(), + 'weight' => 0, + 'module' => 'file', + ), + 'teaser' => array( + 'label' => 'hidden', + 'type' => 'hidden', + 'settings' => array(), + 'weight' => 0, + 'module' => NULL, + ), + 'rss' => array( + 'label' => 'hidden', + 'type' => 'file_table', + 'settings' => array(), + 'weight' => 0, + 'module' => 'file', + ), + ), + 'settings' => array( + 'max_filesize' => variable_get('upload_uploadsize_default', 1), + 'file_extensions' => variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'), + 'file_directory' => '', + ), + ); + foreach ($upload_types as $bundle) { + $instance['bundle'] = $bundle; + field_create_instance($instance); + } + } + + // Migrate records here... keep in mind that each revision can have multiple + // files and we need to put them all on the node object before we can write + // the record. So if/when this beomes a batch operation make sure we get all + // the files for the revision in one batch step. + $uploads = db_select('upload', 'u') + ->fields('u', array('nid', 'vid', 'fid', 'description', 'list', 'weight')) +#this will come back into play once this is done in a batch. +# ->condition('u.vid', $context['last'], '>') + ->orderBy('u.vid', 'ASC') + ->execute(); + +# Need to get this grouping files by vid. +/* + foreach ($uploads as $upload) { + $node = (object) array( + 'nid' => $upload->nid, + 'vid' => $upload->vid, + 'field_upload' => array( + FIELD_LANGUAGE_NONE => array( + 0 => array( + ) + ), + ), + ); + + // This is a core update and no contrib modules are enabled yet, so + // we can assume default field storage for a faster update. + field_sql_storage_field_storage_write('node', $node, FIELD_STORAGE_INSERT, array()); + } +*/ + + // Uninstall the upload module. +# drupal_uninstall_modules(array('upload')); + return $ret; +} + +/** * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. */