You are here

function pmperson_migrate_create_users_if_required in Drupal PM (Project Management) 8

Same name and namespace in other branches
  1. 7.3 pmperson/includes/pmperson.migrate.inc \pmperson_migrate_create_users_if_required()
  2. 7.2 pmperson/includes/pmperson.migrate.inc \pmperson_migrate_create_users_if_required()

Creates Drupal User and associate it with pmperson node.

1 call to pmperson_migrate_create_users_if_required()
pmperson_migrate in pmperson/includes/pmperson.migrate.inc
Helper function for migrating between PM Person nodes and Drupal users.

File

pmperson/includes/pmperson.migrate.inc, line 380
Migration functions for the PM Person module.

Code

function pmperson_migrate_create_users_if_required(&$sandbox) {
  $unmapped_results = db_select('pmperson', 'pmp')
    ->fields('pmp')
    ->condition('pmp.user_uid', '0')
    ->condition('nid', $sandbox['pmperson_current_nid_of_user_being_created'], '>')
    ->range(0, PMPERSON_MIGRATE_MAX_JOB_PER_BATCH)
    ->execute();
  $count = 0;
  foreach ($unmapped_results as $record) {
    $count++;
    $account = NULL;
    if ($account = user_load_by_mail($record->email)) {

      // If the email is already associated with another account, create new.
      // and change the current email.
      if (_pmperson_migrate_get_pmperson_from_uid($account->uid)) {
        $account = _pmperson_migrate_create_user($record);
        db_update('pmperson')
          ->fields(array(
          'email' => $account->mail,
        ))
          ->condition('user_uid', $account->uid)
          ->execute();
      }
    }
    else {
      $account = _pmperson_migrate_create_user($record);
    }
    _pmperson_migrate_associate_user_with_pmperson($record, $account);
  }
  return empty($count);
}