You are here

public function DomainNodeHandler::prepare in Domain Access 7.3

File

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

Class

DomainNodeHandler
Migration class for importing Drupal nodes.

Code

public function prepare($node, stdClass $row) {
  $domains = array();

  // If not set, be sure that we aren't updating an existing record.
  if (!empty($node->nid) && empty($node->domains)) {
    $nodes[$node->nid] = $node;
    domain_node_load($nodes, array());
  }

  // If set, ensure domains exist.
  if (isset($node->domains)) {
    $node->domains = (array) $node->domains;
    foreach ($node->domains as $id) {
      if ($domain = domain_load($id)) {
        $domains[$domain['domain_id']] = $domain['domain_id'];
      }
      if ($domain = domain_machine_name_load($id)) {
        $domains[$domain['domain_id']] = $domain['domain_id'];
      }
    }
  }

  // If empty, assign to the default domain. Note that domain_site can be
  // set automatically if not added by the migration.
  if (empty($domains) && ($default = domain_default_id())) {
    $domains[$default] = $default;
  }
  $node->domains = $domains;
}