From 5ef2a98b5145ed2bbbccf9889c23609092c86c80 Mon Sep 17 00:00:00 2001 From: afornerot Date: Mon, 1 Feb 2021 10:58:48 +0100 Subject: [PATCH] gestion de la deconnexion ldap --- .../Command/ScribeToNinegateCommand.php | 24 ++++++++++++++----- .../CoreBundle/Service/ldapService.php | 7 +++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/ScribeToNinegateCommand.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/ScribeToNinegateCommand.php index 30ba2be9..33e2edc5 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/ScribeToNinegateCommand.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/ScribeToNinegateCommand.php @@ -45,7 +45,7 @@ class ScribeToNinegateCommand extends Command $this->host = $input->getArgument('host'); $this->port = 389; $this->pwd = $input->getArgument('pwd'); - $this->user = "cn=admin,o=gouv,c=fr"; + $this->user = "cn=reader,o=gouv,c=fr"; $ldap_basedn = $this->container->getParameter('ldap_basedn'); $ldap_username = $this->container->getParameter('ldap_username'); @@ -105,9 +105,6 @@ class ScribeToNinegateCommand extends Command $this->writelnred('PURGE DES BLOG'); $this->purge('CadolesPortalBundle:Blog'); - $this->writelnred('PURGE DES PAGES'); - $this->purge('CadolesPortalBundle:Page'); - $this->writelnred('PURGE DES PROJECT'); $this->purge('CadolesPortalBundle:Project'); @@ -126,13 +123,14 @@ class ScribeToNinegateCommand extends Command $this->writelnred('PURGE DES NIVEAU 01'); $this->purge('CadolesCoreBundle:Niveau01'); + $this->writelnred('PURGE DES PAGES'); + $this->purge('CadolesPortalBundle:Page'); + $this->writelnred('PURGE DES ICONES'); $this->purge('CadolesPortalBundle:Icon'); - $this->writeln(''); - $this->writelnred(''); $this->writelnred('== INIT DATA'); $command = $this->getApplication()->find("Core:InitData"); @@ -253,6 +251,20 @@ class ScribeToNinegateCommand extends Command } private function purge($entityname) { + // Si on purge les pages il faut d'abord purger les pages qui ne sont pas pagetemplate + if($entityname=="CadolesPortalBundle:Page") { + $qb=$this->em->createQueryBuilder(); + $entitys = $qb->select('t') + ->from($entityname,'t') + ->where($qb->expr()->isNotNull('t.page')) + ->getQuery() + ->getResult(); + foreach ($entitys as $entity) { + $this->em->remove($entity); + } + $this->em->flush(); + } + $entitys=$this->em->getRepository($entityname)->findAll(); foreach ($entitys as $entity) { $this->em->remove($entity); diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Service/ldapService.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Service/ldapService.php index a0833093..d06ae67e 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Service/ldapService.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Service/ldapService.php @@ -45,7 +45,12 @@ class ldapService } public function connect() { - $this->disconnect(); + // Si on est déjà co = on rebind pour gérer le cas d'un timeout de connection + if($this->connection){ + if(!ldap_bind($this->connection, $this->user, $this->password)){ + $this->disconnect(); + } + } if($this->connection){ return $this->connection;