You are here

public function DomainUserHandler::prepare in Domain Access 7.3

File

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

Class

DomainUserHandler
Migration class for supporting Drupal user accounts.

Code

public function prepare($user, stdClass $row) {

  // If set, ensure domains exist.
  $domains = array();
  if (isset($user->uid)) {
    domain_user_set($user);
  }
  if (isset($user->domain_user)) {
    $user->domain_user = (array) $user->domain_user;
    foreach ($user->domain_user 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.
  if (empty($domains) && ($default = domain_default_id())) {
    $domains[$default] = $default;
  }
  $user->domain_user = $domains;
}