content_taxonomy_migrate.module in Content Taxonomy 7
File
content_taxonomy_migrate.module
View source
<?php
function content_taxonomy_migrate_content_migrate_field_alter(&$field_value, $instance_value) {
if ($field_value['type'] == 'content_taxonomy') {
$field_value['type'] = 'taxonomy_term_reference';
$field_value['module'] = 'taxonomy';
$old_settings = $field_value['settings'];
$vocabulary = taxonomy_vocabulary_load($old_settings['vid']);
$field_value['settings'] = array();
$field_value['settings']['allowed_values'] = array();
$field_value['settings']['allowed_values'][0]['vocabulary'] = $vocabulary->machine_name;
$field_value['settings']['allowed_values'][0]['parent'] = $old_settings['parent'];
}
}
function content_taxonomy_migrate_content_migrate_instance_alter(&$instance_value, $field_value) {
if ($field_value['type'] != 'content_taxonomy') {
return;
}
$fix_this_instance = FALSE;
if ($instance_value['widget_type'] == "content_taxonomy_autocomplete") {
$fix_this_instance = TRUE;
$instance_value['widget_type'] = 'taxonomy_autocomplete';
$instance_value['widget']['type'] = 'taxonomy_autocomplete';
$instance_value['widget']['module'] = 'taxonomy';
}
elseif ($instance_value['widget_type'] == "content_taxonomy_options" || $instance_value['widget_type'] == "content_taxonomy_tree") {
$fix_this_instance = TRUE;
$instance_value['widget_type'] = 'options_buttons';
$instance_value['widget']['type'] = 'options_buttons';
$instance_value['widget']['module'] = 'options';
}
elseif ($instance_value['widget_type'] == "content_taxonomy_select" || $instance_value['widget_type'] == 'content_taxonomy_hs') {
$fix_this_instance = TRUE;
$instance_value['widget_type'] = 'options_select';
$instance_value['widget']['type'] = 'options_select';
$instance_value['widget']['module'] = 'options';
}
foreach ($instance_value['display'] as $context => $settings) {
if ($instance_value['display'][$context]['type'] == 'default') {
$fix_this_instance = TRUE;
$instance_value['display'][$context]['type'] = 'taxonomy_term_reference_plain';
}
elseif ($instance_value['display'][$context]['type'] == 'link') {
$fix_this_instance = TRUE;
$instance_value['display'][$context]['type'] = 'taxonomy_term_reference_link';
}
if ($instance_value['display'][$context]['module'] == 'content_taxonomy_options') {
$fix_this_instance = TRUE;
$instance_value['display'][$context]['module'] = 'options';
}
}
if ($fix_this_instance && !empty($instance_value['default_value'])) {
foreach ($instance_value['default_value'] as $key => $default) {
if (isset($instance_value['default_value'][$key]['value']) || is_null($instance_value['default_value'][$key]['value'])) {
if (empty($instance_value['default_value'][$key]['value'])) {
unset($instance_value['default_value'][$key]['value']);
}
else {
$instance_value['default_value'][$key]['tid'] = $instance_value['default_value'][$key]['value'];
unset($instance_value['default_value'][$key]['value']);
}
if (isset($instance_value['default_value'][$key]['_error_element'])) {
unset($instance_value['default_value'][$key]['_error_element']);
$updated = TRUE;
}
if (empty($instance_value['default_value'][$key])) {
unset($instance_value['default_value'][$key]);
}
}
if (empty($instance_value['default_value'])) {
$instance_value['default_value'] = NULL;
}
}
}
}
function content_taxonomy_migrate_content_migrate_data_record_alter(&$record, $field) {
if ($field['type'] == 'taxonomy_term_reference') {
if (isset($record[$field['field_name'] . '_value']) && !isset($record[$field['field_name'] . '_tid'])) {
$record[$field['field_name'] . '_tid'] = $record[$field['field_name'] . '_value'];
}
if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $record['entity_type'] == 'node') {
if (isset($record[$field['field_name'] . "_tid"]) && $record[$field['field_name'] . "_tid"]) {
$entity = node_load($record['entity_id']);
db_delete('taxonomy_index')
->condition('nid', $entity->nid)
->condition('tid', $record[$field['field_name'] . "_tid"])
->execute();
$query = db_insert('taxonomy_index')
->fields(array(
'nid',
'tid',
'sticky',
'created',
));
$query
->values(array(
'nid' => $entity->nid,
'tid' => $record[$field['field_name'] . "_tid"],
'sticky' => $entity->sticky,
'created' => $entity->created,
));
$query
->execute();
}
}
}
}