init
This commit is contained in:
621
src/Command/AppInitCommand.php
Normal file
621
src/Command/AppInitCommand.php
Normal file
@ -0,0 +1,621 @@
|
||||
<?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 Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Config;
|
||||
|
||||
class AppInitCommand extends Command
|
||||
{
|
||||
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $appname;
|
||||
private $appmailnoreply;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:AppInit')
|
||||
->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->appmailnoreply = $this->container->getParameter('appMailnoreply');
|
||||
|
||||
$output->writeln('APP = Default Data');
|
||||
|
||||
// Création du compte admin si non existant
|
||||
$this->insertUser("admin","admin");
|
||||
|
||||
// Création d'une catégory par défaut
|
||||
$this->insertCategory(-100,1,"Illustrations");
|
||||
|
||||
// colorbgbody = Couleur des fonds de page
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"site", // category
|
||||
"appname", // id
|
||||
"Titre de votre site", // title
|
||||
"", // value
|
||||
"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
|
||||
"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
|
||||
"editor", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Description de votre site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
4, // order
|
||||
"site", // category
|
||||
"appthumbwidth", // id
|
||||
"Largeur des miniatures", // title
|
||||
"0", // value
|
||||
"thumbwidth", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"" , // grouped
|
||||
"Largeur des miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
5, // order
|
||||
"site", // category
|
||||
"appthumbheight", // id
|
||||
"Hauteur des miniatures", // title
|
||||
"0", // value
|
||||
"thumbheight", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"" , // grouped
|
||||
"Largeur des miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
6, // order
|
||||
"site", // category
|
||||
"appthumbfilter", // id
|
||||
"Filtre sur les miniatures", // title
|
||||
"0", // value
|
||||
"boolean", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"" , // grouped
|
||||
"Filtre sur les miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
7, // order
|
||||
"site", // category
|
||||
"appthumbfiltergrayscale", // id
|
||||
"Filtre grayscale sur les miniatures", // title
|
||||
"100", // value
|
||||
"pourcentage", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"appthumbfilter" , // grouped
|
||||
"Filtre grayscale sur les miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
8, // order
|
||||
"site", // category
|
||||
"appthumbfilteropacity", // id
|
||||
"Filtre opacity sur les miniatures", // title
|
||||
"100", // value
|
||||
"pourcentage", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"appthumbfilter" , // grouped
|
||||
"Filtre opacity sur les miniatures"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
9, // order
|
||||
"site", // category
|
||||
"appthumbfiltersepia", // id
|
||||
"Filtre sepia sur les miniatures", // title
|
||||
"0", // value
|
||||
"pourcentage", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"appthumbfilter" , // grouped
|
||||
"Filtre sepia sur les miniatures"
|
||||
);
|
||||
|
||||
|
||||
$this->insertConfig(
|
||||
10, // order
|
||||
"site", // category
|
||||
"appmaxthumbwidth", // id
|
||||
"Largeur maximum de la grille des thumbs", // title
|
||||
"0", // value
|
||||
"integer", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"" , // grouped
|
||||
"Largeur maximum de la grille des thumbs\n0 pour indiquer qu'il n'y a pas de taille maximum"
|
||||
);
|
||||
|
||||
// colorbgbody = Couleur des fonds de page
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"colorbgbody", // category
|
||||
"colorbgbodydark", // id
|
||||
"Couleur de fond fonçée", // title
|
||||
"#343a40", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // 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
|
||||
"#ffffff", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // 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
|
||||
"#ffffff", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"La couleur des titres sur fond fonçé"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"colorfttitle", // category
|
||||
"colorfttitlelight", // id
|
||||
"Couleur des titres sur fond claire", // title
|
||||
"#343a40", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // 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
|
||||
"#ffffff", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // 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
|
||||
"#343a40", // value
|
||||
"color", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // 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
|
||||
"FredokaOne-Regular", // value
|
||||
"font", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"La couleur de la police de votre site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"font", // category
|
||||
"fontbody", // id
|
||||
"Police principale", // title
|
||||
"Roboto-Regular", // value
|
||||
"font", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
true, // required
|
||||
"", // grouped
|
||||
"Nom de la police principale"
|
||||
);
|
||||
|
||||
// logo =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"logo", // category
|
||||
"logodark", // id
|
||||
"Logo sur fond fonçé", // title
|
||||
"", // value
|
||||
"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", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Logo sur fond clair"
|
||||
);
|
||||
|
||||
// image =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"image", // category
|
||||
"imgcontact", // id
|
||||
"Image Contact", // title
|
||||
"", // value
|
||||
"image", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image associée à la section contact"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"image", // category
|
||||
"imglink", // id
|
||||
"Image Liens", // title
|
||||
"", // value
|
||||
"image", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image associée à la section liens"
|
||||
);
|
||||
|
||||
// hero =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"hero", // category
|
||||
"hero01", // id
|
||||
"Carrousel 01", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 01 de votre carrousel"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"hero", // category
|
||||
"hero02", // id
|
||||
"Carrousel 02", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 02 de votre carrousel"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
3, // order
|
||||
"hero", // category
|
||||
"hero03", // id
|
||||
"Carrousel 03", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 03 de votre carrousel"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
4, // order
|
||||
"hero", // category
|
||||
"hero04", // id
|
||||
"Carrousel 04", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 04 de votre carrousel"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
5, // order
|
||||
"hero", // category
|
||||
"hero05", // id
|
||||
"Carrousel 05", // title
|
||||
"", // value
|
||||
"hero", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Image 05 de votre carrousel"
|
||||
);
|
||||
|
||||
// Social =
|
||||
$this->insertConfig(
|
||||
1, // order
|
||||
"social", // category
|
||||
"email", // id
|
||||
"Email", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"L'email du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
2, // order
|
||||
"social", // category
|
||||
"facebook", // id
|
||||
"Facebook", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Facebook du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
3, // order
|
||||
"social", // category
|
||||
"instagram", // id
|
||||
"Instagram", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Instagram du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
4, // order
|
||||
"social", // category
|
||||
"twitter", // id
|
||||
"Twitter", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Twitter du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
5, // order
|
||||
"social", // category
|
||||
"google", // id
|
||||
"Google", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Google du site"
|
||||
);
|
||||
|
||||
$this->insertConfig(
|
||||
6, // order
|
||||
"social", // category
|
||||
"youtube", // id
|
||||
"Youtube", // title
|
||||
"", // value
|
||||
"string", // type,
|
||||
true, // visible
|
||||
true, // changeable
|
||||
false, // required
|
||||
"", // grouped
|
||||
"Le Youtube du site"
|
||||
);
|
||||
|
||||
$output->writeln('');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
protected function insertUser() {
|
||||
$metadata = $this->em->getClassMetaData('App:User');
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
|
||||
// Création du compte admin par défaut
|
||||
$entity = $this->em->getRepository('App:User')->findOneBy(["username"=>"admin"]);
|
||||
if(!$entity) {
|
||||
$this->writelnred('Création du compte admin par défaut avec password admin - Veuillez modifier votre password admin après connexion');
|
||||
$entity = new User;
|
||||
$entity->setId(-100);
|
||||
$entity->setUsername("admin");
|
||||
$entity->setPassword("admin");
|
||||
$entity->setFirstname($this->appname);
|
||||
$entity->setLastname("Admin");
|
||||
$entity->setEmail($this->appmailnoreply);
|
||||
$entity->setRoles(["ROLE_ADMIN"]);
|
||||
$entity->setAvatar("admin.jpg");
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// On flush
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
protected function insertCategory($id,$order,$name) {
|
||||
$metadata = $this->em->getClassMetaData('App:Category');
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
|
||||
// Création du compte admin par défaut
|
||||
$entity = $this->em->getRepository('App:Category')->find($id);
|
||||
if(!$entity) {
|
||||
$entity = new Category;
|
||||
$entity->setId($id);
|
||||
$entity->setOrder($order);
|
||||
$entity->setName($name);
|
||||
$entity->setUsecategoryconfig(false);
|
||||
$entity->setAppthumbfilter(false);
|
||||
$entity->setAppthumbheight(0);
|
||||
$entity->setAppthumbwidth(0);
|
||||
$entity->setAppthumbfilter(false);
|
||||
$entity->setAppthumbfiltergrayscale(100);
|
||||
$entity->setAppthumbfilteropacity(100);
|
||||
$entity->setAppthumbfiltersepia(0);
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// On flush
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
protected function insertConfig($order,$category,$id,$title,$value,$type,$visible,$changeable,$required,$grouped,$help) {
|
||||
$entity=$this->em->getRepository("App:Config")->find($id);
|
||||
if(!$entity) {
|
||||
$entity= new Config();
|
||||
$entity->setId($id);
|
||||
$entity->setValue($value);
|
||||
}
|
||||
|
||||
$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");
|
||||
}
|
||||
}
|
165
src/Command/CronCommand.php
Normal file
165
src/Command/CronCommand.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?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 Symfony\Component\Console\Command\LockableTrait;
|
||||
|
||||
use App\Entity\Cron;
|
||||
|
||||
class CronCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
use LockableTrait;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:Cron')
|
||||
->setDescription('Execution of the cron command')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
$appCron = $this->container->getParameter('appCron');
|
||||
if(!$appCron)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!$this->lock()) {
|
||||
$this->output->writeln("CRON LOCK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$crons = $this->em->getRepository('App:Cron')->toexec();
|
||||
$i=0;
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
foreach($crons as $cron) {
|
||||
$i++;
|
||||
|
||||
// Id du cron
|
||||
$idcron = $cron->getId();
|
||||
|
||||
// Flag d'execution en cours
|
||||
$now=new \DateTime();
|
||||
$cron->setStartexecdate($now);
|
||||
//$cron->setStatut(1);
|
||||
$this->em->persist($cron);
|
||||
$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);
|
||||
|
||||
// Parametre id du cron actuel
|
||||
$jsonparameter["cronid"]=$cron->getId();
|
||||
|
||||
// Parametre si dernière execution
|
||||
$lastchance=false;
|
||||
if($cron->getRepeatcall()>0)
|
||||
$lastchance=($cron->getRepeatexec()+1==$cron->getRepeatcall());
|
||||
$jsonparameter["lastchance"]=$lastchance;
|
||||
|
||||
// Formater la chaine de parametre
|
||||
$parameter = new ArrayInput($jsonparameter);
|
||||
|
||||
// Executer la commande
|
||||
$returnCode=false;
|
||||
try{
|
||||
$returnCode = $command->run($parameter, $output);
|
||||
|
||||
// Revenir sur le cron encours à cause du clear du manager présent dans la synchro
|
||||
// Sinon le manager se pomme et génère des nouveaux enregistrement plutot que mettre à jour celui en cours
|
||||
$cron=$this->em->getRepository('App:Cron')->find($idcron);
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->writelnred("JOB EN ERREUR");
|
||||
}
|
||||
|
||||
// Flag de fin d'execution
|
||||
$now=new \DateTime();
|
||||
$cron->setEndexecdate($now);
|
||||
|
||||
// Date prochaine execution
|
||||
if($cron->getrepeatinterval()>=0) {
|
||||
// Si interval par heure
|
||||
if(fmod($cron->getRepeatinterval(),3600)==0)
|
||||
$next=clone $cron->getNextexecdate();
|
||||
else
|
||||
$next=new \DateTime();
|
||||
|
||||
$next->add(new \DateInterval('PT'.$cron->getRepeatinterval().'S'));
|
||||
$cron->setNextexecdate($next);
|
||||
}
|
||||
|
||||
// Statut OK/KO/Retry
|
||||
if($returnCode!="retry"||!$returnCode) {
|
||||
$cron->setStatut(2);
|
||||
if($returnCode!=1) {
|
||||
$cron->setStatut(3);
|
||||
if($cron->getRepeatcall()>0) $cron->setRepeatexec($cron->getRepeatexec()+1);
|
||||
}
|
||||
}
|
||||
|
||||
$this->em->persist($cron);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
if($crons) {
|
||||
$this->writelnred("==");
|
||||
$this->writelnred("FIN CRON");
|
||||
$this->writelnred("==");
|
||||
$this->writelnred("");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
119
src/Command/CronInitCommand.php
Normal file
119
src/Command/CronInitCommand.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?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 Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
|
||||
use App\Entity\Cron;
|
||||
|
||||
|
||||
class CronInitCommand 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:CronInit')
|
||||
->setDescription('Init Data for Cron')
|
||||
->setHelp('This command Init Data Cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$appCron = $this->container->getParameter('appCron');
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
if(!$appCron)
|
||||
return false;
|
||||
|
||||
$output->writeln('CRON = Default Data');
|
||||
|
||||
$this->insertCron();
|
||||
|
||||
$output->writeln('');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
protected function insertCron() {
|
||||
|
||||
$metadata = $this->em->getClassMetaData('App:Cron');
|
||||
|
||||
// Job Mail
|
||||
// Toute les minutes
|
||||
$entity = $this->em->getRepository('App:Cron')->findOneBy(["command"=>"app:sendMail"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$entity->setCommand("app:sendMail");
|
||||
$entity->setDescription("Execution du spool de mail en attente");
|
||||
$entity->setStatut(2);
|
||||
$entity->setRepeatcall(0);
|
||||
$entity->setRepeatexec(0);
|
||||
$entity->setRepeatinterval(60);
|
||||
$entity->setNextexecdate($entity->getSubmitdate());
|
||||
$entity->setJsonargument('{"message-limit":"100","env":"prod"}');
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// Job de purge des fichiers obsolète
|
||||
// Toute les 24h à 3h00
|
||||
$entity = $this->em->getRepository('App:Cron')->findOneBy(["command"=>"app:purgeFile"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$nextdate=$entity->getSubmitdate();
|
||||
$nextdate->setTime(3,0);
|
||||
$entity->setCommand("app:purgeFile");
|
||||
$entity->setDescription("Suppression des fichiers obsolètes");
|
||||
$entity->setStatut(2);
|
||||
$entity->setRepeatcall(0);
|
||||
$entity->setRepeatexec(0);
|
||||
$entity->setRepeatinterval(86400);
|
||||
$entity->setNextexecdate($nextdate);
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// Job Dump
|
||||
// Toute les 24h à 2h00
|
||||
$entity = $this->em->getRepository('App:Cron')->findOneBy(["command"=>"app:dumpBdd"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$nextdate=$entity->getSubmitdate();
|
||||
$nextdate->setTime(2,0);
|
||||
$entity->setCommand("app:dumpBdd");
|
||||
$entity->setDescription("Sauvegarde de la BDD");
|
||||
$entity->setStatut(2);
|
||||
$entity->setRepeatcall(0);
|
||||
$entity->setRepeatexec(0);
|
||||
$entity->setRepeatinterval(86400);
|
||||
$entity->setNextexecdate($nextdate);
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
// On flush
|
||||
$this->em->flush();
|
||||
|
||||
}
|
||||
}
|
92
src/Command/DumpBddCommand.php
Normal file
92
src/Command/DumpBddCommand.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?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\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class DumpBddCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $byexec;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:dumpBdd')
|
||||
->setDescription('Sauvegarde de la BDD')
|
||||
->setHelp('Sauvegarde de la BDD')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$alias = $this->container->getParameter('appAlias');
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:dumpBdd');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$this->datahost = $this->container->getParameter('databaseHost');
|
||||
$this->database = $this->container->getParameter('databaseName') ;
|
||||
$this->username = $this->container->getParameter('databaseUser') ;
|
||||
$this->password = $this->container->getParameter('databasePassword') ;
|
||||
|
||||
$cmd = sprintf('mysqldump -h %s -B %s -u %s --password=%s'
|
||||
, $this->datahost
|
||||
, $this->database
|
||||
, $this->username
|
||||
, $this->password
|
||||
);
|
||||
|
||||
$result = $this->runCommand($cmd);
|
||||
if($result['exit_status'] == 0) {
|
||||
$this->filesystem->dumpFile($this->rootlog.$alias.".sql", implode('', $result['output']));
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected function runCommand($command)
|
||||
{
|
||||
$command .=" >&1";
|
||||
exec($command, $output, $exit_status);
|
||||
return array(
|
||||
"output" => $output
|
||||
, "exit_status" => $exit_status
|
||||
);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
105
src/Command/PurgeFileCommand.php
Normal file
105
src/Command/PurgeFileCommand.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?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\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class PurgeFileCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $byexec;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:purgeFile')
|
||||
->setDescription('Suppression des fichier obsolètes')
|
||||
->setHelp('Suppression des fichier obsolètes')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$alias = $this->container->getParameter('appAlias');
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:purgeFile');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$now=new \DateTime('now');
|
||||
|
||||
$directory=$this->container->get('kernel')->getProjectDir()."/public/uploads/avatar";
|
||||
$this->writeln($directory);
|
||||
|
||||
$files=[];
|
||||
$fs = new Filesystem();
|
||||
|
||||
if($fs->exists($directory)) {
|
||||
$finder = new Finder();
|
||||
$finder->in($directory)->files();
|
||||
|
||||
foreach (iterator_to_array($finder) as $file) {
|
||||
$name = $file->getRelativePathname();
|
||||
if($name!="admin.jpg"&&$name!="noavatar.png"&&$name!="system.jpg") {
|
||||
$entity=$this->em->getRepository("App:User")->findBy(["avatar"=>$name]);
|
||||
if(!$entity) {
|
||||
$this->writeln($name);
|
||||
$url=$directory."/".$name;
|
||||
if($fs->exists($url)) {
|
||||
$fs->remove($url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fs = new Filesystem();
|
||||
$users=$this->em->getRepository("App:User")->findAll();
|
||||
foreach($users as $user) {
|
||||
if(!$fs->exists($directory."/".$user->getAvatar())) {
|
||||
$this->writeln($user->getUsername());
|
||||
$user->setAvatar("noavatar.png");
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
157
src/Command/RegenThumbCommand.php
Normal file
157
src/Command/RegenThumbCommand.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?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\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class RegenThumbCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $byexec;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:regenthumb')
|
||||
->setDescription('Regénère les thumbs des illustrations')
|
||||
->setHelp('Regénère les thumbs des illustrations')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$alias = $this->container->getParameter('appAlias');
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:regenthumb');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$now=new \DateTime('now');
|
||||
|
||||
$directory=$this->container->get('kernel')->getProjectDir()."/public/uploads/illustration";
|
||||
$this->writeln($directory);
|
||||
|
||||
$files=[];
|
||||
$fs = new Filesystem();
|
||||
|
||||
if($fs->exists($directory)) {
|
||||
$finder = new Finder();
|
||||
$finder->in($directory)->files();
|
||||
|
||||
foreach (iterator_to_array($finder) as $file) {
|
||||
$name = $file->getRelativePathname();
|
||||
if(stripos($name,"thumb_")===false&&stripos($name,"thumbori_")===false) {
|
||||
$width = $this->getWidth($directory.'/'.$name);
|
||||
$height = $this->getHeight($directory.'/'.$name);
|
||||
|
||||
// Création des miniatures proportionnelle
|
||||
$fs->remove($directory.'/thumbori_'.$name);
|
||||
$fs->copy($directory.'/'.$name,$directory.'/thumbori_'.$name);
|
||||
$max_width=500;
|
||||
$scale = $max_width/$width;
|
||||
$this->resizeImage($directory.'/thumbori_'.$name,$width,$height,$scale);
|
||||
|
||||
$this->writeln($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
protected function getHeight($image) {
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
return $height;
|
||||
}
|
||||
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image) {
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
return $width;
|
||||
}
|
||||
|
||||
protected function resizeImage($image,$width,$height,$scale) {
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
|
||||
$newImage = imagecreatetruecolor( $newImageWidth, $newImageHeight );
|
||||
imagealphablending( $newImage, false );
|
||||
imagesavealpha( $newImage, true );
|
||||
imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
imagejpeg($newImage,$image,90);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$image);
|
||||
break;
|
||||
}
|
||||
|
||||
chmod($image, 0640);
|
||||
chown($image, 'www-data');
|
||||
return $image;
|
||||
}
|
||||
}
|
89
src/Command/ScriptCommand.php
Normal file
89
src/Command/ScriptCommand.php
Normal 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");
|
||||
}
|
||||
}
|
87
src/Command/SendMailCommand.php
Normal file
87
src/Command/SendMailCommand.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
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\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
|
||||
class SendMailCommand 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:sendMail')
|
||||
->setDescription('Envoi des mails')
|
||||
->setHelp('Envoi des mails')
|
||||
->addArgument('message-limit', InputArgument::OPTIONAL, 'limit message Mail')
|
||||
->addArgument('env', InputArgument::OPTIONAL, 'env Mail')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:sendMail');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$appMailmethod=$this->container->getParameter("appMailmethod");
|
||||
|
||||
$command = $this->getApplication()->find("swiftmailer:spool:send");
|
||||
$tbparameter["--message-limit"]=100;
|
||||
$tbparameter["--env"]="prod";
|
||||
$tbparameter["--time-limit"]=5;
|
||||
if($appMailmethod=="sendmail") $tbparameter["--transport"]="app.sendmail.transport";
|
||||
|
||||
|
||||
$parameter = new ArrayInput($tbparameter);
|
||||
try{
|
||||
$returnCode = $command->run($parameter, $output);
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->writeln("");
|
||||
$this->writelnred("Impossible d'envoyer des mails");
|
||||
$this->writeln("");
|
||||
return 0;
|
||||
}
|
||||
$this->writeln("");
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
81
src/Command/SetPasswordCommand.php
Normal file
81
src/Command/SetPasswordCommand.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?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\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
|
||||
class SetPasswordCommand 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:setPassword')
|
||||
->setDescription("Modifier le password d'un utilisateur")
|
||||
->setHelp("Modifier le password d'un utilisateur")
|
||||
->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->writelnred('');
|
||||
$this->writelnred('== app:SetPasword');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$username = $input->getArgument('username');
|
||||
$this->writeln($username);
|
||||
|
||||
$password = $input->getArgument('password');
|
||||
$this->writeln($password);
|
||||
|
||||
$user = $this->em->getRepository('App:User')->findOneBy(array('username' => $username));
|
||||
if($user) {
|
||||
// Set Password
|
||||
$user->setPassword($password);
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
81
src/Command/SetRolesCommand.php
Normal file
81
src/Command/SetRolesCommand.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?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\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
|
||||
class SetRolesCommand 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:setRoles')
|
||||
->setDescription("Modifier le rôle d'un utilisateur")
|
||||
->setHelp("Modifier le rôle d'un utilisateur")
|
||||
->addArgument('username', InputArgument::OPTIONAL, 'username')
|
||||
->addArgument('roles', InputArgument::OPTIONAL, 'roles')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:setRoles');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$username = $input->getArgument('username');
|
||||
$this->writeln($username);
|
||||
|
||||
$this->writeln($input->getArgument('roles'));
|
||||
$roles = explode(",",$input->getArgument('roles'));
|
||||
//$this->writeln($roles);
|
||||
|
||||
$user = $this->em->getRepository('App:User')->findOneBy(array('username' => $username));
|
||||
if($user) {
|
||||
// Set Password
|
||||
$user->setRoles($roles);
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
77
src/Command/UpdateDateCommand.php
Normal file
77
src/Command/UpdateDateCommand.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?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\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class UpdateDateCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
private $byexec;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:updatedate')
|
||||
->setDescription('Regnère les dates de création')
|
||||
->setHelp('Regnère les dates de création dans le même ordre mais à la date du jour afin que les illustrations soient vu par le moteur sociale comme nouveau')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$alias = $this->container->getParameter('appAlias');
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:updatedate');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$now=new \DateTime('now');
|
||||
$illustrations=$this->em->getRepository("App:Illustration")->findAll();
|
||||
foreach($illustrations as $illustration) {
|
||||
$now->add(new \DateInterval('PT1M'));
|
||||
$illustration->setSubmittime($now);
|
||||
$this->em->persist($illustration);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
|
||||
$this->writeln('');
|
||||
return 1;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user