You are here

public function MigrateDestinationRole::import in Migrate 7.2

Import a single row.

Parameters

$entity: Object object to build. Prefilled with any fields mapped in the Migration.

$row: Raw source data object - passed through to prepare/complete handlers.

Return value

array Array of key fields of the object that was saved if successful. FALSE on failure.

Overrides MigrateDestinationTable::import

File

plugins/destinations/user.inc, line 336
Support for user destinations.

Class

MigrateDestinationRole

Code

public function import(stdClass $entity, stdClass $row) {
  $migration = Migration::currentMigration();
  $updating = FALSE;

  // Updating previously-migrated content?
  if (isset($row->migrate_map_destid1)) {
    $updating = TRUE;
    if (isset($entity->rid)) {
      if ($entity->rid != $row->migrate_map_destid1) {
        throw new MigrateException(t("Incoming id !id and map destination id !destid don't match", array(
          '!id' => $entity->rid,
          '!destid' => $row->migrate_map_destid1,
        )));
      }
    }
    else {
      $entity->rid = $row->migrate_map_destid1;
    }
  }
  if ($migration
    ->getSystemOfRecord() == Migration::DESTINATION) {
    $updating = TRUE;
    if (!isset($entity->rid)) {
      throw new MigrateException(t('System-of-record is DESTINATION, but no destination id provided'));
    }
    $old_entity = user_role_load($entity->rid);
    foreach ($entity as $field => $value) {
      $old_entity->{$field} = $entity->{$field};
    }
    $entity = $old_entity;
  }
  $this
    ->prepare($entity, $row);
  user_role_save($entity);
  $this
    ->complete($entity, $row);
  if (!empty($entity->rid)) {
    $id = array(
      $entity->rid,
    );
    if ($updating) {
      $this->numUpdated++;
    }
    else {
      $this->numCreated++;
    }
  }
  else {
    $id = FALSE;
  }
  return $id;
}