svg
This commit is contained in:
parent
75d979fa09
commit
dc9f198cce
|
@ -93,6 +93,7 @@ class SynchroCommand extends Command
|
|||
$ldap_usersadmin = $this->container->getParameter('ldap_usersadmin');
|
||||
$fieldstoread = array($ldap_username,$ldap_firstname,$ldap_lastname,$ldap_email);
|
||||
$ldapusers = array();
|
||||
$ldapmails = array();
|
||||
|
||||
if($ldap_template=="scribe") {
|
||||
$this->writeln('');
|
||||
|
@ -138,6 +139,12 @@ class SynchroCommand extends Command
|
|||
$this->writeln('');
|
||||
$this->writeln('== USERS ============================================');
|
||||
|
||||
// On stocke tout les email déjà existant
|
||||
$users=$this->em->getRepository('CadolesCoreBundle:User')->findAll();
|
||||
foreach($users as $user) {
|
||||
array_push($ldapmails,$user->getEmail());
|
||||
}
|
||||
|
||||
// On parcours les niveaux 01 pour connaitre les filtres ldap associé
|
||||
$datas=$this->em->createQueryBuilder()->select('table')->from('CadolesCoreBundle:Niveau01','table')->where('table.ldapfilter IS NOT NULL')->getQuery()->getResult();
|
||||
foreach($datas as $data) {
|
||||
|
@ -146,27 +153,53 @@ class SynchroCommand extends Command
|
|||
|
||||
// Pour chaque utilisateur ldap
|
||||
foreach($results as $result) {
|
||||
// Formatage du résultat
|
||||
if(is_array($result[$ldap_username])) {
|
||||
$result[$ldap_username]=$result[$ldap_username][0];
|
||||
}
|
||||
|
||||
$result[$ldap_username]=utf8_encode($result[$ldap_username]);
|
||||
if(!isset($result[$ldap_lastname])) $result[$ldap_lastname] = "";
|
||||
if(!isset($result[$ldap_firstname])) $result[$ldap_firstname] = "";
|
||||
$result[$ldap_email]=strtolower($result[$ldap_email]);
|
||||
$result[$ldap_email]=utf8_encode($result[$ldap_email]);
|
||||
|
||||
// On sauvegarde ce user
|
||||
if(in_array($result[$ldap_username],$ldapusers)) {
|
||||
$this->writelnred(" - Création dans Bundle impossible >> ".$result[$ldap_username]." deux users avec le meme uid");
|
||||
continue;
|
||||
}
|
||||
array_push($ldapusers,$result[$ldap_username]);
|
||||
|
||||
// Création ou Modification du user
|
||||
$user=$this->em->getRepository('CadolesCoreBundle:User')->findBy(array('username' => $result[$ldap_username]));
|
||||
$user=$this->em->getRepository('CadolesCoreBundle:User')->findOneBy(array('username' => $result[$ldap_username]));
|
||||
if(!$user) {
|
||||
if(empty($result[$ldap_email]))
|
||||
$this->writelnred(" - Création dans Bundle impossible >> ".$result[$ldap_username]." sans email");
|
||||
else {
|
||||
if(in_array($result[$ldap_email],$ldapmails))
|
||||
$this->writelnred(" - Création dans Bundle impossible >> ".$result[$ldap_username]." un autre utilisateur a déjà ce mail = ".$result[$ldap_email]);
|
||||
else {
|
||||
array_push($ldapmails,$result[$ldap_email]);
|
||||
$this->writeln(" - Création dans Bundle >> ".$result[$ldap_username]);
|
||||
if(!$simulate) $this->addUser($data,$result[$ldap_username],$result[$ldap_firstname],$result[$ldap_lastname],$result[$ldap_email],$ldap_usersadmin);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$toadmin=false;
|
||||
if(in_array($result[$ldap_username],$ldap_usersadmin)&&$user->getRole()!="ROLE_ADMIN")
|
||||
if(in_array($result[$ldap_username],$ldap_usersadmin)&&!in_array("ROLE_ADMIN",$user->getRoles()))
|
||||
$toadmin=true;
|
||||
|
||||
if($user->getLastname()!=$result[$ldap_username]||$user->getFirstname()!=$result[$ldap_firstname]||$user->getEmail()!=$result[$ldap_email]||$toadmin) {
|
||||
if($user->getLastname()!=$result[$ldap_lastname]||$user->getFirstname()!=$result[$ldap_firstname]||$user->getEmail()!=$result[$ldap_email]||$toadmin) {
|
||||
$usermail=$this->em->getRepository('CadolesCoreBundle:User')->findOneBy(array('email' => $result[$ldap_email]));
|
||||
if($usermail!=$user) {
|
||||
$this->writelnred(" - Modification dans Bundle impossible >> ".$result[$ldap_username]." un autre utilisateur a déjà ce mail = ".$result[$ldap_email]);
|
||||
}
|
||||
else {
|
||||
$this->writeln(" - Modification dans Bundle >> ".$result[$ldap_username]);
|
||||
if(!$simulate) $this->modUser($user[0],$result[$ldap_username],$result[$ldap_firstname],$result[$ldap_lastname],$result[$ldap_email],$ldap_usersadmin);
|
||||
if(!$simulate) $this->modUser($user,$result[$ldap_username],$result[$ldap_firstname],$result[$ldap_lastname],$result[$ldap_email],$ldap_usersadmin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue