You are here

public function LdapUserConf::synchToDrupalAccount in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_user/LdapUserConf.class.php \LdapUserConf::synchToDrupalAccount()

given a drupal account, query ldap and get all user fields and create user account

Parameters

array $account drupal account array with minimum of name:

array $user_edit drupal edit array in form user_save($account, $user_edit) would take,: generally empty unless overriding synchToDrupalAccount derived values

array $ldap_user as user's ldap entry. passed to avoid requerying ldap in cases where already present:

boolean $save indicating if drupal user should be saved. generally depends on where function is called from.:

Return value

result of user_save() function is $save is true, otherwise return TRUE $user_edit data returned by reference

1 call to LdapUserConf::synchToDrupalAccount()
LdapUserConf::provisionDrupalAccount in ldap_user/LdapUserConf.class.php
given a drupal account, query ldap and get all user fields and save user account (note: parameters are in odd order to match synchDrupalAccount handle)

File

ldap_user/LdapUserConf.class.php, line 766

Class

LdapUserConf

Code

public function synchToDrupalAccount($drupal_user, &$user_edit, $prov_event = LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, $ldap_user = NULL, $save = FALSE) {
  $debug = array(
    'account' => $drupal_user,
    'user_edit' => $user_edit,
    'ldap_user' => $ldap_user,
  );
  if (!$ldap_user && !isset($drupal_user->name) || !$drupal_user && $save || $ldap_user && !isset($ldap_user['sid'])) {

    // should throw watchdog error also
    return FALSE;
  }
  if (!$ldap_user && $this->drupalAcctProvisionServer) {
    $ldap_user = ldap_servers_get_user_ldap_data($drupal_user->name, $this->drupalAcctProvisionServer, 'ldap_user_prov_to_drupal');
  }
  if (!$ldap_user) {
    return FALSE;
  }
  if ($this->drupalAcctProvisionServer) {
    $ldap_server = ldap_servers_get_servers($this->drupalAcctProvisionServer, NULL, TRUE);
    $this
      ->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, array(
      $prov_event,
    ));
  }
  if ($save) {
    $account = user_load($drupal_user->uid);
    $result = user_save($account, $user_edit, 'ldap_user');
    return $result;
  }
  else {
    return TRUE;
  }
}