first commit symfony 6
This commit is contained in:
571
src/Command/InitCommand.php
Normal file
571
src/Command/InitCommand.php
Normal file
@ -0,0 +1,571 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
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;
|
||||
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $appname;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:Init')
|
||||
->setDescription('Init Data for App')
|
||||
->setHelp('This command Init Data App')
|
||||
;
|
||||
}
|
||||
|
||||
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->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();
|
||||
$group->setId(-1);
|
||||
$group->setLabel("Tout le monde");
|
||||
$group->setIsopen(false);
|
||||
$group->setIsworkgroup(false);
|
||||
$group->setApikey(Uuid::uuid4());
|
||||
$this->em->persist($group);
|
||||
$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();
|
||||
$niveau01->setId(-1);
|
||||
$niveau01->setLabel($this->appname);
|
||||
$niveau01->setApikey(Uuid::uuid4());
|
||||
$this->em->persist($niveau01);
|
||||
$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();
|
||||
$user->setId(-1);
|
||||
$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->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");
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
// colorbgbody = Couleur des fonds de page
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"site", // category
|
||||
"appname", // id
|
||||
"Titre de votre site", // title
|
||||
"", // value
|
||||
$this->appname, // default
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Titre de votre site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"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"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
3, // order
|
||||
"site", // category
|
||||
"appdescription", // id
|
||||
"Description de votre site", // title
|
||||
"", // value
|
||||
"", // default
|
||||
"editor", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Description de votre site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
100, // order
|
||||
"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é"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
200, // order
|
||||
"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"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
201, // order
|
||||
"site", // category
|
||||
"permannu", // id
|
||||
"Rôle accédant à l'annuaire", // title
|
||||
"", // value
|
||||
"ROLE_USER", // default
|
||||
"role", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"Détermine quel rôle aura la permission de voir l'annuaire"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
202, // order
|
||||
"site", // category
|
||||
"scopeannu", // id
|
||||
"Scope de l'annuaire", // title
|
||||
"", // value
|
||||
"ALL", // default
|
||||
"scopeannu", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // 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,
|
||||
false, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // 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,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // 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,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // 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,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // 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,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // 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,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // 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,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // 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,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // 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,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Nom de la police principale"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
3, // order
|
||||
"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"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
4, // order
|
||||
"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"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
5, // order
|
||||
"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"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
6, // order
|
||||
"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"
|
||||
);
|
||||
|
||||
// logo =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"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çé"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"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"
|
||||
);
|
||||
|
||||
|
||||
// header =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"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"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"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"
|
||||
);
|
||||
$output->writeln('');
|
||||
|
||||
|
||||
// Job de purge des fichiers obsolète
|
||||
// Toute les 24h à 3h00
|
||||
$entity = $this->em->getRepository('App\Entity\Cron')->findOneBy(["command"=>"app:Clean"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$nextdate=$entity->getSubmitdate();
|
||||
$nextdate->setTime(3,0);
|
||||
$entity->setCommand("app:Clean");
|
||||
$entity->setDescription("Nettoyage des données obsolètes");
|
||||
$entity->setStatut(1);
|
||||
$entity->setRepeatinterval(86400);
|
||||
$entity->setNextexecdate($nextdate);
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// 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->setStatut(1);
|
||||
$entity->setRepeatinterval(86400);
|
||||
$entity->setNextexecdate($nextdate);
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// 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->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();
|
||||
$entity->setId($id);
|
||||
$entity->setValue($value);
|
||||
}
|
||||
|
||||
$entity->setDefault($default);
|
||||
$entity->setCategory($category);
|
||||
$entity->setOrder($order);
|
||||
$entity->setTitle($title);
|
||||
$entity->setType($type);
|
||||
$entity->setVisible($visible);
|
||||
$entity->setChangeable($changeable);
|
||||
$entity->setRequired($required);
|
||||
$entity->setGrouped($grouped);
|
||||
$entity->setHelp($help);
|
||||
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user