You are here

public function MigrationDataImport::prepare in CRM Core 7

Prepare entity before saving.

File

modules/crm_core_data_import/includes/controllers/MigrationDataImport.inc, line 188
Handler for migration process.

Class

MigrationDataImport
@file Handler for migration process.

Code

public function prepare($entity, $row) {

  // Run match engine for crm_core_contact.
  if ($this
    ->getEntityType() == 'crm_core_contact') {

    // Set temporary contact_id.
    $entity->contact_id = 0;
    $matches = array();
    $values = array(
      'contact' => &$entity,
      'matches' => &$matches,
    );
    module_invoke_all('crm_core_contact_match', $values);

    // If contact already exist, replace contact_id to match.
    if (!empty($matches)) {
      $entity->contact_id = reset($matches);

      // Set current entity as original to update fields.
      $entity->original = $entity;
      entity_save('crm_core_contact', $entity);
    }
  }
  drupal_alter('crm_core_data_import_prepare_entity', $entity, $row, $this
    ->generateMachineName());
}