You are here

public function MigrateDestinationTableCopy::import in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 plugins/destinations/table_copy.inc \MigrateDestinationTableCopy::import()

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 MigrateDestination::import

File

plugins/destinations/table_copy.inc, line 48
Copies data_row into a table using drupal_write_record()

Class

MigrateDestinationTableCopy
Destination class implementing migration into a single table.

Code

public function import(stdClass $entity, stdClass $row) {
  $migration = MigrationBase::currentMigration();
  $fields = clone $row;
  $keys = array_keys($this->keySchema);
  $values = array();
  foreach ($keys as $key) {
    $values[] = $row->{$key};
  }
  unset($fields->migrate_map_destid1);
  unset($fields->needs_update);
  $query = db_merge($this->tableName)
    ->key($keys, $values)
    ->fields((array) $fields);
  try {
    $status = $query
      ->execute();
    if ($status == MergeQuery::STATUS_INSERT) {
      $this->numCreated++;
    }
    else {
      $this->numUpdated++;
    }
    return $values;
  } catch (MigrateException $e) {
    $migration
      ->saveMessage($e
      ->getMessage(), $e
      ->getLevel());
    Migration::displayMessage($e
      ->getMessage());
  } catch (Exception $e) {
    $this
      ->handleException($e);
  }
}