content_migrate.api.php 2.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php

/**
 * @file
 * Documentation for content migrate API.
 */

/**
 * Implement this hook to alter the field definition of the migrated content.
 *
 * Use this to tweak the conversion of field settings from the D6 style to the
 * D7 style for specific situations not handled by basic conversion, as when
 * field types or settings are changed.
 *
 * @param $field_value
 * @param $instance_value
 */
function hook_content_migrate_field_alter(&$field_value, $instance_value) {
  switch ($instance_value['widget']['module']) {
    case 'filefield':
      // Module names and types changed.
      $field_value['module'] = 'file';
      $field_value['type'] = 'file';
      break;
  }
}

/**
 * Implements this hook to alter the instance definition of the migrated content.
 *
 * Use this to tweak the conversion of instance or widget settings from the D6
 * style to the D7 style for specific situations not handled by basic
 * conversion, as when formatter or widget names or settings are changed.
 *
 * @param $instance_value
 * @param $field_value
 */
function hook_content_migrate_instance_alter(&$instance_value, $field_value) {
  switch ($instance_value['widget']['module']) {
    case 'text':
      // The formatter names changed, all are prefixed with 'text_'.
      foreach ($instance_value['display'] as $context => $settings) {
        $instance_value['display'][$context]['type'] = 'text_'. $settings['type'];
      }
      break;
  }
}


/**
 * Implement this hook to alter individual data records as they are migrated.
 *
 * This hook is called after the old data record has been read from the
 * database and before it is inserted into the corresponding D7 field. The data
 * column names are renamed in a one-to-one mapping by the order they appear in
 * the database. This is often the desired behavior, but in some cases an
 * implementation of this hook may need to move data between columns.
 *
 * @param $record
 *  The data record, as read by _content_migrate_batch_process_migrate_data().
 *  If the ordering of the D6 and D7 field columns remain the same, no action
 *  is required. If the columns were re-ordered or the data format was changed,
 *  $record should be modified to fit the new field definition.
 * @param $field
 *
 */
function hook_content_migrate_data_record_alter(&$record, $field) {
  switch($field['type']) {
    case 'file':
      // Map D6 filefield field columns to D7 file field columns. Note the data
      // which was previously in the 'data' column is read into the
      // 'description' column since the data column no longer exists.
      if (!empty($record[$field['field_name'] . '_description']) && ($data = unserialize($record[$field['field_name'] . '_description']))) {
        $record[$field['field_name'] . '_description'] = $data['description'];
      }
      else {
        unset($record[$field['field_name'] . '_description']);
      }
      break;
  }
}