You are here

public function DrupalVersion7::getSourceValues in Drupal-to-Drupal data migration 7.2

Populate a migration's source row object with field values.

Parameters

$row:

$entity_id:

$include_body:

Overrides DrupalVersion::getSourceValues

File

d7/d7.inc, line 156
Implementation of DrupalVersion for Drupal 7 sources.

Class

DrupalVersion7
@file Implementation of DrupalVersion for Drupal 7 sources.

Code

public function getSourceValues($row, $entity_id) {

  // Core profile values.
  if ($this->entityType == 'user') {
    $this
      ->getProfileValues($row, $entity_id);
  }

  // Load up field data for dynamically mapped fields
  foreach ($this->sourceFieldInfo as $field_name => $field_info) {

    // Skip core profile values.
    if (!isset($field_info['module']) || $field_info['module'] != 'profile') {

      // Find the data in field_data_$field_name.
      $table = "field_data_{$field_name}";
      $result = Database::getConnection('default', $this->arguments['source_connection'])
        ->select($table, 'f')
        ->fields('f')
        ->condition('entity_type', $this->entityType)
        ->condition('bundle', $this->bundle)
        ->condition('entity_id', $entity_id)
        ->orderBy('delta')
        ->execute();
      foreach ($result as $field_row) {
        $i = 0;

        // We assume the first column is the "primary" value of the field, and
        // assign the field name rather than the column name for it.
        foreach ($this->sourceFieldInfo[$field_name]['columns'] as $display_name => $column_name) {
          if ($i++ == 0) {
            $index = $field_name;
          }
          else {
            $index = $display_name;
          }
          if (isset($row->{$index}) && !is_array($row->{$index})) {
            $row->{$index} = array(
              $row->{$index},
            );
          }
          $row->{$index}[] = $field_row->{$column_name};
        }
      }
    }
  }
}