protected function DrupalVersion6::populateSourceFieldInfo in Drupal-to-Drupal data migration 7.2
Retrieve info on all fields attached to the given entity type and bundle. Populates $this->sourceFieldInfo.
Parameters
$entity_type:
$bundle:
$include_title_body:
1 call to DrupalVersion6::populateSourceFieldInfo()
- DrupalVersion6::profileFields in d6/
d6.inc - Retrieve any user profile fields from the core profile module or content_profile.
File
- d6/
d6.inc, line 78 - Implementation of DrupalVersion for Drupal 6 sources.
Class
- DrupalVersion6
- Drupal 6 implementations of functions shared among multiple types of objects.
Code
protected function populateSourceFieldInfo($entity_type, $bundle, $include_title_body = FALSE) {
if ($entity_type == 'user') {
// Get core profile fields.
$this
->profileFields();
// If there are content profiles, the recursive calls set these to
// the profile type, so reset them.
$this->entityType = $entity_type;
$this->bundle = $bundle;
}
elseif ($entity_type != 'node') {
return;
}
else {
migrate_instrument_start('DrupalVersion6::sourceFieldInfo');
$this->entityType = $entity_type;
$this->bundle = $bundle;
// Standalone nodes handle the title and body through the core migration,
// but for content_profile nodes we need to deal with them here.
if ($include_title_body) {
$type_info = Database::getConnection('default', $this->arguments['source_connection'])
->select('node_type', 'nt')
->fields('nt', array(
'has_title',
'title_label',
'has_body',
'body_label',
))
->condition('type', $bundle)
->execute()
->fetchObject();
// To hopefully uniquify the machine names, use the content_profile
// node type, with '_node_type' appended, in the name.
if (is_object($type_info)) {
if (!empty($type_info->has_title)) {
$this->sourceFieldInfo['field_' . $bundle . '_node_type_title'] = array(
'label' => $type_info->title_label,
'type' => 'title',
);
}
if (!empty($type_info->has_body)) {
$this->sourceFieldInfo['field_' . $bundle . '_node_type_body'] = array(
'label' => $type_info->body_label,
'type' => 'body',
);
}
}
}
// Get each field attached to this type.
if (Database::getConnection('default', $this->arguments['source_connection'])
->schema()
->tableExists('content_node_field_instance')) {
$query = Database::getConnection('default', $this->arguments['source_connection'])
->select('content_node_field_instance', 'i')
->fields('i', array(
'label',
'widget_settings',
))
->condition('type_name', $bundle);
$query
->innerJoin('content_node_field', 'f', 'i.field_name = f.field_name');
$query
->fields('f', array(
'field_name',
'type',
'db_columns',
'global_settings',
'multiple',
'db_storage',
));
$result = $query
->execute();
foreach ($result as $row) {
$field_name = trim($row->field_name);
$db_columns = $db_columns = !empty($row->db_columns) ? unserialize($row->db_columns) : array();
$columns = array();
foreach ($db_columns as $column_name => $column_info) {
// Special handling for the stuff packed into filefield's "data"
if ($row->type == 'filefield' && $column_name == 'data') {
$widget_settings = unserialize($row->widget_settings);
$global_settings = unserialize($row->global_settings);
if (!empty($widget_settings['custom_alt'])) {
$columns[$field_name . ':alt'] = $field_name . '_alt';
}
if (!empty($widget_settings['custom_title'])) {
$columns[$field_name . ':title'] = $field_name . '_title';
}
if (!empty($global_settings['description_field'])) {
$columns[$field_name . ':description'] = $field_name . '_description';
}
}
else {
$display_name = $field_name . ':' . $column_name;
$column_name = $field_name . '_' . $column_name;
$columns[$display_name] = $column_name;
}
}
$this->sourceFieldInfo[$field_name] = array(
'label' => $row->label,
'type' => $row->type,
'columns' => $columns,
'multiple' => $row->multiple,
'db_storage' => $row->db_storage,
'bundle' => $bundle,
);
}
}
// Get each vocabulary attached to this type.
$query = Database::getConnection('default', $this->arguments['source_connection'])
->select('vocabulary_node_types', 'vnt')
->fields('vnt', array(
'vid',
));
$query
->innerJoin('vocabulary', 'v', 'vnt.vid=v.vid');
$query
->addField('v', 'name');
$query
->condition('vnt.type', $bundle);
$result = $query
->execute();
foreach ($result as $row) {
$this->sourceFieldInfo[$row->vid] = array(
'label' => $row->name,
'type' => 'taxonomy_term',
);
}
// If the upload table exists and the type has attachments enabled,
// include upload data.
if (Database::getConnection('default', $this->arguments['source_connection'])
->schema()
->tableExists('upload')) {
$upload = Database::getConnection('default', $this->arguments['source_connection'])
->select('variable', 'v')
->fields('v', array(
'value',
))
->condition('name', 'upload_' . $bundle)
->execute()
->fetchField();
if ($upload) {
$upload = unserialize($upload);
}
else {
$upload = 1;
}
if ($upload) {
$this->sourceFieldInfo['upload'] = array(
'label' => t('Upload'),
'type' => 'upload',
);
$this->sourceFieldInfo['upload:description'] = array(
'label' => t('Upload description'),
'type' => 'upload',
);
$this->sourceFieldInfo['upload:list'] = array(
'label' => t('Upload list'),
'type' => 'upload',
);
$this->sourceFieldInfo['upload:weight'] = array(
'label' => t('Upload weight'),
'type' => 'upload',
);
}
}
migrate_instrument_stop('DrupalVersion6::sourceFieldInfo');
}
}