You are here

public function MigrateDestinationFlagSimple::import in Migrate Extras 7.2

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

Import a single flag_content.

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

./flag.inc, line 56
Flag module integration

Class

MigrateDestinationFlagSimple
Destination class implementing when you want just an insert into flag_content table.

Code

public function import(stdClass $entity, stdClass $row) {
  if (isset($entity->timestamp)) {
    $entity->timestamp = Migration::timestamp($entity->timestamp);
  }
  $entity->fid = $this->fid;
  if (!empty($entity->fcid)) {
    $return = drupal_write_record('flag_content', $entity, 'fcid');
  }
  else {
    $return = drupal_write_record('flag_content', $entity);
  }
  if ($return) {

    // Update the flag_counts table.
    $count = db_select('flag_content')
      ->fields('flag_content')
      ->condition('fid', $this->fid)
      ->condition('content_type', $entity->content_type)
      ->condition('content_id', $entity->content_id)
      ->countQuery()
      ->execute()
      ->fetchField();
    db_merge('flag_counts')
      ->key(array(
      'fid' => $this->fid,
      'content_id' => $entity->content_id,
    ))
      ->fields(array(
      'content_type' => $entity->content_type,
      'count' => $count,
      'last_updated' => REQUEST_TIME,
    ))
      ->execute();
    return array(
      $entity->fcid,
    );
  }
}