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:
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user