diff --git a/src/ninegate-1.0/src/Cadoles/CronBundle/Command/DumpCommand.php b/src/ninegate-1.0/src/Cadoles/CronBundle/Command/DumpCommand.php new file mode 100644 index 00000000..a1439a45 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CronBundle/Command/DumpCommand.php @@ -0,0 +1,95 @@ +setName('Cron:Dump') + ->setDescription('Dump database for backup') + ->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->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/"; + + $mailer_host = $this->getContainer()->getParameter('mailer_host'); + + $this->writelnred(''); + $this->writelnred('== Cron:Dump'); + $this->writelnred('=========================================================================================================='); + + $this->datahost = $this->getContainer()->getParameter('database_host'); + $this->database = $this->getContainer()->getParameter('database_name') ; + $this->username = $this->getContainer()->getParameter('database_user') ; + $this->password = $this->getContainer()->getParameter('database_password') ; + + $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."ninegate.sql", $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(''.$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"); + } +} diff --git a/src/ninegate-1.0/src/Cadoles/CronBundle/Command/InitDataCommand.php b/src/ninegate-1.0/src/Cadoles/CronBundle/Command/InitDataCommand.php index d1a74631..735f30ad 100644 --- a/src/ninegate-1.0/src/Cadoles/CronBundle/Command/InitDataCommand.php +++ b/src/ninegate-1.0/src/Cadoles/CronBundle/Command/InitDataCommand.php @@ -158,6 +158,24 @@ class InitDataCommand extends ContainerAwareCommand $this->entityManager->persist($entity); } + // Job Dump + // Toute les 24h à 2h00 + $entity = $this->entityManager->getRepository('CadolesCronBundle:Cron')->find(220); + if(!$entity) { + $entity = new Cron; + $nextdate=$entity->getSubmitdate(); + $nextdate->setTime(2,0); + $entity->setCommand("Cron:Dump"); + $entity->setDescription("Sauvegarde de la BDD"); + $entity->setId(220); + $entity->setStatut(2); + $entity->setRepeatcall(0); + $entity->setRepeatexec(0); + $entity->setRepeatinterval(86400); + $entity->setNextexecdate($nextdate); + $this->entityManager->persist($entity); + } + // CRON PORTAIL // Job purge des registrations obsolètes // Toute les 5mn diff --git a/src/ninegate-1.0/src/Cadoles/CronBundle/Controller/CronController.php b/src/ninegate-1.0/src/Cadoles/CronBundle/Controller/CronController.php index 358e6bd8..c597ca9e 100644 --- a/src/ninegate-1.0/src/Cadoles/CronBundle/Controller/CronController.php +++ b/src/ninegate-1.0/src/Cadoles/CronBundle/Controller/CronController.php @@ -73,7 +73,7 @@ class CronController extends Controller // Order switch($order[0]["column"]) { case 1 : - $qb->orderBy('table.id',$order[0]["dir"]); + $qb->orderBy('table.nextexecdate',$order[0]["dir"]); break; case 2 : $qb->orderBy('table.command',$order[0]["dir"]); @@ -84,9 +84,6 @@ class CronController extends Controller case 4 : $qb->orderBy('table.statut',$order[0]["dir"]); break; - case 5 : - $qb->orderBy('table.nextexecdate',$order[0]["dir"]); - break; } // Execution de la requete d'affichage @@ -107,7 +104,7 @@ class CronController extends Controller if($data->getRepeatCall()>0 AND $data->getRepeatCall()<=$data->getRepeatExec()) $nextexec="Déjà rejoué ".$data->getRepeatExec()." fois"; - array_push($output["data"],array($action,$data->getId(),$data->getCommand(),$data->getDescription(),$data->getStatutLabel(),$nextexec)); + array_push($output["data"],array($action,$nextexec,$data->getCommand(),$data->getDescription(),$data->getStatutLabel())); } // Retour @@ -204,7 +201,11 @@ class CronController extends Controller public function getlogAction(Request $request, $id) { $kernel = $this->get('kernel'); - $file = $this->get('kernel')->getRootDir() . '/../var/logs/'.$id.'.log'; + if($id=="dump") + $file = $this->get('kernel')->getRootDir() . '/../var/logs/ninegate.sql'; + else + $file = $this->get('kernel')->getRootDir() . '/../var/logs/'.$id.'.log'; + $response = new BinaryFileResponse($file); $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT); return $response; diff --git a/src/ninegate-1.0/src/Cadoles/CronBundle/Resources/views/Cron/list.html.twig b/src/ninegate-1.0/src/Cadoles/CronBundle/Resources/views/Cron/list.html.twig index cc4977fe..4c551340 100644 --- a/src/ninegate-1.0/src/Cadoles/CronBundle/Resources/views/Cron/list.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CronBundle/Resources/views/Cron/list.html.twig @@ -17,11 +17,10 @@ Action - Order + Prochaine exécution Command Description Statut - Prochaine exécution diff --git a/src/ninegate-1.0/src/Cadoles/CronBundle/Resources/views/Cron/logs.html.twig b/src/ninegate-1.0/src/Cadoles/CronBundle/Resources/views/Cron/logs.html.twig index 04ac3f05..b007f791 100644 --- a/src/ninegate-1.0/src/Cadoles/CronBundle/Resources/views/Cron/logs.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CronBundle/Resources/views/Cron/logs.html.twig @@ -6,4 +6,5 @@ Log CRON Log PROD Log DEV + Dump de la Base {% endblock %} \ No newline at end of file diff --git a/tmpl/ninegate-init-01.sql b/tmpl/ninegate-init-01.sql index c54b85c0..1aae968e 100644 --- a/tmpl/ninegate-init-01.sql +++ b/tmpl/ninegate-init-01.sql @@ -83,7 +83,7 @@ INSERT IGNORE INTO `sidebar` (`id`, `parent_id`, `roworder`, `label`, `path`, `f (7000, NULL, 7000, 'CRON', NULL, 'fa-bolt', 'ROLE_ADMIN,ROLE_MODO', 'cron_activate'), (7010, 7000, 7010, 'Jobs', 'cadoles_cron_config', 'fa-bullseye', 'ROLE_ADMIN,ROLE_MODO', 'cron_activate'), -(7020, 7000, 7020, 'Logs', 'cadoles_cron_config_log', 'fa-list-alt', 'ROLE_ADMIN,ROLE_MODO', 'cron_activate'); +(7020, 7000, 7020, 'Logs / Dump', 'cadoles_cron_config_log', 'fa-list-alt', 'ROLE_ADMIN,ROLE_MODO', 'cron_activate');