|
|
@ -7,22 +7,17 @@ use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Symfony\Component\Routing\RouterInterface;
|
|
|
|
|
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
|
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
|
|
|
|
|
|
|
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Entity\Group as Group;
|
|
|
|
use App\Entity\Group;
|
|
|
|
use App\Entity\User as User;
|
|
|
|
use App\Entity\User;
|
|
|
|
use App\Entity\Answer as Answer;
|
|
|
|
|
|
|
|
use App\Entity\Message as Message;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Service\mailService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SynchroUsersCommand extends Command
|
|
|
|
class SynchroUsersCommand extends Command
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private $container;
|
|
|
|
private $container;
|
|
|
|
private $router;
|
|
|
|
|
|
|
|
private $em;
|
|
|
|
private $em;
|
|
|
|
private $output;
|
|
|
|
private $output;
|
|
|
|
private $filesystem;
|
|
|
|
private $filesystem;
|
|
|
@ -30,15 +25,12 @@ class SynchroUsersCommand extends Command
|
|
|
|
private $ldap;
|
|
|
|
private $ldap;
|
|
|
|
private $ldap_basedn;
|
|
|
|
private $ldap_basedn;
|
|
|
|
private $ldapgroups=[];
|
|
|
|
private $ldapgroups=[];
|
|
|
|
private $mail;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct(ContainerInterface $container,EntityManagerInterface $em,RouterInterface $router, mailService $mail)
|
|
|
|
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
parent::__construct();
|
|
|
|
$this->container = $container;
|
|
|
|
$this->container = $container;
|
|
|
|
$this->em = $em;
|
|
|
|
$this->em = $em;
|
|
|
|
$this->router = $router;
|
|
|
|
|
|
|
|
$this->mail = $mail;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function configure()
|
|
|
|
protected function configure()
|
|
|
@ -110,6 +102,17 @@ class SynchroUsersCommand extends Command
|
|
|
|
$ldapusers = array();
|
|
|
|
$ldapusers = array();
|
|
|
|
$ldapmails = array();
|
|
|
|
$ldapmails = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Suppression des groupe ninegate
|
|
|
|
|
|
|
|
$groups=$this->em->getRepository("App:Group")->findAll();
|
|
|
|
|
|
|
|
foreach($groups as $group) {
|
|
|
|
|
|
|
|
if($group->getIdexternal()) {
|
|
|
|
|
|
|
|
$this->writeln(" - Suppression dans Bundle >> ".$group->getName());
|
|
|
|
|
|
|
|
if(!$simulate) {
|
|
|
|
|
|
|
|
$this->em->remove($group);
|
|
|
|
|
|
|
|
$this->em->flush();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($ldap_model=="scribe") {
|
|
|
|
if($ldap_model=="scribe") {
|
|
|
|
$this->writeln('');
|
|
|
|
$this->writeln('');
|
|
|
@ -155,6 +158,32 @@ class SynchroUsersCommand extends Command
|
|
|
|
if(!$simulate) $this->addmodGroup($label,$ldapfilter,true);
|
|
|
|
if(!$simulate) $this->addmodGroup($label,$ldapfilter,true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Elèves des Classes
|
|
|
|
|
|
|
|
$this->writeln('');
|
|
|
|
|
|
|
|
$this->writeln('== ELEVES DES CLASSES ==========================================');
|
|
|
|
|
|
|
|
$results = $this->ldap->search("type=Classe", ['cn','description','gidNumber'], $this->ldap_basedn);
|
|
|
|
|
|
|
|
foreach($results as $result) {
|
|
|
|
|
|
|
|
$cn=$result["cn"];
|
|
|
|
|
|
|
|
$ldapfilter="(&(type=Classe)(cn=$cn))";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$label="ELEVES - ".$result["cn"];
|
|
|
|
|
|
|
|
$this->writeln(" - $label");
|
|
|
|
|
|
|
|
if(!$simulate) $this->addmodGroup($label,$ldapfilter,false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Professeurs des Classes
|
|
|
|
|
|
|
|
$this->writeln('');
|
|
|
|
|
|
|
|
$this->writeln('== PROFESSEURS DES CLASSES ==========================================');
|
|
|
|
|
|
|
|
$results = $this->ldap->search("type=Classe", ['cn','description','gidNumber'], $this->ldap_basedn);
|
|
|
|
|
|
|
|
foreach($results as $result) {
|
|
|
|
|
|
|
|
$cn=$result["cn"];
|
|
|
|
|
|
|
|
$ldapfilter="(|(&(type=Equipe)(cn=profs-$cn))(&(ENTPersonProfils=Administratif)(divcod=$cn)))";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$label="PROFESSEURS - ".$result["cn"];
|
|
|
|
|
|
|
|
$this->writeln(" - $label");
|
|
|
|
|
|
|
|
if(!$simulate) $this->addmodGroup($label,$ldapfilter,false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Options
|
|
|
|
// Options
|
|
|
|
$this->writeln('');
|
|
|
|
$this->writeln('');
|
|
|
|
$this->writeln('== OPTIONS ==========================================');
|
|
|
|
$this->writeln('== OPTIONS ==========================================');
|
|
|
@ -387,15 +416,6 @@ class SynchroUsersCommand extends Command
|
|
|
|
$this->writeln('== GROUPS ============================================');
|
|
|
|
$this->writeln('== GROUPS ============================================');
|
|
|
|
$groups=$this->em->getRepository("App:Group")->findAll();
|
|
|
|
$groups=$this->em->getRepository("App:Group")->findAll();
|
|
|
|
foreach($groups as $group) {
|
|
|
|
foreach($groups as $group) {
|
|
|
|
if($group->getIdexternal()) {
|
|
|
|
|
|
|
|
$this->writeln(" - Suppression dans Bundle >> ".$group->getName());
|
|
|
|
|
|
|
|
if(!$simulate) {
|
|
|
|
|
|
|
|
$this->em->remove($group);
|
|
|
|
|
|
|
|
$this->em->flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!$group->getLdapfilter()) continue;
|
|
|
|
if(!$group->getLdapfilter()) continue;
|
|
|
|
|
|
|
|
|
|
|
|
if(!in_array($group->getId(),$this->ldapgroups)) {
|
|
|
|
if(!in_array($group->getId(),$this->ldapgroups)) {
|
|
|
@ -424,12 +444,25 @@ class SynchroUsersCommand extends Command
|
|
|
|
$this->writeln('== SYNCHONISATION NINEGATE TO BUNDLE ================');
|
|
|
|
$this->writeln('== SYNCHONISATION NINEGATE TO BUNDLE ================');
|
|
|
|
$this->writeln('=====================================================');
|
|
|
|
$this->writeln('=====================================================');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Suppression des groupe annuaire
|
|
|
|
|
|
|
|
$groups=$this->em->getRepository("App:Group")->findAll();
|
|
|
|
|
|
|
|
foreach($groups as $group) {
|
|
|
|
|
|
|
|
if($group->getLdapfilter()) {
|
|
|
|
|
|
|
|
$this->writeln(" - Suppression dans Bundle >> ".$group->getName());
|
|
|
|
|
|
|
|
if(!$simulate) {
|
|
|
|
|
|
|
|
$this->em->remove($group);
|
|
|
|
|
|
|
|
$this->em->flush();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$appmasterurl = $this->container->getParameter("appMasterurl");
|
|
|
|
$appmasterurl = $this->container->getParameter("appMasterurl");
|
|
|
|
$appmasterkey = $this->container->getParameter("appMasterkey");
|
|
|
|
$appmasterkey = $this->container->getParameter("appMasterkey");
|
|
|
|
|
|
|
|
|
|
|
|
// Généraltion de l'urol de communication
|
|
|
|
// Généraltion de l'urol de communication
|
|
|
|
if(stripos($appmasterurl,"/")===0) {
|
|
|
|
if(stripos($appmasterurl,"/")===0) {
|
|
|
|
$url="https://".$this->container->getParameter("appWeburl").$appmasterurl;
|
|
|
|
$url="http://".$this->container->getParameter("appWeburl").$appmasterurl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
$url=$appmasterurl;
|
|
|
|
$url=$appmasterurl;
|
|
|
@ -568,7 +601,7 @@ class SynchroUsersCommand extends Command
|
|
|
|
$this->writeln($group->getName());
|
|
|
|
$this->writeln($group->getName());
|
|
|
|
|
|
|
|
|
|
|
|
$usergroups=[];
|
|
|
|
$usergroups=[];
|
|
|
|
if(array_key_exists($group->getIdexternal(),$tabgroups)&&$tabgroups[$group->getIdexternal()])
|
|
|
|
if($tabgroups[$group->getIdexternal()])
|
|
|
|
$usergroups = $tabgroups[$group->getIdexternal()]["users"];
|
|
|
|
$usergroups = $tabgroups[$group->getIdexternal()]["users"];
|
|
|
|
$tbusers=[];
|
|
|
|
$tbusers=[];
|
|
|
|
foreach($usergroups as $user) {
|
|
|
|
foreach($usergroups as $user) {
|
|
|
@ -599,12 +632,6 @@ class SynchroUsersCommand extends Command
|
|
|
|
$this->em->persist($group);
|
|
|
|
$this->em->persist($group);
|
|
|
|
$this->em->flush();
|
|
|
|
$this->em->flush();
|
|
|
|
|
|
|
|
|
|
|
|
// On s'assure que l'ensemble des activité active soit bien distribué en fonction
|
|
|
|
|
|
|
|
$activitys=$this->em->getRepository("App:Activity")->findAllGroupActivityActive($group,true);
|
|
|
|
|
|
|
|
foreach($activitys as $activity) {
|
|
|
|
|
|
|
|
$this->initAnswer($activity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->writeln('');
|
|
|
|
$this->writeln('');
|
|
|
@ -637,15 +664,6 @@ class SynchroUsersCommand extends Command
|
|
|
|
$this->writeln('== GROUPS ============================================');
|
|
|
|
$this->writeln('== GROUPS ============================================');
|
|
|
|
$groups=$this->em->getRepository("App:Group")->findAll();
|
|
|
|
$groups=$this->em->getRepository("App:Group")->findAll();
|
|
|
|
foreach($groups as $group) {
|
|
|
|
foreach($groups as $group) {
|
|
|
|
if($group->getLdapfilter()) {
|
|
|
|
|
|
|
|
$this->writeln(" - Suppression dans Bundle >> ".$group->getName());
|
|
|
|
|
|
|
|
if(!$simulate) {
|
|
|
|
|
|
|
|
$this->em->remove($group);
|
|
|
|
|
|
|
|
$this->em->flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!$group->getIdexternal()) continue;
|
|
|
|
if(!$group->getIdexternal()) continue;
|
|
|
|
|
|
|
|
|
|
|
|
if(!in_array($group->getIdexternal(),$lstgroups)) {
|
|
|
|
if(!in_array($group->getIdexternal(),$lstgroups)) {
|
|
|
@ -696,12 +714,14 @@ class SynchroUsersCommand extends Command
|
|
|
|
|
|
|
|
|
|
|
|
protected function addUser($username,$firstname,$lastname,$email,$usersadmin) {
|
|
|
|
protected function addUser($username,$firstname,$lastname,$email,$usersadmin) {
|
|
|
|
$user = new User();
|
|
|
|
$user = new User();
|
|
|
|
|
|
|
|
$key = Uuid::uuid4();
|
|
|
|
|
|
|
|
|
|
|
|
$user->setUsername($username);
|
|
|
|
$user->setUsername($username);
|
|
|
|
$user->setPassword("NOPASSWORD");
|
|
|
|
$user->setPassword("NOPASSWORD");
|
|
|
|
$user->setLastname($lastname);
|
|
|
|
$user->setLastname($lastname);
|
|
|
|
$user->setFirstname($firstname);
|
|
|
|
$user->setFirstname($firstname);
|
|
|
|
$user->setEmail($email);
|
|
|
|
$user->setEmail($email);
|
|
|
|
|
|
|
|
$user->setApiKey($key);
|
|
|
|
|
|
|
|
|
|
|
|
// Definition du role
|
|
|
|
// Definition du role
|
|
|
|
if(in_array($username,$usersadmin))
|
|
|
|
if(in_array($username,$usersadmin))
|
|
|
@ -746,48 +766,4 @@ class SynchroUsersCommand extends Command
|
|
|
|
$this->em->flush();
|
|
|
|
$this->em->flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function initAnswer($activity) {
|
|
|
|
|
|
|
|
$em = $this->em;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pour chaque élève
|
|
|
|
|
|
|
|
$group=$activity->getGroup();
|
|
|
|
|
|
|
|
foreach($group->getUsers() as $user) {
|
|
|
|
|
|
|
|
// Existe-t-il une réponse pour l'élève
|
|
|
|
|
|
|
|
if($user->hasRole("ROLE_USER")) {
|
|
|
|
|
|
|
|
$answer=$em->getRepository("App:Answer")->findOneBy(["user"=>$user,"activity"=>$activity]);
|
|
|
|
|
|
|
|
if(!$answer) {
|
|
|
|
|
|
|
|
$answer=new Answer;
|
|
|
|
|
|
|
|
$answer->setActivity($activity);
|
|
|
|
|
|
|
|
$answer->setUser($user);
|
|
|
|
|
|
|
|
$answer->setStatus(-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$em->persist($answer);
|
|
|
|
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Message
|
|
|
|
|
|
|
|
$message=new Message;
|
|
|
|
|
|
|
|
$message->setMessage("Distribution de l'Activité");
|
|
|
|
|
|
|
|
$message->setDeletable(false);
|
|
|
|
|
|
|
|
$message->setUser($activity->getUser());
|
|
|
|
|
|
|
|
$message->setAnswer($answer);
|
|
|
|
|
|
|
|
$message->addReader($activity->getUser());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$em->persist($message);
|
|
|
|
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Notification par mail de la distribution de l'activité
|
|
|
|
|
|
|
|
$to = $user->getEmail();
|
|
|
|
|
|
|
|
$from = $activity->getUser()->getEmail();
|
|
|
|
|
|
|
|
$subject="Nineschool : Nouvelle Activité à réaliser";
|
|
|
|
|
|
|
|
$body ="Activité = ".$activity->getName()."<br>";
|
|
|
|
|
|
|
|
$body.="Professeur = ".$activity->getUser()->getDisplayname()."<br>";
|
|
|
|
|
|
|
|
$body.="Matière = ".$activity->getSubject()."<br>";
|
|
|
|
|
|
|
|
$body.="Url = ".$this->router->generate('app_answer_update', ["id"=>$answer->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->mail->sendEmail($subject, $body, $to, $from);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|