You are here

protected function DrupalVersion6::profileFields in Drupal-to-Drupal data migration 7.2

Retrieve any user profile fields from the core profile module or content_profile.

Return value

array

1 call to DrupalVersion6::profileFields()
DrupalVersion6::populateSourceFieldInfo in d6/d6.inc
Retrieve info on all fields attached to the given entity type and bundle. Populates $this->sourceFieldInfo.

File

d6/d6.inc, line 424
Implementation of DrupalVersion for Drupal 6 sources.

Class

DrupalVersion6
Drupal 6 implementations of functions shared among multiple types of objects.

Code

protected function profileFields() {
  migrate_instrument_start('DrupalVersion6::profileFields');

  // Get any content_profile node types. A variable named content_profile_use_foo
  // with a serialized value of 1 means foo is a node type of interest.
  $names = Database::getConnection('default', $this->arguments['source_connection'])
    ->select('variable', 'v')
    ->fields('v', array(
    'name',
  ))
    ->condition('name', 'content_profile_use_%', 'LIKE')
    ->condition(db_or()
    ->condition('value', 'i:1;')
    ->condition('value', 'b:1;'))
    ->execute()
    ->fetchCol();
  $index = strlen('content_profile_use_');
  foreach ($names as $name) {
    $type_name = substr($name, $index);
    $this->profileTypes[] = $type_name;

    // Populates sourceFieldInfo directly
    $this
      ->populateSourceFieldInfo('node', $type_name, TRUE);
  }

  // If the profile node type is defined by a feature, the content_profile
  // variable may not be in the variables table, but we might find it
  // strongarmed in cache.
  $strongarm = Database::getConnection('default', $this->arguments['source_connection'])
    ->select('cache', 'c')
    ->fields('c', array(
    'data',
  ))
    ->condition('cid', 'strongarm')
    ->execute()
    ->fetchField();
  if ($strongarm) {
    $strongarm = unserialize($strongarm);
    $prefix = 'content_profile_use_';
    $prefix_len = strlen($prefix);
    foreach ($strongarm as $key => $value) {
      if (substr($key, 0, $prefix_len) == $prefix && $value == 1) {
        $type_name = substr($key, $prefix_len);
        if (!in_array($type_name, $this->profileTypes)) {
          $this->profileTypes[] = $type_name;

          // Populates sourceFieldInfo directly
          $this
            ->populateSourceFieldInfo('node', $type_name, TRUE);
        }
      }
    }
  }

  // Then, check the core profile
  if (Database::getConnection('default', $this->arguments['source_connection'])
    ->schema()
    ->tableExists('profile_fields')) {
    $query = Database::getConnection('default', $this->arguments['source_connection'])
      ->select('profile_fields', 'f')
      ->fields('f', array(
      'title',
      'name',
      'type',
    ));
    $result = $query
      ->execute();
    foreach ($result as $row) {
      $this->sourceFieldInfo[trim($row->name)] = array(
        'label' => $row->title,
        'type' => $row->type,
      );
    }
  }
  migrate_instrument_stop('DrupalVersion6::profileFields');
}