Issue #1230450 by yched: Migrate non-imagecache image formatters
[project/cck.git] / modules / content_migrate / modules / content_migrate.filefield.inc
index fe50bed..0b5d191 100644 (file)
@@ -18,6 +18,7 @@ function content_migrate_filefield_field_alter(&$field_value, $instance_value) {
   // There are a bunch of custom imagefield widgets. If they at least start the widget name with 'imagefield' this will work.
   if (substr($instance_value['widget']['type'], 0, 10) == 'imagefield') {
     // Module names and types changed.
+    $field_value['messages'][] = t("Changed field type: The '@field' field type will be changed from '@type' to 'image'.", array('@type' => $field_value['type'], '@field' => $field_value['field_name'], '@widget' => $instance_value['widget']['type']));
     $field_value['module'] = 'image';
     $field_value['type'] = 'image';
     // default_image is now a field setting.
@@ -26,8 +27,14 @@ function content_migrate_filefield_field_alter(&$field_value, $instance_value) {
   // There are a bunch of custom filefield widgets. If they at least start the widget name with 'filefield' this will work.
   if (substr($instance_value['widget']['type'], 0, 9) == 'filefield') {
     // Module names and types changed.
+    $field_value['messages'][] = t("Changed field type: The '@field' field type will be changed from '@type' to 'file'.", array('@type' => $field_value['type'], '@field' => $field_value['field_name'], '@widget' => $instance_value['widget']['type']));
     $field_value['module'] = 'file';
     $field_value['type'] = 'file';
+    // Some settings have changed names.
+    unset($field_value['settings']['list_field']);
+    $field_value['settings']['display_field'] = $field_value['settings']['list_field'];
+    $field_value['settings']['display_default'] = $field_value['settings']['list_default'];
+    unset($field_value['settings']['list_default']);
   }
 }
 
@@ -78,6 +85,38 @@ function content_migrate_filefield_instance_alter(&$instance_value, $field_value
                
       // default_image is now a field setting.
       unset($instance_value['widget']['settings']['default_image']);
+
+      // Translate formatters.
+      foreach ($instance_value['display'] as $context => $settings) {
+        switch ($settings['type']) {
+          case 'image_plain':
+            $instance_value['display'][$context]['type'] = 'image';
+            $instance_value['display'][$context]['module'] = 'image';
+            $instance_value['display'][$context]['settings'] = array(
+              'image_style' => '',
+              'image_link' => '',
+            );
+            break;
+
+          case 'image_nodelink':
+            $instance_value['display'][$context]['type'] = 'image';
+            $instance_value['display'][$context]['module'] = 'image';
+            $instance_value['display'][$context]['settings'] = array(
+              'image_style' => '',
+              'image_link' => 'content',
+            );
+            break;
+
+          case 'image_imagelink':
+            $instance_value['display'][$context]['type'] = 'image';
+            $instance_value['display'][$context]['module'] = 'image';
+            $instance_value['display'][$context]['settings'] = array(
+              'image_style' => '',
+              'image_link' => 'file',
+            );
+            break;
+        }
+      }
       break;
 
     case 'filefield':
@@ -85,12 +124,26 @@ function content_migrate_filefield_instance_alter(&$instance_value, $field_value
       $instance_value['widget']['module'] = 'file';
       $instance_value['widget']['type'] = 'file_generic';
 
-      // Some settings had name changes.
-      $instance_value['widget']['settings']['file_directory'] = $instance_value['widget']['settings']['file_path'];
+      // Some settings had name changes, or moved from the widget to the
+      // instance.
+      $instance_value['settings']['file_directory'] = $instance_value['widget']['settings']['file_path'];
       unset($instance_value['widget']['settings']['file_path']);
-      $instance_value['widget']['settings']['max_filesize'] = $instance_value['widget']['settings']['max_filesize_per_file'];
+      $instance_value['settings']['file_extensions'] = $instance_value['widget']['settings']['file_extensions'];
+      unset($instance_value['widget']['settings']['file_extensions']);
+      $instance_value['settings']['max_filesize'] = $instance_value['widget']['settings']['max_filesize_per_file'];
       unset($instance_value['widget']['settings']['max_filesize_per_file']);
 
+      // This setting is gone.
+      unset($instance_value['widget']['settings']['max_filesize_per_node']);
+
+      // Translate formatter names.
+      foreach ($instance_value['display'] as $context => $settings) {
+        // Note; the 'path_plain' D6 formatter has disappeared.
+        if (in_array($settings['type'], array('default', 'url_plain'))) {
+          $instance_value['display'][$context]['type'] = 'file_'. $settings['type'];
+          $instance_value['display'][$context]['moduke'] = 'file';
+        }
+      }
       break;
   }
  
@@ -102,12 +155,12 @@ function content_migrate_filefield_instance_alter(&$instance_value, $field_value
  *
  * Tweaks individual records in a field.
  */
-function content_migrate_filefield_data_record_alter(&$record, $field) {
+function content_migrate_filefield_data_record_alter(&$record, $field, $instance) {
 
   switch($field['type']) {
     case 'image':
       // Map D6 imagefield field columns to D7 image field columns.
-      if (!empty($record[$field['field_name'] . '_title']) && ($data = unserialize($record[$field['field_name'] . '_title']))) {
+      if (!empty($record[$field['field_name'] . '_data']) && ($data = unserialize($record[$field['field_name'] . '_data']))) {
         $record[$field['field_name'] . '_alt'] = $data['alt'];
         $record[$field['field_name'] . '_title'] = $data['title'];
       }
@@ -119,13 +172,18 @@ function content_migrate_filefield_data_record_alter(&$record, $field) {
     // Fall through.
     case 'file':
       // Map D6 filefield field columns to D7 file field columns.
-      if (!empty($record[$field['field_name'] . '_description']) && ($data = unserialize($record[$field['field_name'] . '_description']))) {
+      if (!empty($record[$field['field_name'] . '_data']) && ($data = unserialize($record[$field['field_name'] . '_data'])) && isset($data['description'])) {
         $record[$field['field_name'] . '_description'] = $data['description'];
       }
       else {
         unset($record[$field['field_name'] . '_description']);
       }
 
+      if (isset($record[$field['field_name'] . '_list'])) {
+        $record[$field['field_name'] . '_display'] = $record[$field['field_name'] . '_list'];
+        unset($record[$field['field_name'] . '_list']);
+      }
+
       // Copies imagefield data from the old 'files' table into 'files_managed' and sets file_usage
       // Mostly copied from system_update_7061, which does the same for the D6 core 'upload' module