You are here

public function BiblioMigrateDestinationFieldCollection::import in Bibliography Module 7.3

Import a single term.

Parameters

$collection: Collection object to build. Pre-filled 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 (item_id only in this case) of the collection that was saved if successful. FALSE on failure.

Overrides MigrateDestination::import

File

includes/migrate/plugins/destinations/biblio_field_collection.inc, line 64

Class

BiblioMigrateDestinationFieldCollection
Destination class implementing migration into field_collection.

Code

public function import(stdClass $collection, stdClass $row) {
  $entity = entity_create('field_collection_item', array(
    'field_name' => $this->bundle,
  ));
  $updating = FALSE;

  // The host entity cannot be reset - we only set it on initial insert
  $host_entity = entity_load_single($this->hostEntityType, $collection->host_entity_id);
  $entity
    ->setHostEntity($this->hostEntityType, $host_entity);
  unset($collection->host_entity_id);
  foreach ((array) $collection as $field => $value) {
    $entity->{$field} = $value;
  }
  $this
    ->prepare($entity, $row);
  migrate_instrument_start('field_collection_save');
  $status = $entity
    ->save();
  migrate_instrument_stop('field_collection_save');

  // TODO: status doesn't return correct value, so just check the
  // entity was created.
  if ($entity->item_id) {
    $this
      ->complete($entity, $row);
    if ($updating) {
      $this->numUpdated++;
    }
    else {
      $this->numCreated++;
    }
    return array(
      $entity->item_id,
    );
  }
  else {
    return FALSE;
  }
}