fix(continuous-integration): correction php-cs-fixer
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
This commit is contained in:
@ -1,16 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use App\Entity\Tallyday as Tallyday;
|
||||
|
||||
|
||||
class CleanRegistrationCommand extends Command
|
||||
{
|
||||
@ -21,7 +18,7 @@ class CleanRegistrationCommand extends Command
|
||||
private $rootlog;
|
||||
private $byexec;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
public function __construct(ContainerInterface $container, EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
@ -39,41 +36,49 @@ class CleanRegistrationCommand extends Command
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir().'/';
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:CleanRegistration');
|
||||
$this->writelnred('== app:CleanRegistration');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$now=new \DateTime('now');
|
||||
$now = new \DateTime('now');
|
||||
$datas = $this->em
|
||||
->createQueryBuilder()
|
||||
->select('table')
|
||||
->from('App\Entity\Registration','table')
|
||||
->from('App\Entity\Registration', 'table')
|
||||
->where('table.keyexpire<:now')
|
||||
->setParameter("now",$now->format("Y-m-d H:i:s"))
|
||||
->setParameter('now', $now->format('Y-m-d H:i:s'))
|
||||
->getQuery()
|
||||
->getResult();
|
||||
foreach($datas as $data) {
|
||||
$this->writeln('Inscription supprimée = '.$data->getkeyexpire()->format("Y-m-d H:i:s")." >> ".$data->getUsername());
|
||||
foreach ($datas as $data) {
|
||||
$this->writeln('Inscription supprimée = '.$data->getkeyexpire()->format('Y-m-d H:i:s').' >> '.$data->getUsername());
|
||||
$this->em->remove($data);
|
||||
$this->em->flush();
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
private function writelnred($string)
|
||||
{
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
if($this->byexec) $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
if ($this->byexec) {
|
||||
$this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
}
|
||||
}
|
||||
private function writeln($string) {
|
||||
|
||||
private function writeln($string)
|
||||
{
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
if($this->byexec) $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
}
|
||||
if ($this->byexec) {
|
||||
$this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,28 +2,26 @@
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Cron;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Command\LockableTrait;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Command\LockableTrait;
|
||||
|
||||
use App\Entity\Cron;
|
||||
|
||||
class CronCommand extends Command
|
||||
{
|
||||
use LockableTrait;
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
use LockableTrait;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
public function __construct(ContainerInterface $container, EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
@ -40,93 +38,99 @@ class CronCommand extends Command
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir().'/';
|
||||
|
||||
if (!$this->lock()) {
|
||||
$this->output->writeln("CRON LOCK");
|
||||
$this->output->writeln('CRON LOCK');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$crons = $this->em->getRepository('App\Entity\Cron')->toexec();
|
||||
|
||||
if($crons) {
|
||||
$now=new \DateTime();
|
||||
if ($crons) {
|
||||
$now = new \DateTime();
|
||||
$this->writelnred('');
|
||||
$this->writelnred('');
|
||||
$this->writelnred('');
|
||||
$this->writelnred('');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
$this->writelnred('== CRON ==================================================================================================');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
$this->writeln ('Date = '.$now->format('Y-m-d H:i:s'));
|
||||
$this->writeln ('Application = '.$this->container->getParameter("appName"));
|
||||
$this->writelnred('==========================================================================================================');
|
||||
$this->writeln('Date = '.$now->format('Y-m-d H:i:s'));
|
||||
$this->writeln('Application = '.$this->container->getParameter('appName'));
|
||||
}
|
||||
|
||||
foreach($crons as $cron) {
|
||||
|
||||
foreach ($crons as $cron) {
|
||||
// Id du cron
|
||||
$idcron = $cron->getId();
|
||||
|
||||
// Flag d'execution en cours
|
||||
$now=new \DateTime();
|
||||
$now = new \DateTime();
|
||||
$cron->setStartexecdate($now);
|
||||
//$cron->setStatut(1);
|
||||
// $cron->setStatut(1);
|
||||
$this->em->flush();
|
||||
|
||||
// Récupération de la commande
|
||||
$command = $this->getApplication()->find($cron->getCommand());
|
||||
|
||||
|
||||
// Réccuépration des parametres
|
||||
$jsonparameter=json_decode($cron->getJsonargument(),true);
|
||||
$jsonparameter = json_decode($cron->getJsonargument(), true);
|
||||
|
||||
// Formater la chaine de parametre
|
||||
if(!$jsonparameter) $jsonparameter=[];
|
||||
if (!$jsonparameter) {
|
||||
$jsonparameter = [];
|
||||
}
|
||||
$parameter = new ArrayInput($jsonparameter);
|
||||
|
||||
// Executer la commande
|
||||
try{
|
||||
try {
|
||||
$returnCode = $command->run($parameter, $output);
|
||||
} catch (\Exception $e) {
|
||||
$this->writelnred('JOB EN ERREUR .'.$e->getMessage());
|
||||
$returnCode = Command::FAILURE;
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->writelnred("JOB EN ERREUR .".$e->getMessage());
|
||||
$returnCode=Command::FAILURE;
|
||||
}
|
||||
|
||||
// Flag de fin d'execution
|
||||
$now=new \DateTime();
|
||||
$now = new \DateTime();
|
||||
$cron->setEndexecdate($now);
|
||||
|
||||
// Si interval par heure
|
||||
if(fmod($cron->getRepeatinterval(),3600)==0)
|
||||
$next=clone $cron->getNextexecdate();
|
||||
else
|
||||
$next=new \DateTime();
|
||||
if (0 == fmod($cron->getRepeatinterval(), 3600)) {
|
||||
$next = clone $cron->getNextexecdate();
|
||||
} else {
|
||||
$next = new \DateTime();
|
||||
}
|
||||
|
||||
$next->add(new \DateInterval('PT'.$cron->getRepeatinterval().'S'));
|
||||
$cron->setNextexecdate($next);
|
||||
|
||||
// Statut OK/KO
|
||||
$cron->setStatut(($returnCode==Command::FAILURE?0:1));
|
||||
$cron->setStatut(Command::FAILURE == $returnCode ? 0 : 1);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
if($crons) {
|
||||
$this->writelnred("==");
|
||||
$this->writelnred("FIN CRON");
|
||||
$this->writelnred("==");
|
||||
$this->writelnred("");
|
||||
if ($crons) {
|
||||
$this->writelnred('==');
|
||||
$this->writelnred('FIN CRON');
|
||||
$this->writelnred('==');
|
||||
$this->writelnred('');
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
private function writelnred($string)
|
||||
{
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
|
||||
private function writeln($string)
|
||||
{
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Config;
|
||||
use App\Entity\Cron;
|
||||
use App\Entity\Group;
|
||||
use App\Entity\Niveau01;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
|
||||
use App\Entity\Group;
|
||||
use App\Entity\Niveau01;
|
||||
use App\Entity\User;
|
||||
use App\Entity\Config;
|
||||
use App\Entity\Cron;
|
||||
|
||||
class InitCommand extends Command
|
||||
{
|
||||
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
@ -29,14 +27,13 @@ class InitCommand extends Command
|
||||
private $rootlog;
|
||||
private $appname;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
public function __construct(ContainerInterface $container, EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@ -48,455 +45,451 @@ class InitCommand extends Command
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$this->appname = $this->container->getParameter('appName');
|
||||
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir().'/';
|
||||
$this->appname = $this->container->getParameter('appName');
|
||||
|
||||
$this->writeln('APP = Default Data');
|
||||
|
||||
// On s'assure que le groupe tout le monde existe
|
||||
$metadata = $this->em->getClassMetaData('App\Entity\Group');
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$group=$this->em->getRepository('App\Entity\Group')->findOneBy(['id'=>'-1']);
|
||||
if(!$group) {
|
||||
$group=new Group();
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$group = $this->em->getRepository('App\Entity\Group')->findOneBy(['id' => '-1']);
|
||||
if (!$group) {
|
||||
$group = new Group();
|
||||
$group->setId(-1);
|
||||
$group->setLabel("Tout le monde");
|
||||
$group->setLabel('Tout le monde');
|
||||
$group->setIsopen(false);
|
||||
$group->setIsworkgroup(false);
|
||||
$group->setApikey(Uuid::uuid4());
|
||||
$this->em->persist($group);
|
||||
$this->em->flush();
|
||||
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
// On s'assure qu'il exite un niveau01
|
||||
$metadata = $this->em->getClassMetaData('App\Entity\Niveau01');
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$niveau01=$this->em->getRepository('App\Entity\Niveau01')->findOneBy(['id'=>'-1']);
|
||||
if(!$niveau01) {
|
||||
$niveau01=new Niveau01();
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$niveau01 = $this->em->getRepository('App\Entity\Niveau01')->findOneBy(['id' => '-1']);
|
||||
if (!$niveau01) {
|
||||
$niveau01 = new Niveau01();
|
||||
$niveau01->setId(-1);
|
||||
$niveau01->setLabel($this->appname);
|
||||
$niveau01->setApikey(Uuid::uuid4());
|
||||
$this->em->persist($niveau01);
|
||||
$this->em->flush();
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
// On s'assure que le user admin existe
|
||||
$metadata = $this->em->getClassMetaData('App\Entity\User');
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$user=$this->em->getRepository('App\Entity\User')->findOneBy(['id'=>'-1']);
|
||||
if(!$user) {
|
||||
$user=new User();
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$user = $this->em->getRepository('App\Entity\User')->findOneBy(['id' => '-1']);
|
||||
if (!$user) {
|
||||
$user = new User();
|
||||
$user->setId(-1);
|
||||
$user->setUsername("admin");
|
||||
$user->setFirstname("admin");
|
||||
$user->setUsername('admin');
|
||||
$user->setFirstname('admin');
|
||||
$user->setLastname($this->appname);
|
||||
$user->setPassword($this->container->getParameter('appSecret'));
|
||||
$user->setEmail($this->container->getParameter('appMailnoreply'));
|
||||
$user->setApikey(Uuid::uuid4());
|
||||
$user->setAvatar("admin.jpg");
|
||||
$user->setAvatar('admin.jpg');
|
||||
$user->setIsVisible(true);
|
||||
$user->setNiveau01($niveau01);
|
||||
|
||||
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
// On s'assure que les appAdmins sont bien admin
|
||||
foreach($this->container->getParameter('appAdmins') as $admin) {
|
||||
$user=$this->em->getRepository('App\Entity\User')->findOneBy(['username'=>$admin]);
|
||||
if($user&&!$user->hasRole("ROLE_ADMIN")) {
|
||||
$user->setRole("ROLE_ADMIN");
|
||||
foreach ($this->container->getParameter('appAdmins') as $admin) {
|
||||
$user = $this->em->getRepository('App\Entity\User')->findOneBy(['username' => $admin]);
|
||||
if ($user && !$user->hasRole('ROLE_ADMIN')) {
|
||||
$user->setRole('ROLE_ADMIN');
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// colorbgbody = Couleur des fonds de page
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"site", // category
|
||||
"appname", // id
|
||||
"Titre de votre site", // title
|
||||
"", // value
|
||||
'site', // category
|
||||
'appname', // id
|
||||
'Titre de votre site', // title
|
||||
'', // value
|
||||
$this->appname, // default
|
||||
"string", // type,
|
||||
'string', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Titre de votre site"
|
||||
'', // grouped
|
||||
'Titre de votre site'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"site", // category
|
||||
"appsubname", // id
|
||||
"Sous-titre de votre site", // title
|
||||
"", // value
|
||||
"", // default
|
||||
"string", // type,
|
||||
'site', // category
|
||||
'appsubname', // id
|
||||
'Sous-titre de votre site', // title
|
||||
'', // value
|
||||
'', // default
|
||||
'string', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Sous-titre de votre site"
|
||||
'', // grouped
|
||||
'Sous-titre de votre site'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
3, // order
|
||||
"site", // category
|
||||
"appdescription", // id
|
||||
"Description de votre site", // title
|
||||
"", // value
|
||||
"", // default
|
||||
"editor", // type,
|
||||
'site', // category
|
||||
'appdescription', // id
|
||||
'Description de votre site', // title
|
||||
'', // value
|
||||
'', // default
|
||||
'editor', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Description de votre site"
|
||||
'', // grouped
|
||||
'Description de votre site'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
100, // order
|
||||
"site", // category
|
||||
"fgforceconnect", // id
|
||||
"Forcer la connexion", // title
|
||||
"", // value
|
||||
"0", // default
|
||||
"boolean", // type,
|
||||
'site', // category
|
||||
'fgforceconnect', // id
|
||||
'Forcer la connexion', // title
|
||||
'', // value
|
||||
'0', // default
|
||||
'boolean', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"Forcer la connexion afin de rendre votre site privé"
|
||||
'', // grouped
|
||||
'Forcer la connexion afin de rendre votre site privé'
|
||||
);
|
||||
|
||||
|
||||
$this->insertConfig(
|
||||
200, // order
|
||||
"site", // category
|
||||
"permgroup", // id
|
||||
"Rôle créateur de groupe de travail", // title
|
||||
"", // value
|
||||
"ROLE_MASTER", // default
|
||||
"role", // type,
|
||||
'site', // category
|
||||
'permgroup', // id
|
||||
'Rôle créateur de groupe de travail', // title
|
||||
'', // value
|
||||
'ROLE_MASTER', // default
|
||||
'role', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"Détermine quel rôle aura la permission de créer des groupes de travail"
|
||||
'', // grouped
|
||||
'Détermine quel rôle aura la permission de créer des groupes de travail'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
201, // order
|
||||
"site", // category
|
||||
"permannu", // id
|
||||
'site', // category
|
||||
'permannu', // id
|
||||
"Rôle accédant à l'annuaire", // title
|
||||
"", // value
|
||||
"ROLE_USER", // default
|
||||
"role", // type,
|
||||
'', // value
|
||||
'ROLE_USER', // default
|
||||
'role', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
'', // grouped
|
||||
"Détermine quel rôle aura la permission de voir l'annuaire"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
202, // order
|
||||
"site", // category
|
||||
"scopeannu", // id
|
||||
'site', // category
|
||||
'scopeannu', // id
|
||||
"Scope de l'annuaire", // title
|
||||
"", // value
|
||||
"ALL", // default
|
||||
"scopeannu", // type,
|
||||
'', // value
|
||||
'ALL', // default
|
||||
'scopeannu', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
'', // grouped
|
||||
"Détermine le scope des utilisateurs visibles dans l'annuaire par d'autres utilisateurs"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
500, // order
|
||||
"site", // category
|
||||
"apptheme", // id
|
||||
"Thème de votre site", // title
|
||||
"", // value
|
||||
"", // default
|
||||
"string", // type,
|
||||
'site', // category
|
||||
'apptheme', // id
|
||||
'Thème de votre site', // title
|
||||
'', // value
|
||||
'', // default
|
||||
'string', // type,
|
||||
false, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Thème de votre site"
|
||||
'', // grouped
|
||||
'Thème de votre site'
|
||||
);
|
||||
|
||||
|
||||
// colorbgbody = Couleur des fonds de page
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"colorbgbody", // category
|
||||
"colorbgbodydark", // id
|
||||
"Couleur de fond fonçée", // title
|
||||
"", // value
|
||||
"#2e3131", // default
|
||||
"color", // type,
|
||||
'colorbgbody', // category
|
||||
'colorbgbodydark', // id
|
||||
'Couleur de fond fonçée', // title
|
||||
'', // value
|
||||
'#2e3131', // default
|
||||
'color', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
'', // grouped
|
||||
"La couleur de fond quand le site a besoin d'avoir une couleur de fond foncée"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"colorbgbody", // category
|
||||
"colorbgbodylight", // id
|
||||
"Couleur de fond claire", // title
|
||||
"", // value
|
||||
"#ffffff", // default
|
||||
"color", // type,
|
||||
'colorbgbody', // category
|
||||
'colorbgbodylight', // id
|
||||
'Couleur de fond claire', // title
|
||||
'', // value
|
||||
'#ffffff', // default
|
||||
'color', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
'', // grouped
|
||||
"La couleur de fond quand le site a besoin d'avoir une couleur de fond claire"
|
||||
);
|
||||
|
||||
// colorfttitle = Couleur des fontes titre
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"colorfttitle", // category
|
||||
"colorfttitledark", // id
|
||||
"Couleur des titres sur fond fonçé", // title
|
||||
"", // value
|
||||
"#ffffff", // default
|
||||
"color", // type,
|
||||
'colorfttitle', // category
|
||||
'colorfttitledark', // id
|
||||
'Couleur des titres sur fond fonçé', // title
|
||||
'', // value
|
||||
'#ffffff', // default
|
||||
'color', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"La couleur des titres sur fond fonçé"
|
||||
'', // grouped
|
||||
'La couleur des titres sur fond fonçé'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"colorfttitle", // category
|
||||
"colorfttitlelight", // id
|
||||
"Couleur des titres sur fond claire", // title
|
||||
"", // value
|
||||
"#2e3131", // default
|
||||
"color", // type,
|
||||
'colorfttitle', // category
|
||||
'colorfttitlelight', // id
|
||||
'Couleur des titres sur fond claire', // title
|
||||
'', // value
|
||||
'#2e3131', // default
|
||||
'color', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"La couleur des titres sur fond claire"
|
||||
'', // grouped
|
||||
'La couleur des titres sur fond claire'
|
||||
);
|
||||
|
||||
|
||||
// colorftbody = Couleur des fontes titre
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"colorftbody", // category
|
||||
"colorftbodydark", // id
|
||||
"Couleur de la police sur fond fonçé", // title
|
||||
"", // value
|
||||
"#ffffff", // default
|
||||
"color", // type,
|
||||
'colorftbody', // category
|
||||
'colorftbodydark', // id
|
||||
'Couleur de la police sur fond fonçé', // title
|
||||
'', // value
|
||||
'#ffffff', // default
|
||||
'color', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"La couleur de la police sur fond fonçé"
|
||||
'', // grouped
|
||||
'La couleur de la police sur fond fonçé'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"colorftbody", // category
|
||||
"colorftbodylight", // id
|
||||
"Couleur de la police sur fond claire", // title
|
||||
"", // value
|
||||
"#343a40", // default
|
||||
"color", // type,
|
||||
'colorftbody', // category
|
||||
'colorftbodylight', // id
|
||||
'Couleur de la police sur fond claire', // title
|
||||
'', // value
|
||||
'#343a40', // default
|
||||
'color', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"La couleur de la police sur fond claire"
|
||||
'', // grouped
|
||||
'La couleur de la police sur fond claire'
|
||||
);
|
||||
|
||||
// font = nom des polices
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"font", // category
|
||||
"fonttitle", // id
|
||||
"Police pour les titres", // title
|
||||
"", // value
|
||||
"Theboldfont", // default
|
||||
"font", // type,
|
||||
'font', // category
|
||||
'fonttitle', // id
|
||||
'Police pour les titres', // title
|
||||
'', // value
|
||||
'Theboldfont', // default
|
||||
'font', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"La couleur de la police de votre site"
|
||||
);
|
||||
'', // grouped
|
||||
'La couleur de la police de votre site'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"font", // category
|
||||
"fontbody", // id
|
||||
"Police principale", // title
|
||||
"", // value
|
||||
"Roboto-Regular", // default
|
||||
"font", // type,
|
||||
'font', // category
|
||||
'fontbody', // id
|
||||
'Police principale', // title
|
||||
'', // value
|
||||
'Roboto-Regular', // default
|
||||
'font', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Nom de la police principale"
|
||||
'', // grouped
|
||||
'Nom de la police principale'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
3, // order
|
||||
"font", // category
|
||||
"fontsizeh1", // id
|
||||
"Taille des titres h1", // title
|
||||
"", // value
|
||||
"40", // default
|
||||
"integer", // type,
|
||||
'font', // category
|
||||
'fontsizeh1', // id
|
||||
'Taille des titres h1', // title
|
||||
'', // value
|
||||
'40', // default
|
||||
'integer', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Taille des titres h1 en px"
|
||||
'', // grouped
|
||||
'Taille des titres h1 en px'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
4, // order
|
||||
"font", // category
|
||||
"fontsizeh2", // id
|
||||
"Taille des titres h2", // title
|
||||
"", // value
|
||||
"32", // default
|
||||
"integer", // type,
|
||||
'font', // category
|
||||
'fontsizeh2', // id
|
||||
'Taille des titres h2', // title
|
||||
'', // value
|
||||
'32', // default
|
||||
'integer', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Taille des titres h2 en px"
|
||||
'', // grouped
|
||||
'Taille des titres h2 en px'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
5, // order
|
||||
"font", // category
|
||||
"fontsizeh3", // id
|
||||
"Taille des titres h3", // title
|
||||
"", // value
|
||||
"28", // default
|
||||
"integer", // type,
|
||||
'font', // category
|
||||
'fontsizeh3', // id
|
||||
'Taille des titres h3', // title
|
||||
'', // value
|
||||
'28', // default
|
||||
'integer', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Taille des titres h3 en px"
|
||||
'', // grouped
|
||||
'Taille des titres h3 en px'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
6, // order
|
||||
"font", // category
|
||||
"fontsizeh4", // id
|
||||
"Taille des titres h4", // title
|
||||
"", // value
|
||||
"24", // default
|
||||
"integer", // type,
|
||||
'font', // category
|
||||
'fontsizeh4', // id
|
||||
'Taille des titres h4', // title
|
||||
'', // value
|
||||
'24', // default
|
||||
'integer', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Taille des titres h4 en px"
|
||||
'', // grouped
|
||||
'Taille des titres h4 en px'
|
||||
);
|
||||
|
||||
// logo =
|
||||
// logo =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"logo", // category
|
||||
"logodark", // id
|
||||
"Logo sur fond fonçé", // title
|
||||
"", // value
|
||||
"logo.png", // default
|
||||
"logo", // type,
|
||||
'logo', // category
|
||||
'logodark', // id
|
||||
'Logo sur fond fonçé', // title
|
||||
'', // value
|
||||
'logo.png', // default
|
||||
'logo', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Logo sur fond fonçé"
|
||||
);
|
||||
'', // grouped
|
||||
'Logo sur fond fonçé'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"logo", // category
|
||||
"logolight", // id
|
||||
"Logo sur fond clair", // title
|
||||
"", // value
|
||||
"logo.png", // default
|
||||
"logo", // type,
|
||||
'logo', // category
|
||||
'logolight', // id
|
||||
'Logo sur fond clair', // title
|
||||
'', // value
|
||||
'logo.png', // default
|
||||
'logo', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Logo sur fond clair"
|
||||
);
|
||||
'', // grouped
|
||||
'Logo sur fond clair'
|
||||
);
|
||||
|
||||
|
||||
// header =
|
||||
// header =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"header", // category
|
||||
"headerimage", // id
|
||||
"Image de fond de la bannière", // title
|
||||
"", // value
|
||||
"header.jpg", // default
|
||||
"header", // type,
|
||||
'header', // category
|
||||
'headerimage', // id
|
||||
'Image de fond de la bannière', // title
|
||||
'', // value
|
||||
'header.jpg', // default
|
||||
'header', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image appnamede fond de la bannière"
|
||||
);
|
||||
'', // grouped
|
||||
'Image appnamede fond de la bannière'
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"header", // category
|
||||
"headerheight", // id
|
||||
"Hauteur de la bannière", // title
|
||||
"", // value
|
||||
"100", // default
|
||||
"integer", // type,
|
||||
'header', // category
|
||||
'headerheight', // id
|
||||
'Hauteur de la bannière', // title
|
||||
'', // value
|
||||
'100', // default
|
||||
'integer', // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image de fond de la bannière"
|
||||
);
|
||||
'', // grouped
|
||||
'Image de fond de la bannière'
|
||||
);
|
||||
$output->writeln('');
|
||||
|
||||
|
||||
// Job synchronisation des comptes utilisateur
|
||||
// Toute les 24h à 3h00
|
||||
$entity = $this->em->getRepository('App\Entity\Cron')->findOneBy(["command"=>"app:Synchro"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$nextdate=$entity->getSubmitdate();
|
||||
$nextdate->setTime(4,0);
|
||||
$entity->setCommand("app:Synchro");
|
||||
$entity->setDescription("Synchronisation des comptes utilisateurs");
|
||||
$entity = $this->em->getRepository('App\Entity\Cron')->findOneBy(['command' => 'app:Synchro']);
|
||||
if (!$entity) {
|
||||
$entity = new Cron();
|
||||
$nextdate = $entity->getSubmitdate();
|
||||
$nextdate->setTime(4, 0);
|
||||
$entity->setCommand('app:Synchro');
|
||||
$entity->setDescription('Synchronisation des comptes utilisateurs');
|
||||
$entity->setStatut(1);
|
||||
$entity->setRepeatinterval(86400);
|
||||
$entity->setNextexecdate($nextdate);
|
||||
@ -505,27 +498,29 @@ class InitCommand extends Command
|
||||
|
||||
// Job purge des registrations obsolètes
|
||||
// Toute les 5mn
|
||||
$entity = $this->em->getRepository('App\Entity\Cron')->findOneBy(["command"=>"app:CleanRegistration"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$entity->setCommand("app:CleanRegistration");
|
||||
$entity->setDescription("Nettoyage des Inscriptions obsolètes");
|
||||
$entity = $this->em->getRepository('App\Entity\Cron')->findOneBy(['command' => 'app:CleanRegistration']);
|
||||
if (!$entity) {
|
||||
$entity = new Cron();
|
||||
$entity->setCommand('app:CleanRegistration');
|
||||
$entity->setDescription('Nettoyage des Inscriptions obsolètes');
|
||||
$entity->setStatut(1);
|
||||
$entity->setRepeatinterval(300);
|
||||
$entity->setNextexecdate($entity->getSubmitdate());
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
$output->writeln('');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function insertConfig($order,$category,$id,$title,$value,$default,$type,$visible,$changeable,$required,$grouped,$help) {
|
||||
$entity=$this->em->getRepository("App\Entity\Config")->find($id);
|
||||
if(!$entity) {
|
||||
$entity= new Config();
|
||||
private function insertConfig($order, $category, $id, $title, $value, $default, $type, $visible, $changeable, $required, $grouped, $help)
|
||||
{
|
||||
$entity = $this->em->getRepository("App\Entity\Config")->find($id);
|
||||
if (!$entity) {
|
||||
$entity = new Config();
|
||||
$entity->setId($id);
|
||||
$entity->setValue($value);
|
||||
}
|
||||
@ -545,12 +540,15 @@ class InitCommand extends Command
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
private function writelnred($string)
|
||||
{
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
|
||||
private function writeln($string)
|
||||
{
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
|
||||
use Cadoles\CoreBundle\Entity\User;
|
||||
|
||||
class SetPasswordCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
@ -20,7 +18,7 @@ class SetPasswordCommand extends Command
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
public function __construct(ContainerInterface $container, EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
@ -33,21 +31,19 @@ class SetPasswordCommand extends Command
|
||||
->setName('app:SetPassword')
|
||||
->setDescription("Modifier le password d'un utilisateur")
|
||||
->setHelp("Modifier le password d'un utilisateur")
|
||||
->addArgument('username', InputArgument::OPTIONAL, 'username')
|
||||
->addArgument('username', InputArgument::OPTIONAL, 'username')
|
||||
->addArgument('password', InputArgument::OPTIONAL, 'password')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir().'/';
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:SetPasword');
|
||||
$this->writelnred('== app:SetPasword');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$username = $input->getArgument('username');
|
||||
@ -56,28 +52,31 @@ class SetPasswordCommand extends Command
|
||||
$password = $input->getArgument('password');
|
||||
$this->writeln($password);
|
||||
|
||||
$user = $this->em->getRepository('App\Entity\User')->findOneBy(array('username' => $username));
|
||||
if($user) {
|
||||
$user = $this->em->getRepository('App\Entity\User')->findOneBy(['username' => $username]);
|
||||
if ($user) {
|
||||
// Set Password
|
||||
$user->setPassword($password);
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
private function writelnred($string)
|
||||
{
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
if(!$string) $string=" ";
|
||||
|
||||
private function writeln($string)
|
||||
{
|
||||
if (!$string) {
|
||||
$string = ' ';
|
||||
}
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Service\LdapService;
|
||||
use App\Service\ApiService;
|
||||
use App\Entity\Niveau01;
|
||||
use App\Entity\Niveau02;
|
||||
use App\Entity\User;
|
||||
use App\Entity\Group;
|
||||
use App\Entity\Niveau01;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserGroup;
|
||||
|
||||
use App\Service\ApiService;
|
||||
use App\Service\LdapService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class SynchroCommand extends Command
|
||||
{
|
||||
@ -60,8 +55,8 @@ class SynchroCommand extends Command
|
||||
private $groupmemberisdn;
|
||||
private $filtergroup;
|
||||
private $filteruser;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em,LdapService $ldapservice,ApiService $apiservice)
|
||||
|
||||
public function __construct(ContainerInterface $container, EntityManagerInterface $em, LdapService $ldapservice, ApiService $apiservice)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
@ -81,85 +76,84 @@ class SynchroCommand extends Command
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$this->appMasteridentity = $this->container->getParameter('appMasteridentity');
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir().'/';
|
||||
$this->appMasteridentity = $this->container->getParameter('appMasteridentity');
|
||||
|
||||
|
||||
|
||||
$appSynchro = $this->container->getParameter('appSynchro');
|
||||
|
||||
$this->synchro = $this->container->getParameter("appSynchro");
|
||||
$this->synchropurgeniveau01 = $this->container->getParameter("appSynchroPurgeNiveau01");
|
||||
$this->synchropurgeniveau02 = $this->container->getParameter("appSynchroPurgeNiveau02");
|
||||
$this->synchropurgegroup = $this->container->getParameter("appSynchroPurgeGroup");
|
||||
$this->synchropurgeuser = $this->container->getParameter("appSynchroPurgeUser");
|
||||
|
||||
$this->host = $this->container->getParameter("ldapHost");
|
||||
$this->port = $this->container->getParameter("ldapPort");
|
||||
$this->usetls = $this->container->getParameter("ldapUsetls");
|
||||
$this->userwriter = $this->container->getParameter("ldapUserwriter");
|
||||
$this->user = $this->container->getParameter("ldapUser");
|
||||
$this->password = $this->container->getParameter("ldapPassword");
|
||||
$this->basedn = $this->container->getParameter("ldapBasedn");
|
||||
$this->baseorganisation = $this->container->getParameter("ldapBaseorganisation");
|
||||
$this->baseniveau01 = $this->container->getParameter("ldapBaseniveau01");
|
||||
$this->baseniveau02 = $this->container->getParameter("ldapBaseniveau02");
|
||||
$this->basegroup = $this->container->getParameter("ldapBasegroup");
|
||||
$this->baseuser = $this->container->getParameter("ldapBaseuser");
|
||||
$this->username = $this->container->getParameter("ldapUsername");
|
||||
$this->firstname = $this->container->getParameter("ldapFirstname");
|
||||
$this->lastname = $this->container->getParameter("ldapLastname");
|
||||
$this->email = $this->container->getParameter("ldapEmail");
|
||||
$this->avatar = $this->container->getParameter("ldapAvatar");
|
||||
$this->memberof = $this->container->getParameter("ldapMemberof");
|
||||
$this->groupgid = $this->container->getParameter("ldapGroupgid");
|
||||
$this->groupname = $this->container->getParameter("ldapGroupname");
|
||||
$this->groupmember = $this->container->getParameter("ldapGroupmember");
|
||||
$this->groupmemberisdn = $this->container->getParameter("ldapGroupmemberisdn");
|
||||
$this->filtergroup = $this->container->getParameter("ldapFiltergroup");
|
||||
$this->filteruser = $this->container->getParameter("ldapFilteruser");
|
||||
$this->synchro = $this->container->getParameter('appSynchro');
|
||||
$this->synchropurgeniveau01 = $this->container->getParameter('appSynchroPurgeNiveau01');
|
||||
$this->synchropurgeniveau02 = $this->container->getParameter('appSynchroPurgeNiveau02');
|
||||
$this->synchropurgegroup = $this->container->getParameter('appSynchroPurgeGroup');
|
||||
$this->synchropurgeuser = $this->container->getParameter('appSynchroPurgeUser');
|
||||
|
||||
switch($appSynchro){
|
||||
case "LDAP2NINE":
|
||||
$return=$this->ldap2nine();
|
||||
break;
|
||||
$this->host = $this->container->getParameter('ldapHost');
|
||||
$this->port = $this->container->getParameter('ldapPort');
|
||||
$this->usetls = $this->container->getParameter('ldapUsetls');
|
||||
$this->userwriter = $this->container->getParameter('ldapUserwriter');
|
||||
$this->user = $this->container->getParameter('ldapUser');
|
||||
$this->password = $this->container->getParameter('ldapPassword');
|
||||
$this->basedn = $this->container->getParameter('ldapBasedn');
|
||||
$this->baseorganisation = $this->container->getParameter('ldapBaseorganisation');
|
||||
$this->baseniveau01 = $this->container->getParameter('ldapBaseniveau01');
|
||||
$this->baseniveau02 = $this->container->getParameter('ldapBaseniveau02');
|
||||
$this->basegroup = $this->container->getParameter('ldapBasegroup');
|
||||
$this->baseuser = $this->container->getParameter('ldapBaseuser');
|
||||
$this->username = $this->container->getParameter('ldapUsername');
|
||||
$this->firstname = $this->container->getParameter('ldapFirstname');
|
||||
$this->lastname = $this->container->getParameter('ldapLastname');
|
||||
$this->email = $this->container->getParameter('ldapEmail');
|
||||
$this->avatar = $this->container->getParameter('ldapAvatar');
|
||||
$this->memberof = $this->container->getParameter('ldapMemberof');
|
||||
$this->groupgid = $this->container->getParameter('ldapGroupgid');
|
||||
$this->groupname = $this->container->getParameter('ldapGroupname');
|
||||
$this->groupmember = $this->container->getParameter('ldapGroupmember');
|
||||
$this->groupmemberisdn = $this->container->getParameter('ldapGroupmemberisdn');
|
||||
$this->filtergroup = $this->container->getParameter('ldapFiltergroup');
|
||||
$this->filteruser = $this->container->getParameter('ldapFilteruser');
|
||||
|
||||
case "NINE2LDAP":
|
||||
$return=$this->nine2ldap();
|
||||
break;
|
||||
switch ($appSynchro) {
|
||||
case 'LDAP2NINE':
|
||||
$return = $this->ldap2nine();
|
||||
break;
|
||||
|
||||
case "NINE2NINE":
|
||||
$return=$this->nine2nine();
|
||||
break;
|
||||
case 'NINE2LDAP':
|
||||
$return = $this->nine2ldap();
|
||||
break;
|
||||
|
||||
case 'NINE2NINE':
|
||||
$return = $this->nine2nine();
|
||||
break;
|
||||
|
||||
default:
|
||||
$return=Command::SUCCESS;
|
||||
break;
|
||||
$return = Command::SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return $return;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function ldap2nine()
|
||||
{
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:Synchro');
|
||||
$this->writelnred('== app:Synchro');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
|
||||
// Synchronisation ldap2nine possible uniquement si appMasteridentity=LDAP or SSO
|
||||
if($this->appMasteridentity!="LDAP"&&$this->appMasteridentity!="SSO") {
|
||||
$this->writeln("Synchronisation impossible si appMasteridentity!=LDAP et appMasteridentity!=SSO");
|
||||
if ('LDAP' != $this->appMasteridentity && 'SSO' != $this->appMasteridentity) {
|
||||
$this->writeln('Synchronisation impossible si appMasteridentity!=LDAP et appMasteridentity!=SSO');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// Synchronisation impossible si aucune connexion à l'annuaire
|
||||
if(!$this->ldap->connect()) {
|
||||
if (!$this->ldap->connect()) {
|
||||
$this->writeln("Synchronisation impossible connexion impossible à l'annuaire");
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
@ -168,240 +162,256 @@ class SynchroCommand extends Command
|
||||
$this->writeln('== SYNCHONISATION LDAP TO NINE ======================');
|
||||
$this->writeln('=====================================================');
|
||||
|
||||
$tbniveau01members=[];
|
||||
$tbgroupmembers=[];
|
||||
$tbniveau01s=[];
|
||||
$tbgroups=[];
|
||||
$tbusers=[];
|
||||
$tbniveau01members = [];
|
||||
$tbgroupmembers = [];
|
||||
$tbniveau01s = [];
|
||||
$tbgroups = [];
|
||||
$tbusers = [];
|
||||
|
||||
$ldapniveau01s=$this->em->createQueryBuilder()->select('entity')->from('App:Niveau01','entity')->where('entity.ldapfilter IS NOT NULL')->getQuery()->getResult();
|
||||
$ldapgroups=$this->em->createQueryBuilder()->select('entity')->from('App:Group','entity')->where('entity.ldapfilter IS NOT NULL')->getQuery()->getResult();
|
||||
$ldapniveau01s = $this->em->createQueryBuilder()->select('entity')->from('App:Niveau01', 'entity')->where('entity.ldapfilter IS NOT NULL')->getQuery()->getResult();
|
||||
$ldapgroups = $this->em->createQueryBuilder()->select('entity')->from('App:Group', 'entity')->where('entity.ldapfilter IS NOT NULL')->getQuery()->getResult();
|
||||
|
||||
$fgsynchroniveau01s=(!empty($this->baseniveau01)&&!empty($this->groupgid)&&!empty($this->groupname)&&!empty($this->filtergroup));
|
||||
$fgsynchrogroups=(!empty($this->basegroup)&&!empty($this->groupgid)&&!empty($this->groupname)&&!empty($this->filtergroup));
|
||||
$fgsynchrousers=(!empty($this->baseuser)&&!empty($this->username)&&!empty($this->email)&&!empty($this->filteruser));
|
||||
|
||||
$fgsynchropurgeniveau01s=($fgsynchroniveau01s&&$this->synchropurgeniveau01);
|
||||
$fgsynchropurgegroups=($fgsynchrogroups&&$this->synchropurgegroup);
|
||||
$fgsynchropurgeusers=($fgsynchrousers&&$this->synchropurgeuser);
|
||||
$fgsynchroniveau01s = (!empty($this->baseniveau01) && !empty($this->groupgid) && !empty($this->groupname) && !empty($this->filtergroup));
|
||||
$fgsynchrogroups = (!empty($this->basegroup) && !empty($this->groupgid) && !empty($this->groupname) && !empty($this->filtergroup));
|
||||
$fgsynchrousers = (!empty($this->baseuser) && !empty($this->username) && !empty($this->email) && !empty($this->filteruser));
|
||||
|
||||
$fgsynchropurgeniveau01s = ($fgsynchroniveau01s && $this->synchropurgeniveau01);
|
||||
$fgsynchropurgegroups = ($fgsynchrogroups && $this->synchropurgegroup);
|
||||
$fgsynchropurgeusers = ($fgsynchrousers && $this->synchropurgeuser);
|
||||
|
||||
// Synchronisation des niveau01s
|
||||
if($fgsynchroniveau01s) {
|
||||
if ($fgsynchroniveau01s) {
|
||||
$this->writeln('');
|
||||
$this->writeln('== NIVEAU01 =========================================');
|
||||
$ldapentrys=$this->ldap->search($this->filtergroup,[$this->groupgid,$this->groupname,$this->groupmember],$this->baseniveau01);
|
||||
foreach($ldapentrys as $ldapentry) {
|
||||
$niveau01other=$this->em->getRepository("App\Entity\Niveau01")->findOneBy(["label"=>$ldapentry[$this->groupname]]);
|
||||
if($niveau01other&&$niveau01other->getIdexternal()!=$ldapentry[$this->groupgid]) {
|
||||
$this->writelnred(" > ".$ldapentry[$this->groupname]." = Impossible à synchroniser un autre niveau01 existe déjà avec ce label");
|
||||
$ldapentrys = $this->ldap->search($this->filtergroup, [$this->groupgid, $this->groupname, $this->groupmember], $this->baseniveau01);
|
||||
foreach ($ldapentrys as $ldapentry) {
|
||||
$niveau01other = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $ldapentry[$this->groupname]]);
|
||||
if ($niveau01other && $niveau01other->getIdexternal() != $ldapentry[$this->groupgid]) {
|
||||
$this->writelnred(' > '.$ldapentry[$this->groupname].' = Impossible à synchroniser un autre niveau01 existe déjà avec ce label');
|
||||
continue;
|
||||
}
|
||||
|
||||
// On recherche le groupe via le gid
|
||||
// On recherche le groupe via le gid
|
||||
$this->writeln(' > '.$ldapentry[$this->groupname]);
|
||||
$niveau01=$this->em->getRepository("App\Entity\Niveau01")->findOneBy(["idexternal"=>$ldapentry[$this->groupgid]]);
|
||||
if(!$niveau01) {
|
||||
$niveau01=new Niveau01();
|
||||
$niveau01->setApikey(Uuid::uuid4());
|
||||
$niveau01 = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['idexternal' => $ldapentry[$this->groupgid]]);
|
||||
if (!$niveau01) {
|
||||
$niveau01 = new Niveau01();
|
||||
$niveau01->setApikey(Uuid::uuid4());
|
||||
$this->em->persist($niveau01);
|
||||
}
|
||||
$niveau01->setIdexternal($ldapentry[$this->groupgid]);
|
||||
$niveau01->setLabel($ldapentry[$this->groupname]);
|
||||
$niveau01->setLdapfilter("(".$this->groupname."=".$ldapentry[$this->groupname].")");
|
||||
$niveau01->setLdapfilter('('.$this->groupname.'='.$ldapentry[$this->groupname].')');
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
// Sauvegarde du niveau01ldap
|
||||
array_push($tbniveau01s,$ldapentry[$this->groupname]);
|
||||
array_push($tbniveau01s, $ldapentry[$this->groupname]);
|
||||
|
||||
// Sauvegarde des membres du niveau01
|
||||
if(!empty($ldapentry[$this->groupmember])) {
|
||||
if(!is_array($ldapentry[$this->groupmember])) {
|
||||
$member=$ldapentry[$this->groupmember];
|
||||
if(!array_key_exists($member,$tbniveau01members)) $tbniveau01members[$member]=[];
|
||||
array_push($tbniveau01members[$member],$ldapentry[$this->groupname]);
|
||||
}
|
||||
else {
|
||||
foreach($ldapentry[$this->groupmember] as $member) {
|
||||
if(!array_key_exists($member,$tbniveau01members)) $tbniveau01members[$member]=[];
|
||||
array_push($tbniveau01members[$member],$ldapentry[$this->groupname]);
|
||||
if (!empty($ldapentry[$this->groupmember])) {
|
||||
if (!is_array($ldapentry[$this->groupmember])) {
|
||||
$member = $ldapentry[$this->groupmember];
|
||||
if (!array_key_exists($member, $tbniveau01members)) {
|
||||
$tbniveau01members[$member] = [];
|
||||
}
|
||||
array_push($tbniveau01members[$member], $ldapentry[$this->groupname]);
|
||||
} else {
|
||||
foreach ($ldapentry[$this->groupmember] as $member) {
|
||||
if (!array_key_exists($member, $tbniveau01members)) {
|
||||
$tbniveau01members[$member] = [];
|
||||
}
|
||||
array_push($tbniveau01members[$member], $ldapentry[$this->groupname]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->writeln('');
|
||||
$this->writeln('== NIVEAU01 =========================================');
|
||||
$this->writelnred(" > Synchronisation impossible il vous manque des paramétres ldap pour le faire");
|
||||
$this->writelnred(' > Synchronisation impossible il vous manque des paramétres ldap pour le faire');
|
||||
}
|
||||
|
||||
// Synchronisation des groups
|
||||
if($fgsynchrogroups) {
|
||||
if ($fgsynchrogroups) {
|
||||
$this->writeln('');
|
||||
$this->writeln('== GROUP ============================================');
|
||||
$ldapentrys=$this->ldap->search($this->filtergroup,[$this->groupgid,$this->groupname,$this->groupmember],$this->basegroup);
|
||||
$ldapentrys = $this->ldap->search($this->filtergroup, [$this->groupgid, $this->groupname, $this->groupmember], $this->basegroup);
|
||||
|
||||
foreach($ldapentrys as $ldapentry) {
|
||||
$groupother=$this->em->getRepository("App\Entity\Group")->findOneBy(["label"=>$ldapentry[$this->groupname]]);
|
||||
if($groupother&&$groupother->getIdexternal()!=$ldapentry[$this->groupgid]) {
|
||||
$this->writelnred(" > ".$ldapentry[$this->groupname]." = Impossible à synchroniser un autre groupe existe déjà avec ce label");
|
||||
foreach ($ldapentrys as $ldapentry) {
|
||||
$groupother = $this->em->getRepository("App\Entity\Group")->findOneBy(['label' => $ldapentry[$this->groupname]]);
|
||||
if ($groupother && $groupother->getIdexternal() != $ldapentry[$this->groupgid]) {
|
||||
$this->writelnred(' > '.$ldapentry[$this->groupname].' = Impossible à synchroniser un autre groupe existe déjà avec ce label');
|
||||
continue;
|
||||
}
|
||||
|
||||
// On recherche le groupe via le gid
|
||||
// On recherche le groupe via le gid
|
||||
$this->writeln(' > '.$ldapentry[$this->groupname]);
|
||||
$group=$this->em->getRepository("App\Entity\Group")->findOneBy(["idexternal"=>$ldapentry[$this->groupgid]]);
|
||||
if(!$group) {
|
||||
$group=new Group();
|
||||
$group = $this->em->getRepository("App\Entity\Group")->findOneBy(['idexternal' => $ldapentry[$this->groupgid]]);
|
||||
if (!$group) {
|
||||
$group = new Group();
|
||||
$group->setIsopen(false);
|
||||
$group->setIsworkgroup(false);
|
||||
$group->setApikey(Uuid::uuid4());
|
||||
$group->setApikey(Uuid::uuid4());
|
||||
|
||||
$this->em->persist($group);
|
||||
}
|
||||
$group->setIdexternal($ldapentry[$this->groupgid]);
|
||||
$group->setLabel($ldapentry[$this->groupname]);
|
||||
$group->setLdapfilter("(".$this->groupname."=".$ldapentry[$this->groupname].")");
|
||||
$group->setLdapfilter('('.$this->groupname.'='.$ldapentry[$this->groupname].')');
|
||||
|
||||
$this->em->flush();
|
||||
$this->em->flush();
|
||||
|
||||
// Sauvegarde du groupldap
|
||||
array_push($tbgroups,$ldapentry[$this->groupname]);
|
||||
array_push($tbgroups, $ldapentry[$this->groupname]);
|
||||
|
||||
// Sauvegarde des membres du group
|
||||
if(!empty($ldapentry[$this->groupmember])) {
|
||||
if(!is_array($ldapentry[$this->groupmember])) {
|
||||
$member=$ldapentry[$this->groupmember];
|
||||
if(!array_key_exists($member,$tbgroupmembers)) $tbgroupmembers[$member]=[];
|
||||
array_push($tbgroupmembers[$member],$ldapentry[$this->groupname]);
|
||||
}
|
||||
else {
|
||||
foreach($ldapentry[$this->groupmember] as $member) {
|
||||
if(!array_key_exists($member,$tbgroupmembers)) $tbgroupmembers[$member]=[];
|
||||
array_push($tbgroupmembers[$member],$ldapentry[$this->groupname]);
|
||||
if (!empty($ldapentry[$this->groupmember])) {
|
||||
if (!is_array($ldapentry[$this->groupmember])) {
|
||||
$member = $ldapentry[$this->groupmember];
|
||||
if (!array_key_exists($member, $tbgroupmembers)) {
|
||||
$tbgroupmembers[$member] = [];
|
||||
}
|
||||
array_push($tbgroupmembers[$member], $ldapentry[$this->groupname]);
|
||||
} else {
|
||||
foreach ($ldapentry[$this->groupmember] as $member) {
|
||||
if (!array_key_exists($member, $tbgroupmembers)) {
|
||||
$tbgroupmembers[$member] = [];
|
||||
}
|
||||
array_push($tbgroupmembers[$member], $ldapentry[$this->groupname]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->writeln('');
|
||||
$this->writeln('== GROUP ============================================');
|
||||
$this->writelnred(" > Synchronisation impossible il vous manque des paramétres ldap pour le faire");
|
||||
$this->writelnred(' > Synchronisation impossible il vous manque des paramétres ldap pour le faire');
|
||||
}
|
||||
|
||||
|
||||
// Synchronisation des users
|
||||
if($fgsynchrousers) {
|
||||
if ($fgsynchrousers) {
|
||||
$this->writeln('');
|
||||
$this->writeln('== USER =============================================');
|
||||
$ldapentrys=$this->ldap->search($this->filteruser,[$this->username,$this->firstname,$this->lastname,$this->email,$this->avatar,$this->memberof],$this->baseuser);
|
||||
$ldapentrys = $this->ldap->search($this->filteruser, [$this->username, $this->firstname, $this->lastname, $this->email, $this->avatar, $this->memberof], $this->baseuser);
|
||||
|
||||
foreach($ldapentrys as $ldapentry) {
|
||||
$userother=$this->em->getRepository("App\Entity\User")->findOneBy(["email"=>$ldapentry[$this->email]]);
|
||||
if($userother&&$userother->getUSername()!=$ldapentry[$this->username]) {
|
||||
$this->writelnred(" > ".$ldapentry[$this->groupname]." = Impossible à synchroniser un autre user existe déjà avec ce mail");
|
||||
foreach ($ldapentrys as $ldapentry) {
|
||||
$userother = $this->em->getRepository("App\Entity\User")->findOneBy(['email' => $ldapentry[$this->email]]);
|
||||
if ($userother && $userother->getUSername() != $ldapentry[$this->username]) {
|
||||
$this->writelnred(' > '.$ldapentry[$this->groupname].' = Impossible à synchroniser un autre user existe déjà avec ce mail');
|
||||
continue;
|
||||
}
|
||||
$userother=$this->em->getRepository("App\Entity\Registration")->findOneBy(["email"=>$ldapentry[$this->email]]);
|
||||
if($userother&&$userother->getUSername()!=$ldapentry[$this->username]) {
|
||||
$this->writelnred(" > ".$ldapentry[$this->username]." = Impossible à synchroniser un autre user existe déjà avec ce mail");
|
||||
$userother = $this->em->getRepository("App\Entity\Registration")->findOneBy(['email' => $ldapentry[$this->email]]);
|
||||
if ($userother && $userother->getUSername() != $ldapentry[$this->username]) {
|
||||
$this->writelnred(' > '.$ldapentry[$this->username].' = Impossible à synchroniser un autre user existe déjà avec ce mail');
|
||||
continue;
|
||||
}
|
||||
|
||||
// On recherche le user via le username
|
||||
$this->writeln(' > '.$ldapentry[$this->username]);
|
||||
$user=$this->em->getRepository("App\Entity\User")->findOneBy(["username"=>$ldapentry[$this->username]]);
|
||||
if(!$user) {
|
||||
$user=new User();
|
||||
$user = $this->em->getRepository("App\Entity\User")->findOneBy(['username' => $ldapentry[$this->username]]);
|
||||
if (!$user) {
|
||||
$user = new User();
|
||||
$user->setUsername($ldapentry[$this->username]);
|
||||
$user->setIsvisible(true);
|
||||
$user->setApikey(Uuid::uuid4());
|
||||
$user->setRole("ROLE_USER");
|
||||
$user->setAvatar("noavatar.png");
|
||||
$user->setRole('ROLE_USER');
|
||||
$user->setAvatar('noavatar.png');
|
||||
|
||||
$uuid=Uuid::uuid4();
|
||||
$user->setPassword("PWD-".$ldapentry[$this->username]."-".$uuid);
|
||||
$uuid = Uuid::uuid4();
|
||||
$user->setPassword('PWD-'.$ldapentry[$this->username].'-'.$uuid);
|
||||
|
||||
$this->em->persist($user);
|
||||
}
|
||||
|
||||
// Recherche du niveau01
|
||||
$niveau01=null;
|
||||
if($user->getNiveau01()&&empty($user->getNiveau01()->getIdexternal()))
|
||||
$niveau01=$user->getNiveau01();
|
||||
if(array_key_exists($ldapentry[$this->username],$tbniveau01members))
|
||||
$niveau01=$this->em->getRepository("App\Entity\Niveau01")->findOneBy(["label"=>$tbniveau01members[$ldapentry[$this->username]][0]]);
|
||||
if(!$niveau01)
|
||||
$niveau01=$this->em->getRepository('App\Entity\Niveau01')->find(-1);
|
||||
$niveau01 = null;
|
||||
if ($user->getNiveau01() && empty($user->getNiveau01()->getIdexternal())) {
|
||||
$niveau01 = $user->getNiveau01();
|
||||
}
|
||||
if (array_key_exists($ldapentry[$this->username], $tbniveau01members)) {
|
||||
$niveau01 = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $tbniveau01members[$ldapentry[$this->username]][0]]);
|
||||
}
|
||||
if (!$niveau01) {
|
||||
$niveau01 = $this->em->getRepository('App\Entity\Niveau01')->find(-1);
|
||||
}
|
||||
|
||||
// Mise à jour des attributs
|
||||
if(!empty($ldapentry[$this->lastname])) $user->setLastname($ldapentry[$this->lastname]);
|
||||
if(!empty($ldapentry[$this->firstname])) $user->setFirstname($ldapentry[$this->firstname]);
|
||||
if(!empty($ldapentry[$this->email])) $user->setEmail($ldapentry[$this->email]);
|
||||
if(!empty($ldapentry[$this->avatar])) $user->setAvatar($ldapentry[$this->avatar]);
|
||||
if (!empty($ldapentry[$this->lastname])) {
|
||||
$user->setLastname($ldapentry[$this->lastname]);
|
||||
}
|
||||
if (!empty($ldapentry[$this->firstname])) {
|
||||
$user->setFirstname($ldapentry[$this->firstname]);
|
||||
}
|
||||
if (!empty($ldapentry[$this->email])) {
|
||||
$user->setEmail($ldapentry[$this->email]);
|
||||
}
|
||||
if (!empty($ldapentry[$this->avatar])) {
|
||||
$user->setAvatar($ldapentry[$this->avatar]);
|
||||
}
|
||||
|
||||
// Mise à jour du niveau01
|
||||
if($niveau01!=$user->getNiveau01()) $user->setNiveau02(null);
|
||||
if ($niveau01 != $user->getNiveau01()) {
|
||||
$user->setNiveau02(null);
|
||||
}
|
||||
$user->setNiveau01($niveau01);
|
||||
|
||||
|
||||
// Mise à jour du role
|
||||
if(in_array($ldapentry[$this->username],$this->container->getParameter("appAdmins")))
|
||||
$user->setRole("ROLE_ADMIN");
|
||||
if (in_array($ldapentry[$this->username], $this->container->getParameter('appAdmins'))) {
|
||||
$user->setRole('ROLE_ADMIN');
|
||||
}
|
||||
|
||||
// Sauvegarde en bdd
|
||||
$this->em->flush();
|
||||
$this->em->flush();
|
||||
|
||||
// Sauvegarde du userldap
|
||||
array_push($tbusers,$ldapentry[$this->username]);
|
||||
array_push($tbusers, $ldapentry[$this->username]);
|
||||
|
||||
// Inscription au groupe
|
||||
if(array_key_exists($ldapentry[$this->username],$tbgroupmembers)) {
|
||||
foreach($tbgroupmembers[$ldapentry[$this->username]] as $grouplabel) {
|
||||
$group=$this->em->getRepository("App\Entity\Group")->findOneBy(["label"=>$grouplabel]);
|
||||
if($group) {
|
||||
$usergroup=$this->em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$user,"group"=>$group]);
|
||||
if(!$usergroup) {
|
||||
$usergroup=new UserGroup();
|
||||
if (array_key_exists($ldapentry[$this->username], $tbgroupmembers)) {
|
||||
foreach ($tbgroupmembers[$ldapentry[$this->username]] as $grouplabel) {
|
||||
$group = $this->em->getRepository("App\Entity\Group")->findOneBy(['label' => $grouplabel]);
|
||||
if ($group) {
|
||||
$usergroup = $this->em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
||||
if (!$usergroup) {
|
||||
$usergroup = new UserGroup();
|
||||
$usergroup->setUser($user);
|
||||
$usergroup->setGroup($group);
|
||||
$usergroup->setApikey(Uuid::uuid4());
|
||||
$usergroup->setRolegroup(0);
|
||||
$this->em->persist($usergroup);
|
||||
$this->em->flush();
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Desinscription des group ldap
|
||||
foreach($ldapgroups as $group) {
|
||||
if(!array_key_exists($ldapentry[$this->username],$tbgroupmembers)||!in_array($group->getLabel(),$tbgroupmembers[$ldapentry[$this->username]])) {
|
||||
$usergroup=$this->em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$user,"group"=>$group]);
|
||||
if($usergroup) {
|
||||
foreach ($ldapgroups as $group) {
|
||||
if (!array_key_exists($ldapentry[$this->username], $tbgroupmembers) || !in_array($group->getLabel(), $tbgroupmembers[$ldapentry[$this->username]])) {
|
||||
$usergroup = $this->em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
||||
if ($usergroup) {
|
||||
$this->em->remove($usergroup);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
}
|
||||
} else {
|
||||
$this->writeln('');
|
||||
$this->writeln('== USER =============================================');
|
||||
$this->writelnred(" > Synchronisation impossible il vous manque des paramétres ldap pour le faire");
|
||||
}
|
||||
$this->writelnred(' > Synchronisation impossible il vous manque des paramétres ldap pour le faire');
|
||||
}
|
||||
|
||||
// Purge des users
|
||||
if($fgsynchropurgeusers) {
|
||||
if ($fgsynchropurgeusers) {
|
||||
$this->writeln('');
|
||||
$this->writeln('== PURGE USER =============================================');
|
||||
|
||||
$users=$this->em->getRepository("App\Entity\User")->findAll();
|
||||
foreach($users as $user) {
|
||||
if(!in_array($user->getUsername(),$tbusers)) {
|
||||
if($user->getId()>0) {
|
||||
$users = $this->em->getRepository("App\Entity\User")->findAll();
|
||||
foreach ($users as $user) {
|
||||
if (!in_array($user->getUsername(), $tbusers)) {
|
||||
if ($user->getId() > 0) {
|
||||
$this->writeln(' > '.$user->getUSername());
|
||||
$this->em->remove($user);
|
||||
$this->em->flush();
|
||||
@ -411,17 +421,16 @@ class SynchroCommand extends Command
|
||||
}
|
||||
|
||||
// Purge des groups
|
||||
if($fgsynchropurgegroups) {
|
||||
if ($fgsynchropurgegroups) {
|
||||
$this->writeln('');
|
||||
$this->writeln('== PURGE GROUP =============================================');
|
||||
|
||||
foreach($ldapgroups as $group) {
|
||||
if(!in_array($group->getLabel(),$tbgroups)) {
|
||||
if($group->getId()>0) {
|
||||
foreach ($ldapgroups as $group) {
|
||||
if (!in_array($group->getLabel(), $tbgroups)) {
|
||||
if ($group->getId() > 0) {
|
||||
$this->writeln(' > '.$group->getLabel());
|
||||
$this->em->remove($group);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$group->setLdapfilter(null);
|
||||
$group->setIdexternal(null);
|
||||
}
|
||||
@ -429,27 +438,26 @@ class SynchroCommand extends Command
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Purge des niveau01s
|
||||
if($fgsynchropurgeniveau01s) {
|
||||
if ($fgsynchropurgeniveau01s) {
|
||||
$this->writeln('');
|
||||
$this->writeln('== PURGE NIVEAU01 =============================================');
|
||||
|
||||
foreach($ldapniveau01s as $niveau01) {
|
||||
if(!in_array($niveau01->getLabel(),$tbniveau01s)) {
|
||||
if($niveau01->getId()>0) {
|
||||
$user=$this->em->getRepository("App\Entity\User")->findOneBy(["niveau01"=>$niveau01]);
|
||||
if($user) {
|
||||
$resetniveau01=$this->em->getRepository("App\Entity\User")->find(-1);
|
||||
foreach ($ldapniveau01s as $niveau01) {
|
||||
if (!in_array($niveau01->getLabel(), $tbniveau01s)) {
|
||||
if ($niveau01->getId() > 0) {
|
||||
$user = $this->em->getRepository("App\Entity\User")->findOneBy(['niveau01' => $niveau01]);
|
||||
if ($user) {
|
||||
$resetniveau01 = $this->em->getRepository("App\Entity\User")->find(-1);
|
||||
$user->setNiveau01($resetniveau01);
|
||||
$user->setNiveau02(null);
|
||||
}
|
||||
|
||||
$this->writeln(' > '.$niveau01->getLabel());
|
||||
$this->em->remove($niveau01);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$niveau01->setLdapfilter(null);
|
||||
$niveau01->setIdexternal(null);
|
||||
}
|
||||
@ -457,32 +465,28 @@ class SynchroCommand extends Command
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
private function nine2ldap()
|
||||
{
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:Synchro');
|
||||
$this->writelnred('== app:Synchro');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
// Synchronisation impossible si aucune connexion à l'annuaire
|
||||
if(!$this->ldap->isNine2Ldap()) {
|
||||
$this->writeln("Synchronisation impossible soit :");
|
||||
if (!$this->ldap->isNine2Ldap()) {
|
||||
$this->writeln('Synchronisation impossible soit :');
|
||||
$this->writeln("- connexion impossible à l'annuaire");
|
||||
$this->writeln("- appMasteridentity!=SQL");
|
||||
$this->writeln('- appMasteridentity!=SQL');
|
||||
$this->writeln("- votre user ldap n'a pas de permission en écriture");
|
||||
$this->writeln("- vous n'avez pas renseigné les bases de votre organisation");
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('=====================================================');
|
||||
$this->writeln('== SYNCHONISATION NINE TO LDAP ======================');
|
||||
@ -499,346 +503,365 @@ class SynchroCommand extends Command
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== USER =============================================');
|
||||
$users=$this->em->getRepository("App\Entity\User")->findAll();
|
||||
$attributes=$this->ldap->listAttributesUser();
|
||||
foreach($users as $user) {
|
||||
$filter=str_replace("*",$user->getUsername(),$this->filteruser);
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseuser);
|
||||
if(empty($ldapentrys)) {
|
||||
$this->writeln($user->getUsername()." = SUBMIT");
|
||||
$users = $this->em->getRepository("App\Entity\User")->findAll();
|
||||
$attributes = $this->ldap->listAttributesUser();
|
||||
foreach ($users as $user) {
|
||||
$filter = str_replace('*', $user->getUsername(), $this->filteruser);
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseuser);
|
||||
if (empty($ldapentrys)) {
|
||||
$this->writeln($user->getUsername().' = SUBMIT');
|
||||
$this->ldap->addUser($user);
|
||||
}
|
||||
elseif($this->ldap->ismodifyUser($user,$ldapentrys[0])) {
|
||||
$this->writeln($user->getUsername()." = UPDATE");
|
||||
} elseif ($this->ldap->ismodifyUser($user, $ldapentrys[0])) {
|
||||
$this->writeln($user->getUsername().' = UPDATE');
|
||||
$this->ldap->modifyUser($user);
|
||||
}
|
||||
}
|
||||
|
||||
$ldapentrys=$this->ldap->search($this->filteruser,$attributes,$this->baseuser);
|
||||
foreach($ldapentrys as $ldapentry) {
|
||||
$user=$this->em->getRepository("App\Entity\User")->findOneBy(["username"=>$ldapentry["uid"]]);
|
||||
if(!$user) {
|
||||
$this->writeln($ldapentry["uid"]." = DELETE");
|
||||
$dn=$this->ldap->getUserDN($ldapentry["uid"]);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
$ldapentrys = $this->ldap->search($this->filteruser, $attributes, $this->baseuser);
|
||||
foreach ($ldapentrys as $ldapentry) {
|
||||
$user = $this->em->getRepository("App\Entity\User")->findOneBy(['username' => $ldapentry['uid']]);
|
||||
if (!$user) {
|
||||
$this->writeln($ldapentry['uid'].' = DELETE');
|
||||
$dn = $this->ldap->getUserDN($ldapentry['uid']);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== GROUP ============================================');
|
||||
$groups=$this->em->getRepository("App\Entity\Group")->findAll();
|
||||
$attributes=$this->ldap->listAttributesGroup();
|
||||
foreach($groups as $group) {
|
||||
if($group->getLdapfilter()) {
|
||||
$groups = $this->em->getRepository("App\Entity\Group")->findAll();
|
||||
$attributes = $this->ldap->listAttributesGroup();
|
||||
foreach ($groups as $group) {
|
||||
if ($group->getLdapfilter()) {
|
||||
$group->setLdapfilter(null);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$filter="gidnumber=".$group->getId();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->basegroup);
|
||||
if(empty($ldapentrys)) {
|
||||
$filter=str_replace("*",$group->getLabel(),$this->filtergroup);
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau01);
|
||||
$filter = 'gidnumber='.$group->getId();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->basegroup);
|
||||
if (empty($ldapentrys)) {
|
||||
$filter = str_replace('*', $group->getLabel(), $this->filtergroup);
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau01);
|
||||
}
|
||||
|
||||
if(empty($ldapentrys)) {
|
||||
$this->writeln($group->getLabel()." = SUBMIT");
|
||||
$this->ldap->addGroup($group);
|
||||
}
|
||||
elseif($this->ldap->ismodifyGroup($group,$ldapentrys[0])) {
|
||||
$this->writeln($group->getLabel()." = UPDATE");
|
||||
$this->ldap->modifyGroup($group,$ldapentrys[0]["cn"]);
|
||||
}
|
||||
}
|
||||
|
||||
$ldapentrys=$this->ldap->search($this->filtergroup,$attributes,$this->basegroup);
|
||||
foreach($ldapentrys as $ldapentry) {
|
||||
$group=$this->em->getRepository("App\Entity\Group")->find($ldapentry["gidnumber"]);
|
||||
if(!$group) {
|
||||
$this->writeln($ldapentry["cn"]." = DELETE");
|
||||
$dn=$this->ldap->getGroupDN($ldapentry["cn"]);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
if (empty($ldapentrys)) {
|
||||
$this->writeln($group->getLabel().' = SUBMIT');
|
||||
$this->ldap->addGroup($group);
|
||||
} elseif ($this->ldap->ismodifyGroup($group, $ldapentrys[0])) {
|
||||
$this->writeln($group->getLabel().' = UPDATE');
|
||||
$this->ldap->modifyGroup($group, $ldapentrys[0]['cn']);
|
||||
}
|
||||
}
|
||||
|
||||
$ldapentrys = $this->ldap->search($this->filtergroup, $attributes, $this->basegroup);
|
||||
foreach ($ldapentrys as $ldapentry) {
|
||||
$group = $this->em->getRepository("App\Entity\Group")->find($ldapentry['gidnumber']);
|
||||
if (!$group) {
|
||||
$this->writeln($ldapentry['cn'].' = DELETE');
|
||||
$dn = $this->ldap->getGroupDN($ldapentry['cn']);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== NIVEAU02 =========================================');
|
||||
$niveau02s=$this->em->getRepository("App\Entity\Niveau02")->findAll();
|
||||
$attributes=$this->ldap->listAttributesNiveau02();
|
||||
foreach($niveau02s as $niveau02) {
|
||||
$filter="gidnumber=".$niveau02->getId();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau02);
|
||||
if(empty($ldapentrys)) {
|
||||
$filter=str_replace("*",$niveau02->getLabel(),$this->filtergroup);
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau01);
|
||||
$niveau02s = $this->em->getRepository("App\Entity\Niveau02")->findAll();
|
||||
$attributes = $this->ldap->listAttributesNiveau02();
|
||||
foreach ($niveau02s as $niveau02) {
|
||||
$filter = 'gidnumber='.$niveau02->getId();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau02);
|
||||
if (empty($ldapentrys)) {
|
||||
$filter = str_replace('*', $niveau02->getLabel(), $this->filtergroup);
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau01);
|
||||
}
|
||||
|
||||
if(empty($ldapentrys)) {
|
||||
$this->writeln($niveau02->getLabel()." = SUBMIT");
|
||||
|
||||
if (empty($ldapentrys)) {
|
||||
$this->writeln($niveau02->getLabel().' = SUBMIT');
|
||||
$this->ldap->addNiveau02($niveau02);
|
||||
} elseif ($this->ldap->ismodifyNiveau02($niveau02, $ldapentrys[0])) {
|
||||
$this->writeln($niveau02->getLabel().' = UPDATE');
|
||||
$this->ldap->modifyNiveau02($niveau02, $ldapentrys[0]['cn']);
|
||||
}
|
||||
elseif($this->ldap->ismodifyNiveau02($niveau02,$ldapentrys[0])) {
|
||||
$this->writeln($niveau02->getLabel()." = UPDATE");
|
||||
$this->ldap->modifyNiveau02($niveau02,$ldapentrys[0]["cn"]);
|
||||
}
|
||||
}
|
||||
|
||||
$ldapentrys=$this->ldap->search($this->filtergroup,$attributes,$this->baseniveau02);
|
||||
foreach($ldapentrys as $ldapentry) {
|
||||
$niveau02=$this->em->getRepository("App\Entity\Niveau02")->find($ldapentry["gidnumber"]);
|
||||
if(!$niveau02) {
|
||||
$this->writeln($ldapentry["cn"]." = DELETE");
|
||||
$dn=$this->ldap->getNiveau02DN($ldapentry["cn"]);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
}
|
||||
|
||||
$ldapentrys = $this->ldap->search($this->filtergroup, $attributes, $this->baseniveau02);
|
||||
foreach ($ldapentrys as $ldapentry) {
|
||||
$niveau02 = $this->em->getRepository("App\Entity\Niveau02")->find($ldapentry['gidnumber']);
|
||||
if (!$niveau02) {
|
||||
$this->writeln($ldapentry['cn'].' = DELETE');
|
||||
$dn = $this->ldap->getNiveau02DN($ldapentry['cn']);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== NIVEAU01 =========================================');
|
||||
$niveau01s=$this->em->getRepository("App\Entity\Niveau01")->findAll();
|
||||
$attributes=$this->ldap->listAttributesNiveau01();
|
||||
foreach($niveau01s as $niveau01) {
|
||||
if($niveau01->getLdapfilter()) {
|
||||
$niveau01s = $this->em->getRepository("App\Entity\Niveau01")->findAll();
|
||||
$attributes = $this->ldap->listAttributesNiveau01();
|
||||
foreach ($niveau01s as $niveau01) {
|
||||
if ($niveau01->getLdapfilter()) {
|
||||
$niveau01->setLdapfilter(null);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$filter="gidnumber=".$niveau01->getId();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau01);
|
||||
if(empty($ldapentrys)) {
|
||||
$filter=str_replace("*",$niveau01->getLabel(),$this->filtergroup);
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau01);
|
||||
$filter = 'gidnumber='.$niveau01->getId();
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau01);
|
||||
if (empty($ldapentrys)) {
|
||||
$filter = str_replace('*', $niveau01->getLabel(), $this->filtergroup);
|
||||
$ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau01);
|
||||
}
|
||||
|
||||
if(empty($ldapentrys)) {
|
||||
$this->writeln($niveau01->getLabel()." = SUBMIT");
|
||||
if (empty($ldapentrys)) {
|
||||
$this->writeln($niveau01->getLabel().' = SUBMIT');
|
||||
$this->ldap->addNiveau01($niveau01);
|
||||
}
|
||||
elseif($this->ldap->ismodifyNiveau01($niveau01,$ldapentrys[0])) {
|
||||
$this->writeln($niveau01->getLabel()." = UPDATE");
|
||||
$this->ldap->modifyNiveau01($niveau01,$ldapentrys[0]["cn"]);
|
||||
} elseif ($this->ldap->ismodifyNiveau01($niveau01, $ldapentrys[0])) {
|
||||
$this->writeln($niveau01->getLabel().' = UPDATE');
|
||||
$this->ldap->modifyNiveau01($niveau01, $ldapentrys[0]['cn']);
|
||||
}
|
||||
}
|
||||
|
||||
$ldapentrys=$this->ldap->search($this->filtergroup,$attributes,$this->baseniveau01);
|
||||
foreach($ldapentrys as $ldapentry) {
|
||||
$niveau01=$this->em->getRepository("App\Entity\Niveau01")->find($ldapentry["gidnumber"]);
|
||||
if(!$niveau01) {
|
||||
$this->writeln($ldapentry["cn"]." = DELETE");
|
||||
$dn=$this->ldap->getNiveau01DN($ldapentry["cn"]);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
|
||||
$ldapentrys = $this->ldap->search($this->filtergroup, $attributes, $this->baseniveau01);
|
||||
foreach ($ldapentrys as $ldapentry) {
|
||||
$niveau01 = $this->em->getRepository("App\Entity\Niveau01")->find($ldapentry['gidnumber']);
|
||||
if (!$niveau01) {
|
||||
$this->writeln($ldapentry['cn'].' = DELETE');
|
||||
$dn = $this->ldap->getNiveau01DN($ldapentry['cn']);
|
||||
$this->ldap->deleteByDN($dn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function nine2nine()
|
||||
{
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:Synchro');
|
||||
$this->writelnred('== app:Synchro');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
|
||||
// Synchronisation ldap2nine possible uniquement si appMasteridentity=NINE
|
||||
if($this->appMasteridentity!="NINE") {
|
||||
$this->writeln("Synchronisation impossible si appMasteridentity!=NINE");
|
||||
if ('NINE' != $this->appMasteridentity) {
|
||||
$this->writeln('Synchronisation impossible si appMasteridentity!=NINE');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$nineurl = $this->container->getParameter("nineUrl");
|
||||
$ninesecret = $this->container->getParameter("nineSecret");
|
||||
if(!$nineurl||!$ninesecret) {
|
||||
$this->writeln("Synchronisation impossible soit parametres NINE_URL et/ou NINE_SECRET manquant");
|
||||
$nineurl = $this->container->getParameter('nineUrl');
|
||||
$ninesecret = $this->container->getParameter('nineSecret');
|
||||
if (!$nineurl || !$ninesecret) {
|
||||
$this->writeln('Synchronisation impossible soit parametres NINE_URL et/ou NINE_SECRET manquant');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$nineurl.="/rest/";
|
||||
$nineurl .= '/rest/';
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('=====================================================');
|
||||
$this->writeln('== SYNCHONISATION NINE TO NINE ======================');
|
||||
$this->writeln('=====================================================');
|
||||
|
||||
$nineniveau01s=$this->em->createQueryBuilder()->select('entity')->from('App:Niveau01','entity')->where('entity.idexternal IS NOT NULL')->getQuery()->getResult();
|
||||
$ninegroups=$this->em->createQueryBuilder()->select('entity')->from('App:Group','entity')->where('entity.idexternal IS NOT NULL')->getQuery()->getResult();
|
||||
$nineniveau01s = $this->em->createQueryBuilder()->select('entity')->from('App:Niveau01', 'entity')->where('entity.idexternal IS NOT NULL')->getQuery()->getResult();
|
||||
$ninegroups = $this->em->createQueryBuilder()->select('entity')->from('App:Group', 'entity')->where('entity.idexternal IS NOT NULL')->getQuery()->getResult();
|
||||
|
||||
$tbniveau01members=[];
|
||||
$tbgroupmembers=[];
|
||||
$tbniveau01s=[];
|
||||
$tbgroups=[];
|
||||
$tbusers=[];
|
||||
$tbniveau01members = [];
|
||||
$tbgroupmembers = [];
|
||||
$tbniveau01s = [];
|
||||
$tbgroups = [];
|
||||
$tbusers = [];
|
||||
|
||||
$fgsynchropurgeniveau01s = $this->synchropurgeniveau01;
|
||||
$fgsynchropurgegroups = $this->synchropurgegroup;
|
||||
$fgsynchropurgeusers = $this->synchropurgeuser;
|
||||
|
||||
$fgsynchropurgeniveau01s=($this->synchropurgeniveau01);
|
||||
$fgsynchropurgegroups=($this->synchropurgegroup);
|
||||
$fgsynchropurgeusers=($this->synchropurgeuser);
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== NIVEAU01 =========================================');
|
||||
|
||||
$response = $this->apiservice->run("GET",$nineurl."getAllNiveau01s",null,["key"=>$ninesecret]);
|
||||
if($response->code!="200") return Command::FAILURE;
|
||||
foreach($response->body as $nineniveau01 ) {
|
||||
$niveau01other=$this->em->getRepository("App\Entity\Niveau01")->findOneBy(["label"=>$nineniveau01->niveau01label]);
|
||||
if($niveau01other&&$niveau01other->getIdexternal()!=$nineniveau01->niveau01id) {
|
||||
$this->writelnred(" > ".$nineniveau01->niveau01label." = Impossible à synchroniser un autre niveau01 existe déjà avec ce label");
|
||||
|
||||
$response = $this->apiservice->run('GET', $nineurl.'getAllNiveau01s', null, ['key' => $ninesecret]);
|
||||
if ('200' != $response->code) {
|
||||
return Command::FAILURE;
|
||||
}
|
||||
foreach ($response->body as $nineniveau01) {
|
||||
$niveau01other = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $nineniveau01->niveau01label]);
|
||||
if ($niveau01other && $niveau01other->getIdexternal() != $nineniveau01->niveau01id) {
|
||||
$this->writelnred(' > '.$nineniveau01->niveau01label.' = Impossible à synchroniser un autre niveau01 existe déjà avec ce label');
|
||||
continue;
|
||||
}
|
||||
|
||||
// On recherche le groupe via le gid
|
||||
// On recherche le groupe via le gid
|
||||
$this->writeln(' > '.$nineniveau01->niveau01label);
|
||||
$niveau01=$this->em->getRepository("App\Entity\Niveau01")->findOneBy(["idexternal"=>$nineniveau01->niveau01id]);
|
||||
if(!$niveau01) {
|
||||
$niveau01=new Niveau01();
|
||||
$niveau01 = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['idexternal' => $nineniveau01->niveau01id]);
|
||||
if (!$niveau01) {
|
||||
$niveau01 = new Niveau01();
|
||||
$niveau01->setApikey(Uuid::uuid4());
|
||||
$this->em->persist($niveau01);
|
||||
}
|
||||
|
||||
$niveau01->setIdexternal($nineniveau01->niveau01id);
|
||||
$niveau01->setLabel($nineniveau01->niveau01label);
|
||||
$this->em->flush();
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
// Sauvegarde du niveau01nine
|
||||
array_push($tbniveau01s,$nineniveau01->niveau01label);
|
||||
array_push($tbniveau01s, $nineniveau01->niveau01label);
|
||||
|
||||
// Sauvegarde des membres du niveau01
|
||||
if(!empty($nineniveau01->niveau01users)) {
|
||||
foreach($nineniveau01->niveau01users as $member) {
|
||||
if(!array_key_exists($member->userlogin,$tbniveau01members)) $tbniveau01members[$member->userlogin]=[];
|
||||
array_push($tbniveau01members[$member->userlogin],$nineniveau01->niveau01label);
|
||||
if (!empty($nineniveau01->niveau01users)) {
|
||||
foreach ($nineniveau01->niveau01users as $member) {
|
||||
if (!array_key_exists($member->userlogin, $tbniveau01members)) {
|
||||
$tbniveau01members[$member->userlogin] = [];
|
||||
}
|
||||
array_push($tbniveau01members[$member->userlogin], $nineniveau01->niveau01label);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== GROUP ============================================');
|
||||
|
||||
$response = $this->apiservice->run("GET",$nineurl."getAllGroups",null,["key"=>$ninesecret]);
|
||||
if($response->code!="200") return Command::FAILURE;
|
||||
foreach($response->body as $ninegroup ) {
|
||||
$groupother=$this->em->getRepository("App\Entity\Group")->findOneBy(["label"=>$ninegroup->grouplabel]);
|
||||
if($groupother&&$groupother->getIdexternal()!=$ninegroup->groupid) {
|
||||
$this->writelnred(" > ".$ninegroup->grouplabel." = Impossible à synchroniser un autre group existe déjà avec ce label");
|
||||
$response = $this->apiservice->run('GET', $nineurl.'getAllGroups', null, ['key' => $ninesecret]);
|
||||
if ('200' != $response->code) {
|
||||
return Command::FAILURE;
|
||||
}
|
||||
foreach ($response->body as $ninegroup) {
|
||||
$groupother = $this->em->getRepository("App\Entity\Group")->findOneBy(['label' => $ninegroup->grouplabel]);
|
||||
if ($groupother && $groupother->getIdexternal() != $ninegroup->groupid) {
|
||||
$this->writelnred(' > '.$ninegroup->grouplabel.' = Impossible à synchroniser un autre group existe déjà avec ce label');
|
||||
continue;
|
||||
}
|
||||
|
||||
// On recherche le groupe via le gid
|
||||
// On recherche le groupe via le gid
|
||||
$this->writeln(' > '.$ninegroup->grouplabel);
|
||||
$group=$this->em->getRepository("App\Entity\Group")->findOneBy(["idexternal"=>$ninegroup->groupid]);
|
||||
if(!$group) {
|
||||
$group=new Group();
|
||||
$group = $this->em->getRepository("App\Entity\Group")->findOneBy(['idexternal' => $ninegroup->groupid]);
|
||||
if (!$group) {
|
||||
$group = new Group();
|
||||
$group->setIsopen(false);
|
||||
$group->setIsworkgroup(false);
|
||||
$group->setApikey(Uuid::uuid4());
|
||||
$group->setApikey(Uuid::uuid4());
|
||||
|
||||
$this->em->persist($group);
|
||||
}
|
||||
|
||||
$group->setIdexternal($ninegroup->groupid);
|
||||
$group->setLabel($ninegroup->grouplabel);
|
||||
$this->em->flush();
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
// Sauvegarde du groupnine
|
||||
array_push($tbgroups,$ninegroup->grouplabel);
|
||||
array_push($tbgroups, $ninegroup->grouplabel);
|
||||
|
||||
// Sauvegarde des membres du group
|
||||
if(!empty($ninegroup->groupusers)) {
|
||||
foreach($ninegroup->groupusers as $member) {
|
||||
if(!array_key_exists($member->userlogin,$tbgroupmembers)) $tbgroupmembers[$member->userlogin]=[];
|
||||
array_push($tbgroupmembers[$member->userlogin],$ninegroup->grouplabel);
|
||||
if (!empty($ninegroup->groupusers)) {
|
||||
foreach ($ninegroup->groupusers as $member) {
|
||||
if (!array_key_exists($member->userlogin, $tbgroupmembers)) {
|
||||
$tbgroupmembers[$member->userlogin] = [];
|
||||
}
|
||||
array_push($tbgroupmembers[$member->userlogin], $ninegroup->grouplabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->writeln('');
|
||||
$this->writeln('== USER =============================================');
|
||||
$response = $this->apiservice->run("GET",$nineurl."getAllUsers",null,["key"=>$ninesecret]);
|
||||
if($response->code!="200") return Command::FAILURE;
|
||||
$nineusers=$response->body;
|
||||
$response = $this->apiservice->run('GET', $nineurl.'getAllUsers', null, ['key' => $ninesecret]);
|
||||
if ('200' != $response->code) {
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$nineusers = $response->body;
|
||||
|
||||
foreach($nineusers as $nineuser) {
|
||||
$userother=$this->em->getRepository("App\Entity\User")->findOneBy(["email"=>$nineuser->useremail]);
|
||||
if($userother&&$userother->getUsername()!=$nineuser->userlogin) {
|
||||
$this->writelnred(" > ".$nineuser->userlogin." = Impossible à synchroniser un autre user existe déjà avec ce mail");
|
||||
foreach ($nineusers as $nineuser) {
|
||||
$userother = $this->em->getRepository("App\Entity\User")->findOneBy(['email' => $nineuser->useremail]);
|
||||
if ($userother && $userother->getUsername() != $nineuser->userlogin) {
|
||||
$this->writelnred(' > '.$nineuser->userlogin.' = Impossible à synchroniser un autre user existe déjà avec ce mail');
|
||||
continue;
|
||||
}
|
||||
$userother=$this->em->getRepository("App\Entity\Registration")->findOneBy(["email"=>$nineuser->useremail]);
|
||||
if($userother&&$userother->getUSername()!=$nineuser->userlogin) {
|
||||
$this->writelnred(" > ".$nineuser->userlogin." = Impossible à synchroniser un autre user existe déjà avec ce mail");
|
||||
$userother = $this->em->getRepository("App\Entity\Registration")->findOneBy(['email' => $nineuser->useremail]);
|
||||
if ($userother && $userother->getUSername() != $nineuser->userlogin) {
|
||||
$this->writelnred(' > '.$nineuser->userlogin.' = Impossible à synchroniser un autre user existe déjà avec ce mail');
|
||||
continue;
|
||||
}
|
||||
|
||||
// On recherche le user via le username
|
||||
$this->writeln(' > '.$nineuser->userlogin);
|
||||
$user=$this->em->getRepository("App\Entity\User")->findOneBy(["username"=>$nineuser->userlogin]);
|
||||
if(!$user) {
|
||||
$user=new User();
|
||||
$user = $this->em->getRepository("App\Entity\User")->findOneBy(['username' => $nineuser->userlogin]);
|
||||
if (!$user) {
|
||||
$user = new User();
|
||||
$user->setUsername($nineuser->userlogin);
|
||||
$user->setIsvisible(true);
|
||||
$user->setApikey(Uuid::uuid4());
|
||||
$user->setRole("ROLE_USER");
|
||||
$user->setRole('ROLE_USER');
|
||||
$user->setAvatar($nineuser->useravatar);
|
||||
|
||||
$uuid=Uuid::uuid4();
|
||||
$user->setPassword("PWD-".$nineuser->userlogin."-".$uuid);
|
||||
$uuid = Uuid::uuid4();
|
||||
$user->setPassword('PWD-'.$nineuser->userlogin.'-'.$uuid);
|
||||
|
||||
$this->em->persist($user);
|
||||
}
|
||||
|
||||
// Recherche du niveau01
|
||||
$niveau01=null;
|
||||
if($user->getNiveau01()&&empty($user->getNiveau01()->getIdexternal()))
|
||||
$niveau01=$user->getNiveau01();
|
||||
if(array_key_exists($nineuser->userlogin,$tbniveau01members))
|
||||
$niveau01=$this->em->getRepository("App\Entity\Niveau01")->findOneBy(["label"=>$tbniveau01members[$nineuser->userlogin][0]]);
|
||||
if(!$niveau01)
|
||||
$niveau01=$this->em->getRepository('App\Entity\Niveau01')->find(-1);
|
||||
$niveau01 = null;
|
||||
if ($user->getNiveau01() && empty($user->getNiveau01()->getIdexternal())) {
|
||||
$niveau01 = $user->getNiveau01();
|
||||
}
|
||||
if (array_key_exists($nineuser->userlogin, $tbniveau01members)) {
|
||||
$niveau01 = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $tbniveau01members[$nineuser->userlogin][0]]);
|
||||
}
|
||||
if (!$niveau01) {
|
||||
$niveau01 = $this->em->getRepository('App\Entity\Niveau01')->find(-1);
|
||||
}
|
||||
|
||||
// Mise à jour des attributs
|
||||
if(!empty($nineuser->userlastname)) $user->setLastname($nineuser->userlastname);
|
||||
if(!empty($nineuser->userfirstname)) $user->setFirstname($nineuser->userfirstname);
|
||||
if(!empty($nineuser->useremail)) $user->setEmail($nineuser->useremail);
|
||||
if(!empty($nineuser->useravatar)) $user->setAvatar($nineuser->useravatar);
|
||||
if (!empty($nineuser->userlastname)) {
|
||||
$user->setLastname($nineuser->userlastname);
|
||||
}
|
||||
if (!empty($nineuser->userfirstname)) {
|
||||
$user->setFirstname($nineuser->userfirstname);
|
||||
}
|
||||
if (!empty($nineuser->useremail)) {
|
||||
$user->setEmail($nineuser->useremail);
|
||||
}
|
||||
if (!empty($nineuser->useravatar)) {
|
||||
$user->setAvatar($nineuser->useravatar);
|
||||
}
|
||||
|
||||
// Mise à jour du niveau01
|
||||
if($niveau01!=$user->getNiveau01()) $user->setNiveau02(null);
|
||||
if ($niveau01 != $user->getNiveau01()) {
|
||||
$user->setNiveau02(null);
|
||||
}
|
||||
$user->setNiveau01($niveau01);
|
||||
|
||||
|
||||
// Mise à jour du role
|
||||
if(in_array($nineuser->userlogin,$this->container->getParameter("appAdmins")))
|
||||
$user->setRole("ROLE_ADMIN");
|
||||
if (in_array($nineuser->userlogin, $this->container->getParameter('appAdmins'))) {
|
||||
$user->setRole('ROLE_ADMIN');
|
||||
}
|
||||
|
||||
// Sauvegarde en bdd
|
||||
$this->em->flush();
|
||||
$this->em->flush();
|
||||
|
||||
// Sauvegarde du userldap
|
||||
array_push($tbusers,$nineuser->userlogin);
|
||||
array_push($tbusers, $nineuser->userlogin);
|
||||
|
||||
// Inscription au groupe
|
||||
if(array_key_exists($nineuser->userlogin,$tbgroupmembers)) {
|
||||
foreach($tbgroupmembers[$nineuser->userlogin] as $grouplabel) {
|
||||
$group=$this->em->getRepository("App\Entity\Group")->findOneBy(["label"=>$grouplabel]);
|
||||
if($group) {
|
||||
$usergroup=$this->em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$user,"group"=>$group]);
|
||||
if(!$usergroup) {
|
||||
$usergroup=new UserGroup();
|
||||
if (array_key_exists($nineuser->userlogin, $tbgroupmembers)) {
|
||||
foreach ($tbgroupmembers[$nineuser->userlogin] as $grouplabel) {
|
||||
$group = $this->em->getRepository("App\Entity\Group")->findOneBy(['label' => $grouplabel]);
|
||||
if ($group) {
|
||||
$usergroup = $this->em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
||||
if (!$usergroup) {
|
||||
$usergroup = new UserGroup();
|
||||
$usergroup->setUser($user);
|
||||
$usergroup->setGroup($group);
|
||||
$usergroup->setApikey(Uuid::uuid4());
|
||||
$usergroup->setRolegroup(0);
|
||||
$this->em->persist($usergroup);
|
||||
$this->em->flush();
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Desinscription des group ldap
|
||||
foreach($ninegroups as $group) {
|
||||
if(!array_key_exists($nineuser->userlogin,$tbgroupmembers)||!in_array($group->getLabel(),$tbgroupmembers[$nineuser->userlogin])) {
|
||||
$usergroup=$this->em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$user,"group"=>$group]);
|
||||
if($usergroup) {
|
||||
foreach ($ninegroups as $group) {
|
||||
if (!array_key_exists($nineuser->userlogin, $tbgroupmembers) || !in_array($group->getLabel(), $tbgroupmembers[$nineuser->userlogin])) {
|
||||
$usergroup = $this->em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
||||
if ($usergroup) {
|
||||
$this->em->remove($usergroup);
|
||||
$this->em->flush();
|
||||
}
|
||||
@ -846,16 +869,15 @@ class SynchroCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Purge des users
|
||||
if($fgsynchropurgeusers) {
|
||||
if ($fgsynchropurgeusers) {
|
||||
$this->writeln('');
|
||||
$this->writeln('== PURGE USER =============================================');
|
||||
|
||||
$users=$this->em->getRepository("App\Entity\User")->findAll();
|
||||
foreach($users as $user) {
|
||||
if(!in_array($user->getUsername(),$tbusers)) {
|
||||
if($user->getId()>0) {
|
||||
$users = $this->em->getRepository("App\Entity\User")->findAll();
|
||||
foreach ($users as $user) {
|
||||
if (!in_array($user->getUsername(), $tbusers)) {
|
||||
if ($user->getId() > 0) {
|
||||
$this->writeln(' > '.$user->getUsername());
|
||||
$this->em->remove($user);
|
||||
$this->em->flush();
|
||||
@ -865,17 +887,16 @@ class SynchroCommand extends Command
|
||||
}
|
||||
|
||||
// Purge des groups
|
||||
if($fgsynchropurgegroups) {
|
||||
if ($fgsynchropurgegroups) {
|
||||
$this->writeln('');
|
||||
$this->writeln('== PURGE GROUP =============================================');
|
||||
|
||||
foreach($ninegroups as $group) {
|
||||
if(!in_array($group->getLabel(),$tbgroups)) {
|
||||
if($group->getId()>0) {
|
||||
foreach ($ninegroups as $group) {
|
||||
if (!in_array($group->getLabel(), $tbgroups)) {
|
||||
if ($group->getId() > 0) {
|
||||
$this->writeln(' > '.$group->getLabel());
|
||||
$this->em->remove($group);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$group->setLdapfilter(null);
|
||||
$group->setIdexternal(null);
|
||||
}
|
||||
@ -883,27 +904,26 @@ class SynchroCommand extends Command
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Purge des niveau01s
|
||||
if($fgsynchropurgeniveau01s) {
|
||||
if ($fgsynchropurgeniveau01s) {
|
||||
$this->writeln('');
|
||||
$this->writeln('== PURGE NIVEAU01 =============================================');
|
||||
|
||||
foreach($nineniveau01s as $niveau01) {
|
||||
if(!in_array($niveau01->getLabel(),$tbniveau01s)) {
|
||||
if($niveau01->getId()>0) {
|
||||
$user=$this->em->getRepository("App\Entity\User")->findOneBy(["niveau01"=>$niveau01]);
|
||||
if($user) {
|
||||
$resetniveau01=$this->em->getRepository("App\Entity\User")->find(-1);
|
||||
foreach ($nineniveau01s as $niveau01) {
|
||||
if (!in_array($niveau01->getLabel(), $tbniveau01s)) {
|
||||
if ($niveau01->getId() > 0) {
|
||||
$user = $this->em->getRepository("App\Entity\User")->findOneBy(['niveau01' => $niveau01]);
|
||||
if ($user) {
|
||||
$resetniveau01 = $this->em->getRepository("App\Entity\User")->find(-1);
|
||||
$user->setNiveau01($resetniveau01);
|
||||
$user->setNiveau02(null);
|
||||
}
|
||||
|
||||
$this->writeln(' > '.$niveau01->getLabel());
|
||||
$this->em->remove($niveau01);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$niveau01->setLdapfilter(null);
|
||||
$niveau01->setIdexternal(null);
|
||||
}
|
||||
@ -911,59 +931,61 @@ class SynchroCommand extends Command
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
private function writelnred($string)
|
||||
{
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
|
||||
private function writeln($string) {
|
||||
|
||||
private function writeln($string)
|
||||
{
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
}
|
||||
|
||||
protected function addUser($niveau01,$username,$firstname,$lastname,$email,$usersadmin) {
|
||||
protected function addUser($niveau01, $username, $firstname, $lastname, $email, $usersadmin)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$user->setUsername($username);
|
||||
$user->setLastname($lastname);
|
||||
$user->setFirstname($firstname);
|
||||
$user->setEmail($email);
|
||||
$user->setEmail($email);
|
||||
$user->setNiveau01($niveau01);
|
||||
$user->setSiren($niveau01->getSiren());
|
||||
$user->setVisible(true);
|
||||
$user->setAuthlevel("simple");
|
||||
$user->setBelongingpopulation("agent");
|
||||
$user->setAuthlevel('simple');
|
||||
$user->setBelongingpopulation('agent');
|
||||
|
||||
$uuid=Uuid::uuid4();
|
||||
$user->setPassword("PWD-".$username."-".$uuid);
|
||||
$uuid = Uuid::uuid4();
|
||||
$user->setPassword('PWD-'.$username.'-'.$uuid);
|
||||
|
||||
if(in_array($username,$usersadmin))
|
||||
$user->setRole("ROLE_ADMIN");
|
||||
else {
|
||||
$user->setRole("ROLE_USER");
|
||||
}
|
||||
if (in_array($username, $usersadmin)) {
|
||||
$user->setRole('ROLE_ADMIN');
|
||||
} else {
|
||||
$user->setRole('ROLE_USER');
|
||||
}
|
||||
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
protected function modUser($user,$username,$firstname,$lastname,$email,$usersadmin) {
|
||||
protected function modUser($user, $username, $firstname, $lastname, $email, $usersadmin)
|
||||
{
|
||||
$user->setLastname($lastname);
|
||||
$user->setFirstname($firstname);
|
||||
$user->setEmail($email);
|
||||
|
||||
if(in_array($username,$usersadmin))
|
||||
$user->setRole("ROLE_ADMIN");
|
||||
if (in_array($username, $usersadmin)) {
|
||||
$user->setRole('ROLE_ADMIN');
|
||||
}
|
||||
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user