You are here

public function MigrateDestinationDomain::import in Domain Access 7.3

Import a single row.

Parameters

$domain: Domain 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

./domain.migrate.inc, line 78
Support for domains in core Drupal objects

Class

MigrateDestinationDomain
Migration class for importing domains into Drupal.

Code

public function import(stdClass $domain, stdClass $row) {

  // Set up optional fields.
  if (empty($domain->machine_name)) {
    $domain->machine_name = domain_machine_name($domain->subdomain);
  }
  if (!isset($domain->valid)) {
    $domain->valid = 1;
  }
  if (empty($domain->scheme)) {
    $domain->scheme = 'http';
  }
  if (!isset($domain->weight)) {
    $domain->weight = count(domain_domains()) + 1;
  }
  if (!isset($domain->is_default)) {
    $domain->is_default = 0;
  }

  // Invoke migration prepare handlers.
  $this
    ->prepare($domain, $row);

  // Domains are handled as arrays, so clone the object to an array.
  $domain = clone $domain;
  $domain = (array) $domain;

  // Check to see if this is a new domain.
  $update = FALSE;
  if ($data = domain_machine_name_load($domain['machine_name'])) {
    $domain['domain_id'] = $data['domain_id'];
    $update = TRUE;
  }

  // domain_save() provides no return callback, so we can't really test this
  // without running a domain_load() check.
  migrate_instrument_start('domain_save');
  domain_save($domain);
  migrate_instrument_stop('domain_save');

  // Return the new id or FALSE on failure.
  if ($data = domain_machine_name_load($domain['machine_name'])) {

    // Increment the count if the save succeeded.
    if ($update) {
      $this->numUpdated++;
    }
    else {
      $this->numCreated++;
    }

    // Return the primary key to the mapping table.
    $return = array(
      $data['machine_name'],
    );
  }
  else {
    $return = FALSE;
  }

  // Invoke migration complete handlers.
  $domain = (object) $data;
  $this
    ->complete($domain, $row);
  return $return;
}