+ * Allows site administrator to execute migration of old/disabled/deleted

+ * file types to new ones.

+ */

+function media_upgrade_file_types($form, &$form_state) {

+ $migratable_types = _media_get_migratable_file_types();

+

+ // Silently return if there are no file types that need migration.

+ if (empty($migratable_types)) {

+ return array(

+ 'message' => array(

+ '#markup' => t('There are no file types that need migration.'),

+ ),

+ );

+ }

+

+ $form['message'] = array(

+ 'message' => array(

+ '#markup' => t('This page allows you to migrate deprecated and/or disabled file types to new ones. It will migrate files from old type to new one and optionally migrate fields and delete old type.'),

+ ),

+ );

+

+ $form['migrate_fields'] = array(

+ '#type' => 'checkbox',

+ '#title' => t('Migrate fields'),

+ '#default_value' => TRUE,

+ '#description' => t('Migrate fields and their values from old file types to new ones.'),

+ );

+ $form['delete_old_type'] = array(

+ '#type' => 'checkbox',

+ '#title' => t('Delete old type'),

+ '#default_value' => FALSE,

+ '#description' => t('Delete old file type if migration was successful and delete operation is possible (type is not exported in code).'),

+ );

+ $form['migrate_mimes'] = array(

+ '#type' => 'checkbox',

+ '#title' => t('Migrate type mime-type'),

+ '#default_value' => TRUE,

+ '#description' => t('Move mime-type from old type to new one.'),

+ );

+

+ $form['upgradable_types'] = array(

+ '#type' => 'fieldset',

+ '#title' => t('Upgradable file types'),

+ );

+

+ $options = array('- ' . t('Do not upgrade') . ' -');

+ foreach (file_type_get_enabled_types() as $type) {

+ $options[$type->type] = $type->label;

+ }

+

+ foreach ($migratable_types as $machine_name) {

+ $type = file_type_load($machine_name);

+ if (!$type) {

+ $type = new stdClass;

+ $type->label = $type->type = $machine_name;

+ }

+ $form['upgradable_types'][$machine_name] = array(

+ '#type' => 'select',

+ '#title' => $type->label,

+ '#options' => $options,

+ '#description' => t(

+ 'Select file type which you want to migrate @type to. Select %no_upgrade if type should stay as it is.',

+ drupal_set_message(t('There are disabled/deleted file types that can be migrated to their new alternatives. Visit <a href="!url">migration page</a> to get more information.', array('!url' => url('admin/structure/file-types/upgrade'))));