function ldap_user_user_insert in Lightweight Directory Access Protocol (LDAP) 7.2
Same name and namespace in other branches
- 8.4 ldap_user/ldap_user.module \ldap_user_user_insert()
- 8.2 ldap_user/ldap_user.module \ldap_user_user_insert()
- 8.3 ldap_user/ldap_user.module \ldap_user_user_insert()
Implements hook_user_insert().
File
- ldap_user/
ldap_user.module, line 907 - Module for the LDAP User Entity.
Code
function ldap_user_user_insert(&$user_edit, $account, $category) {
global $user;
$not_associated = ldap_user_ldap_exclude($account, $user_edit);
// Check for first time user.
$new_account_request = (bool) ($user->uid == 0 && $account->access == 0 && $account->login == 0);
$already_provisioned_to_ldap = ldap_user_ldap_provision_semaphore('provision', 'get', $account->name);
$already_synched_to_ldap = ldap_user_ldap_provision_semaphore('synch', 'user_action_query', $account->name);
if ($not_associated || $already_synched_to_ldap || $already_synched_to_ldap || $new_account_request) {
return;
}
$ldap_user_conf = ldap_user_conf();
/**
* in hook_user_insert, account is already created, so never call provisionDrupalAccount(), just
* synchToDrupalAccount(), even if action is 'provision'
*/
$empty_user_edit = [];
if ($account->status && $ldap_user_conf
->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE)) {
$ldap_user_conf
->synchToDrupalAccount($account, $empty_user_edit, LDAP_USER_EVENT_CREATE_DRUPAL_USER, NULL, TRUE);
}
if ($ldap_user_conf->provisionsLdapEntriesFromDrupalUsers) {
$prov_enabled = $ldap_user_conf
->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY, LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE);
if ($prov_enabled) {
$ldap_provision_entry = $ldap_user_conf
->getProvisionRelatedLdapEntry($account);
if (!$ldap_provision_entry) {
$provision_result = $ldap_user_conf
->provisionLdapEntry($account);
if ($provision_result['status'] == 'success') {
ldap_user_ldap_provision_semaphore('provision', 'set', $account->name);
}
}
elseif ($ldap_provision_entry) {
$bool_result = $ldap_user_conf
->synchToLdapEntry($account, $user_edit);
if ($bool_result) {
ldap_user_ldap_provision_semaphore('synch', 'set', $account->name);
}
}
}
}
}