8.5.x User.php User::prepareRow(Row $row)
8.5.x User.php User::prepareRow(Row $row)
8.0.x User.php User::prepareRow(Row $row)
8.0.x User.php User::prepareRow(Row $row)
8.1.x User.php User::prepareRow(Row $row)
8.1.x User.php User::prepareRow(Row $row)
8.2.x User.php User::prepareRow(Row $row)
8.2.x User.php User::prepareRow(Row $row)
8.3.x User.php User::prepareRow(Row $row)
8.3.x User.php User::prepareRow(Row $row)
8.4.x User.php User::prepareRow(Row $row)
8.4.x User.php User::prepareRow(Row $row)
8.6.x User.php User::prepareRow(Row $row)
8.6.x User.php User::prepareRow(Row $row)

Adds additional data to the row.

Parameters

\Drupal\Migrate\Row $row: The row object.

Return value

bool FALSE if this row needs to be skipped.

Overrides SourcePluginBase::prepareRow

File

core/modules/user/src/Plugin/migrate/source/d7/User.php, line 63

Class

User
Drupal 7 user source from database.

Namespace

Drupal\user\Plugin\migrate\source\d7

Code

public function prepareRow(Row $row) {
  $roles = $this
    ->select('users_roles', 'ur')
    ->fields('ur', [
    'rid',
  ])
    ->condition('ur.uid', $row
    ->getSourceProperty('uid'))
    ->execute()
    ->fetchCol();
  $row
    ->setSourceProperty('roles', $roles);
  $row
    ->setSourceProperty('data', unserialize($row
    ->getSourceProperty('data')));

  // Get Field API field values.
  foreach (array_keys($this
    ->getFields('user')) as $field) {
    $row
      ->setSourceProperty($field, $this
      ->getFieldValues('user', $field, $row
      ->getSourceProperty('uid')));
  }

  // Get profile field values. This code is lifted directly from the D6
  // ProfileFieldValues plugin.
  if ($this
    ->getDatabase()
    ->schema()
    ->tableExists('profile_value')) {
    $query = $this
      ->select('profile_value', 'pv')
      ->fields('pv', [
      'fid',
      'value',
    ]);
    $query
      ->leftJoin('profile_field', 'pf', 'pf.fid=pv.fid');
    $query
      ->fields('pf', [
      'name',
      'type',
    ]);
    $query
      ->condition('uid', $row
      ->getSourceProperty('uid'));
    $results = $query
      ->execute();
    foreach ($results as $profile_value) {
      if ($profile_value['type'] == 'date') {
        $date = unserialize($profile_value['value']);
        $date = date('Y-m-d', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
        $row
          ->setSourceProperty($profile_value['name'], [
          'value' => $date,
        ]);
      }
      elseif ($profile_value['type'] == 'list') {

        // Explode by newline and comma.
        $row
          ->setSourceProperty($profile_value['name'], preg_split("/[\r\n,]+/", $profile_value['value']));
      }
      else {
        $row
          ->setSourceProperty($profile_value['name'], [
          $profile_value['value'],
        ]);
      }
    }
  }
  return parent::prepareRow($row);
}