systeme de script en moulinette sur reconfigure

This commit is contained in:
root 2020-07-10 11:07:42 +02:00
parent eb23661e1b
commit 54ffb73121
8 changed files with 202 additions and 7 deletions

View File

@ -15,10 +15,15 @@ if [ ! -f $DIR/.env ]; then
fi
# Installation des dépendances composer
composer install
echo COMPOSER = Install
composer install --quiet
php bin/console app:AppInit --env=prod
php bin/console app:CronInit --env=prod
php bin/console app:Script --env=prod
# Permissions
echo PERMISSIONS
./scripts/perm.sh www-data
echo

View File

@ -64,7 +64,7 @@ class DumpBddCommand extends Command
$result = $this->runCommand($cmd);
if($result['exit_status'] == 0) {
$this->filesystem->dumpFile($this->rootlog.$alias.".sql", $result['output']);
$this->filesystem->dumpFile($this->rootlog.$alias.".sql", implode('', $result['output']));
}
$this->writeln('');

View File

@ -0,0 +1,89 @@
<?php
namespace App\Command;
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\Console\Input\ArrayInput;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Id\AssignedGenerator;
use App\Entity\Script;
class ScriptCommand extends Command
{
private $container;
private $em;
private $output;
private $filesystem;
private $rootlog;
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
{
parent::__construct();
$this->container = $container;
$this->em = $em;
}
protected function configure()
{
$this
->setName('app:Script')
->setDescription('Script to call')
->setHelp('Script to call')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->output = $output;
$this->filesystem = new Filesystem();
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
$output->writeln('APP = Scripts');
//$this->callscript("test");
$output->writeln('');
return 1;
}
private function callscript($name) {
$script=$this->em->getRepository("App:Script")->findOneBy(["name"=>$name]);
if(!$script) {
$this->writelnred("== SCRIPT = ".$name);
$this->$name();
$script=new Script();
$script->setName($name);
$this->em->persist($script);
$this->em->flush();
$this->writeln("");
}
}
private function test() {
$this->writeln("TEST");
}
private function writelnred($string) {
$this->output->writeln('<fg=red>'.$string.'</>');
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
private function writeln($string) {
$this->output->writeln($string);
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
}

View File

@ -36,8 +36,8 @@ class SynchroUsersCommand extends Command
{
$this
->setName('app:synchroUsers')
->setDescription('Synchronisation des Utilisateurs via un annuaire scribe')
->setHelp('Synchronisation des Utilisateurs via un annuaire scribe')
->setDescription('Synchronisation des Utilisateurs')
->setHelp('Synchronisation des Utilisateurs')
->addArgument('simulate', InputArgument::OPTIONAL, 'true to simulate / false to run')
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
@ -106,6 +106,33 @@ class SynchroUsersCommand extends Command
$this->writeln('');
$this->writeln('== SCRIBE ===========================================');
$this->writeln('');
$this->writeln('== PROFILS ==========================================');
// Eleves
$ldapfilter="(&(uid=*)(ENTPersonProfils=eleve))";
$label="PROFIL - Elèves";
$this->writeln(" - $label");
if(!$simulate) $this->addmodGroup($label,$ldapfilter,false);
// Enseignants
$ldapfilter="(|(&(uid=*)(ENTPersonProfils=enseignant))(&(uid=*)(typeadmin=0))(&(uid=*)(typeadmin=2)))";
$label="PROFIL - Enseignants";
$this->writeln(" - $label");
if(!$simulate) $this->addmodGroup($label,$ldapfilter,true);
// Responsables
$ldapfilter="(&(uid=*)(ENTPersonProfils=responsable))";
$label="PROFIL - Responsables";
$this->writeln(" - $label");
if(!$simulate) $this->addmodGroup($label,$ldapfilter,false);
// Administratifs
$ldapfilter="(&(uid=*)(ENTPersonProfils=administratif))";
$label="PROFIL - Administratifs";
$this->writeln(" - $label");
if(!$simulate) $this->addmodGroup($label,$ldapfilter,true);
// Classes
$this->writeln('');
$this->writeln('== CLASSES ==========================================');
@ -114,7 +141,7 @@ class SynchroUsersCommand extends Command
$cn=$result["cn"];
$ldapfilter="(|(&(type=Classe)(cn=$cn))(&(type=Equipe)(cn=profs-$cn))(&(ENTPersonProfils=Administratif)(divcod=$cn)))";
$label="CLASSE = ".$result["cn"];
$label="CLASSE - ".$result["cn"];
$this->writeln(" - $label");
if(!$simulate) $this->addmodGroup($label,$ldapfilter,true);
}
@ -127,7 +154,7 @@ class SynchroUsersCommand extends Command
foreach($results as $result) {
$ldapfilter="(|(&(type=Option)(cn=$cn))(&(type=Equipe)(cn=profs-$cn))(&(ENTPersonProfils=Administratif)(divcod=$cn)))";
$label="OPTION = ".$result["cn"];
$label="OPTION - ".$result["cn"];
$this->writeln(" - $label");
if(!$simulate) $this->addmodGroup($label,$ldapfilter,true);
}
@ -148,7 +175,7 @@ class SynchroUsersCommand extends Command
$cn=$result["cn"];
$ldapfilter="(&(&".$ldap_filtergroup.")(cn=$cn))";
$label="GROUPE = ".$result["cn"];
$label="GROUPE - ".$result["cn"];
$this->writeln(" - $label");
if(!$simulate) $this->addmodGroup($label,$ldapfilter,true);
}

View File

@ -164,6 +164,15 @@ class GroupController extends AbstractController
if ($form->get('submit')->isClicked() && $mode=="submit") {
}
if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) {
// On s'assure que le label ne contient pas des caractères speciaux
$string = preg_replace('~[^ éèêôöàïî\'@a-zA-Z0-9._-]~', '', $data->getName());
if($string!=$data->getName())
{
$form->addError(new FormError('Caractères interdit dans ce label'));
}
}
if ($form->get('submit')->isClicked() && !$form->isValid()) {
$this->get('session')->getFlashBag()->clear();

View File

@ -0,0 +1,50 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Script
*
* @ORM\Table(name="script")
* @ORM\Entity(repositoryClass="App\Repository\ScriptRepository")
*/
class Script
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", nullable=false)
* @Assert\NotBlank()
*
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Repository;
use App\Entity\Script;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
class ScriptRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Script::class);
}
}