From a40e46113f2f31fd476759fb58f107bd1b154a30 Mon Sep 17 00:00:00 2001 From: afornerot Date: Thu, 23 Apr 2020 14:35:50 +0200 Subject: [PATCH] svg --- .../CronBundle/Command/CronexecCommand.php | 92 +++++++++++++++++ .../Cadoles/CronBundle/Entity/Cronexec.php | 98 +++++++++++++++++++ .../Repository/CronexecRepository.php | 9 ++ .../Resources/views/Cron/exec.html.twig | 32 ++++++ 4 files changed, 231 insertions(+) create mode 100644 src/ninegate-1.0/src/Cadoles/CronBundle/Command/CronexecCommand.php create mode 100644 src/ninegate-1.0/src/Cadoles/CronBundle/Entity/Cronexec.php create mode 100644 src/ninegate-1.0/src/Cadoles/CronBundle/Repository/CronexecRepository.php create mode 100644 src/ninegate-1.0/src/Cadoles/CronBundle/Resources/views/Cron/exec.html.twig diff --git a/src/ninegate-1.0/src/Cadoles/CronBundle/Command/CronexecCommand.php b/src/ninegate-1.0/src/Cadoles/CronBundle/Command/CronexecCommand.php new file mode 100644 index 00000000..cb8c23fb --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CronBundle/Command/CronexecCommand.php @@ -0,0 +1,92 @@ +setName('Cron:Exec') + ->setDescription("Executer les commandes présente dans le bus des commandes à exécuter à la volet") + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + + $this->container = $this->getApplication()->getKernel()->getContainer(); + $this->em = $this->container->get('doctrine')->getEntityManager(); + $this->output = $output; + $this->filesystem = new Filesystem(); + $this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/"; + echo $this->rootlog; + // On supprime le fichier de log spécifique à ce script + //$this->filesystem->remove($this->rootlog."exec.log"); + $this->filesystem->dumpFile($this->rootlog.'exec.log', ""); + $this->filesystem->chown($this->rootlog.'exec.log', "www-data"); + + $cronexecs=$this->em->getRepository("CadolesCronBundle:Cronexec")->findAll(); + if($cronexecs) { + $this->writelnred(''); + $this->writelnred('== Cron:Exec'); + $this->writelnred('=========================================================================================================='); + + foreach($cronexecs as $cron) { + // 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(); + $jsonparameter["byexec"]=true; + + // Formater la chaine de parametre + $parameter = new ArrayInput($jsonparameter); + + // Executer la commande + $returnCode=false; + try{ + $returnCode = $command->run($parameter, $output); + } + catch(\Exception $e) { + $this->writelnred("JOB EN ERREUR"); + } + } + } + + return 1; + } + + private function writelnred($string) { + $this->output->writeln(''.$string.''); + $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n"); + $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"); + $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n"); + } +} diff --git a/src/ninegate-1.0/src/Cadoles/CronBundle/Entity/Cronexec.php b/src/ninegate-1.0/src/Cadoles/CronBundle/Entity/Cronexec.php new file mode 100644 index 00000000..3ebca4b2 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CronBundle/Entity/Cronexec.php @@ -0,0 +1,98 @@ +id; + } + + /** + * Set command + * + * @param string $command + * + * @return Cronexec + */ + public function setCommand($command) + { + $this->command = $command; + + return $this; + } + + /** + * Get command + * + * @return string + */ + public function getCommand() + { + return $this->command; + } + + /** + * Set jsonargument + * + * @param string $jsonargument + * + * @return Cronexec + */ + public function setJsonargument($jsonargument) + { + $this->jsonargument = $jsonargument; + + return $this; + } + + /** + * Get jsonargument + * + * @return string + */ + public function getJsonargument() + { + return $this->jsonargument; + } +} diff --git a/src/ninegate-1.0/src/Cadoles/CronBundle/Repository/CronexecRepository.php b/src/ninegate-1.0/src/Cadoles/CronBundle/Repository/CronexecRepository.php new file mode 100644 index 00000000..45bfe70f --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CronBundle/Repository/CronexecRepository.php @@ -0,0 +1,9 @@ +JOB EXEC +

+
+
+ Logs +
+ +
+
+
+{% endblock %} + +{% block localjavascript %} + function refreshContent() { + console.log("refresh"); + + $.ajax({ + method: "POST", + url: "{{ path('cadoles_cron_config_cronexecread') }}", + success: function(data, dataType) + { + $(".panel-body").html(data.replace(/\"/g,"").replace(/\\n/g,"
")); + } + }); + }; + + var timer=setInterval(refreshContent, 1000); + +{% endblock %} \ No newline at end of file