You are here

protected function DrupalVersion5::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_body:

1 call to DrupalVersion5::populateSourceFieldInfo()
DrupalVersion5::profileFields in d5/d5.inc
Retrieve any user profile fields from the core profile module or content_profile.

File

d5/d5.inc, line 78
Implementation of DrupalVersion for Drupal 5 sources.

Class

DrupalVersion5
Drupal 5 implementations of functions shared among multiple types of objects.

Code

protected function populateSourceFieldInfo($entity_type, $bundle, $include_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;
  }
  elseif (empty($this->sourceFieldInfo)) {
    migrate_instrument_start('DrupalVersion5::sourceFieldInfo');
    $this->entityType = $entity_type;
    $this->bundle = $bundle;

    // Get each field attached to this type.
    if (Database::getConnection('default', $this->arguments['source_connection'])
      ->schema()
      ->tableExists('node_field_instance')) {
      $query = Database::getConnection('default', $this->arguments['source_connection'])
        ->select('node_field_instance', 'i')
        ->fields('i', array(
        'label',
        'type_name',
      ))
        ->condition('type_name', $bundle);
      $query
        ->innerJoin('node_field', 'f', 'i.field_name = f.field_name');
      $query
        ->fields('f', array(
        'field_name',
        'type',
        'multiple',
        'db_storage',
      ));
      $result = $query
        ->execute();
      foreach ($result as $row) {
        $field_name = trim($row->field_name);
        $db_columns = $this
          ->getFieldTypeColumns($row);
        $columns = array();
        foreach ($db_columns as $column_name) {
          $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,
        );
      }
    }

    // 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',
      );
    }
    migrate_instrument_stop('DrupalVersion5::sourceFieldInfo');
  }
}