LDAP : sync script now updates or create user
This commit is contained in:
parent
04e1be4afd
commit
0358ef4918
@ -178,6 +178,8 @@ if ($result >= 0)
|
|||||||
foreach ($ldaprecords as $key => $ldapuser)
|
foreach ($ldaprecords as $key => $ldapuser)
|
||||||
{
|
{
|
||||||
$fuser = new User($db);
|
$fuser = new User($db);
|
||||||
|
|
||||||
|
$fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné
|
||||||
|
|
||||||
// Propriete membre
|
// Propriete membre
|
||||||
$fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
|
$fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
|
||||||
@ -210,6 +212,7 @@ if ($result >= 0)
|
|||||||
$fuser->fk_member=0;
|
$fuser->fk_member=0;
|
||||||
|
|
||||||
$fuser->statut=1;
|
$fuser->statut=1;
|
||||||
|
// TODO : revoir la gestion du status
|
||||||
/*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
|
/*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
|
||||||
{
|
{
|
||||||
$fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
$fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
|
||||||
@ -219,25 +222,44 @@ if ($result >= 0)
|
|||||||
//if ($fuser->statut > 1) $fuser->statut=1;
|
//if ($fuser->statut > 1) $fuser->statut=1;
|
||||||
|
|
||||||
//print_r($ldapuser);
|
//print_r($ldapuser);
|
||||||
|
|
||||||
// Group of user
|
if($fuser->id > 0) { // User update
|
||||||
// We should use here $groupid
|
print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
|
||||||
|
$res=$fuser->update($user);
|
||||||
// Creation member
|
|
||||||
print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
|
if ($res < 0)
|
||||||
$fuser_id=$fuser->create($user);
|
{
|
||||||
if ($fuser_id > 0)
|
$error++;
|
||||||
{
|
print ' --> '.$res.' '.$fuser->error;
|
||||||
print ' --> Created member id='.$fuser_id.' login='.$fuser->login;
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
print ' --> Updated user id='.$fuser->id.' login='.$fuser->login;
|
||||||
$error++;
|
}
|
||||||
print ' --> '.$fuser_id.' '.$fuser->error;
|
} else { // User creation
|
||||||
|
print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
|
||||||
|
$res=$fuser->create($user);
|
||||||
|
|
||||||
|
if ($res > 0)
|
||||||
|
{
|
||||||
|
print ' --> Created user id='.$fuser->id.' login='.$fuser->login;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
print ' --> '.$res.' '.$fuser->error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
//print_r($fuser);
|
//print_r($fuser);
|
||||||
|
|
||||||
|
// Gestion des groupes
|
||||||
|
// TODO : revoir la gestion des groupes (ou script de sync groupes)
|
||||||
|
/*if(!$error) {
|
||||||
|
foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) {
|
||||||
|
$groupdn;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error || $forcecommit)
|
if (! $error || $forcecommit)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user