You are here

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

Get any core profile values associated with this user.

Parameters

$row:

$entity_id:

Overrides DrupalVersion::getProfileValues

1 call to DrupalVersion7::getProfileValues()
DrupalVersion7::getSourceValues in d7/d7.inc
Populate a migration's source row object with field values.

File

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

Class

DrupalVersion7
@file Implementation of DrupalVersion for Drupal 7 sources.

Code

public function getProfileValues($row, $entity_id) {
  if (Database::getConnection('default', $this->arguments['source_connection'])
    ->schema()
    ->tableExists('profile_value')) {
    migrate_instrument_start('DrupalVersion7::getProfileValues');
    $query = Database::getConnection('default', $this->arguments['source_connection'])
      ->select('profile_value', 'v')
      ->fields('v', array(
      'value',
    ))
      ->condition('uid', $entity_id)
      ->condition('value', '', '<>');
    $query
      ->innerJoin('profile_field', 'f', 'v.fid=f.fid');
    $query
      ->fields('f', array(
      'name',
      'type',
    ));
    $result = $query
      ->execute();
    foreach ($result as $data_row) {
      switch ($data_row->type) {
        case 'checkbox':
          switch (trim(strtolower($data_row->value))) {
            case 'n':
              $data_row->value = 0;
              break;
            case 'y':
              $data_row->value = 1;
              break;
            default:
              break;
          }
          break;
        case 'date':

          // Dates may be serialized arrays or NULLs.
          if (strpos($data_row->value, 'a:') === 0) {
            $date_array = unserialize($data_row->value);
            $data_row->value = $date_array['year'] . '-' . $date_array['month'] . '-' . $date_array['day'];
          }
          elseif (strpos($data_row->value, 'N;') === 0) {
            $data_row->value = NULL;
          }
          break;
      }
      $row->{$data_row->name} = $data_row->value;
    }
    migrate_instrument_stop('DrupalVersion7::getProfileValues');
  }
}