You are here

public function MigrateDestinationVotingapi::import in Migrate Extras 7.2

Same name and namespace in other branches
  1. 6.2 votingapi.inc \MigrateDestinationVotingapi::import()

Import a single vote.

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

./votingapi.inc, line 63
VotingAPI module integration

Class

MigrateDestinationVotingapi
Destination class for the votingapi_vote table.

Code

public function import(stdClass $entity, stdClass $row) {
  $this
    ->prepare($entity, $row);

  // Votes have to be assigned to an entity.
  if (empty($entity->entity_id)) {
    watchdog('VotingAPI Import', 'Skipped import due to empty entity_id for vote import: @serial', array(
      '@serial' => json_encode($row),
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  if (isset($entity->timestamp)) {
    $entity->timestamp = Migration::timestamp($entity->timestamp);
  }

  // Just converting $entity to an array doesn't work...
  $vote = array();
  $vote['entity_type'] = $entity->entity_type;
  $vote['entity_id'] = $entity->entity_id;
  $vote['value_type'] = $entity->value_type;
  $vote['value'] = $entity->value;
  $vote['uid'] = $entity->uid;
  $vote['tag'] = $entity->tag;
  $vote['timestamp'] = $entity->timestamp;
  $vote['vote_source'] = $entity->vote_source;
  votingapi_add_votes($vote);
  if (isset($vote[0]['vote_id'])) {
    $entity->vote_id = $vote[0]['vote_id'];
    $this
      ->complete($entity, $row);
    $this->importedIds[$entity->entity_type][] = $entity->entity_id;
    return array(
      $entity->vote_id,
    );
  }
  else {
    return FALSE;
  }
}