-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.inc
49 lines (46 loc) · 1.71 KB
/
migrate.inc
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
<?php
// $Id$
/**
* @file
* Hook implementations to assist with the migration from Drupal 6 to 7
*/
/**
* Implementation of hook_content_migrate_field_alter()
*/
function matrix_content_migrate_field_alter(&$field_value, $instance_value) {
switch ($instance_value['widget']['module']) {
case 'matrix':
$field_value['module'] = 'matrix';
$field_value['type'] = 'matrix_text';
break;
}
}
/**
* Implementation of hook_content_migrate_data_record_alter().
*
* The data in matrix has a one-to-many relationship from node to data
* This hook does the inserts rather than content_migrate which assumes a one-to-one relationship
*/
function matrix_content_migrate_data_record_alter(&$record, $field) {
switch($field['type']) {
case 'matrix_text':
case 'matrix_custom':
$new_table = content_migrate_new_table($field);
$new_revision_table = content_migrate_new_revision($field);
$result = db_query("SELECT * FROM {node_field_matrix_data} WHERE nid = :nid AND vid = :vid AND field_name = :field_name", array(':nid' => $record['entity_id'], ':vid' => $record['revision_id'], ':field_name' => $field['field_name']));
foreach ($result as $row) {
$record[$field['field_name'] . '_row'] = $row->row + 1;
$record[$field['field_name'] . '_col'] = $row->col + 1;
$record[$field['field_name'] . '_value'] = $row->value;
if (!empty($record)) {
if ($record['revision_id'] == $row->vid) {
drupal_write_record($new_table, $record);
}
drupal_write_record($new_revision_table, $record);
}
$record['delta']++;
}
$record = array(); //prevent content_migrate from processing anything
break;
}
}