Commit bd46af96c92f6fe6a784c770ad2a87eda1652114

Authored by www-data
2 parents bb7d8723 dbef9660
Exists in master and in 2 other branches 3,1, 3.1

Merge remote branch 'upstream/master'

Command/CronCommand.php
... ... @@ -2,13 +2,13 @@
2 2  
3 3 namespace Swpb\Bundle\CocarBundle\Command;
4 4  
5   -use Symfony\Component\Console\Command\Command;
6 5 use Symfony\Component\Console\Input\InputArgument;
7 6 use Symfony\Component\Console\Input\InputInterface;
8 7 use Symfony\Component\Console\Input\InputOption;
9 8 use Symfony\Component\Console\Output\OutputInterface;
  9 +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10 10  
11   -class CronCommand extends Command
  11 +class CronCommand extends ContainerAwareCommand
12 12 {
13 13 /**
14 14 *
... ... @@ -109,29 +109,29 @@ class CronCommand extends Command
109 109 {
110 110 try
111 111 {
112   - $r = file_get_contents($this->getApplication()->getKernel()->getContainer()->get('router')
113   - ->generate("cocar_$task", array(), true));
  112 + #$r = file_get_contents($this->getApplication()->getKernel()->getContainer()->get('router')
  113 + # ->generate("cocar_$task", array(), true));
114 114  
115   - /*
  115 +
116 116 if($task == 'monitor')
117   - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/monitor");
  117 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/monitor");
118 118 elseif($task == 'status')
119   - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/status");
  119 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/status");
120 120 elseif($task == 'reliability')
121   - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/reliability");
  121 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/reliability");
122 122 elseif($task == 'rrdlog')
123   - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/rrdlog");
  123 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/rrdlog");
124 124 elseif($task == 'dailyperform')
125   - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/dailyperform");
  125 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/dailyperform");
126 126 elseif($task == 'generatealarm')
127   - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/generatealarm");
  127 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/generatealarm");
128 128 elseif($task == 'endalarm')
129   - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/endalarm");
  129 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/endalarm");
130 130 elseif($task == 'graphdailyperform')
131   - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/graphdailyperform");
  131 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/graphdailyperform");
132 132 elseif($task == 'printer')
133   - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/totalizer/info");
134   - */
  133 + $this->getContainer()->get('printer')->totalizer();
  134 +
135 135 }
136 136 catch(Exception $e)
137 137 {
... ...
Controller/PrinterController.php
... ... @@ -15,6 +15,8 @@ use Swpb\Bundle\CocarBundle\Entity\Printer;
15 15 use Swpb\Bundle\CocarBundle\Entity\PrinterCounter;
16 16 use Swpb\Bundle\CocarBundle\Form\PrinterType;
17 17  
  18 +use Doctrine\ORM\EntityManager;
  19 +
18 20 /**
19 21 * Printer controller.
20 22 *
... ... @@ -23,6 +25,13 @@ use Swpb\Bundle\CocarBundle\Form\PrinterType;
23 25 class PrinterController extends Controller
24 26 {
25 27  
  28 + private $em;
  29 +
  30 + public function __construct(EntityManager $em = null)
  31 + {
  32 + $this->em = $em;
  33 + }
  34 +
26 35 /**
27 36 * Lists all Printer entities.
28 37 *
... ... @@ -73,7 +82,8 @@ class PrinterController extends Controller
73 82  
74 83 if(isset($counter[$size]))
75 84 {
76   - $pCounter[$key]['prints'] = $counter[$size]['prints'] - $counter[0]['prints'];
  85 + $pCounter[$key]['prints'] = ($size == 0) ?
  86 + $counter[$size]['prints'] : $counter[$size]['prints'] - $counter[0]['prints'];
77 87 $pCounter[$key]['blackInk'] = $counter[$size]['blackInk'];
78 88 $pCounter[$key]['coloredInk'] = $counter[$size]['coloredInk'];
79 89 }
... ... @@ -377,15 +387,9 @@ class PrinterController extends Controller
377 387 ->getForm();
378 388 }
379 389  
380   - /**
381   - * @Route("/totalizer/info", name="cocar_printer")
382   - * @Template()
383   - */
384   - public function totalizerAction()
  390 + public function totalizer()
385 391 {
386   - $em = $this->getDoctrine()->getManager();
387   -
388   - $printers = $em->getRepository('CocarBundle:Printer')->findAll();
  392 + $printers = $this->em->getRepository('CocarBundle:Printer')->findAll();
389 393  
390 394 foreach($printers as $printer)
391 395 {
... ... @@ -399,12 +403,12 @@ class PrinterController extends Controller
399 403 if($outPut = shell_exec($com))
400 404 {
401 405 $this->updateCounter($printer, $outPut);
402   - $this->createOrUpdateGraph($printer, $outPut);
  406 + #$this->createOrUpdateGraph($printer, $outPut);
403 407 }
404 408 }
405 409 catch(Exception $e)
406 410 {
407   - return new Response($e->getMessage());
  411 + #return new Response($e->getMessage());
408 412 }
409 413 }
410 414 return new Response();
... ... @@ -417,16 +421,14 @@ class PrinterController extends Controller
417 421 {
418 422 try
419 423 {
420   - $em = $this->getDoctrine()->getManager();
421   -
422 424 $counter = new PrinterCounter;
423 425  
424 426 $counter->setPrinter($printer);
425 427 $counter->setPrints($prints);
426 428 $counter->setDate(time());
427 429  
428   - $em->persist($counter);
429   - $em->flush();
  430 + $this->em->persist($counter);
  431 + $this->em->flush();
430 432 }
431 433 catch(\Exception $e)
432 434 {
... ...
Resources/config/services.yml
... ... @@ -14,3 +14,6 @@ services:
14 14 class: Swpb\Bundle\CocarBundle\Controller\MonitorController
15 15 circuit:
16 16 class: Swpb\Bundle\CocarBundle\Entity\Circuits
  17 + printer:
  18 + class: Swpb\Bundle\CocarBundle\Controller\PrinterController
  19 + arguments: ["@doctrine.orm.entity_manager"]
17 20 \ No newline at end of file
... ...
Resources/views/Printer/index.html.twig
... ... @@ -31,6 +31,8 @@
31 31 <td>
32 32 {% if printerCounter[entity.id] is defined %}
33 33 {{ printerCounter[entity.id]['prints'] }}
  34 + {% else %}
  35 + 0
34 36 {% endif %}
35 37 </td>
36 38 <td>{{ entity.name }}</td>
... ...
schedules.txt
1   -30 06 * * * php /var/www/cocar/app/console perform:task --graphdailyperform
2   -0 06 * * * php /var/www/cocar/app/console perform:task --rrdlog
3   -0 5 * * * php /var/www/cocar/app/console perform:task --dailyperform
4   -*/5 * * * * php /var/www/cocar/app/console perform:task --reliability
  1 +30 06 * * * php /srv/gerente/app/console perform:task --graphdailyperform
  2 +0 06 * * * php /srv/gerente/app/console perform:task --rrdlog
  3 +0 5 * * * php /srv/gerente/app/console perform:task --dailyperform
  4 +*/5 * * * * php /srv/gerente/app/console perform:task --reliability
5 5 0,5,10,15,20,25,30,35,40,45,50,55 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --generatealarm
6   -0 20 * * * php /var/www/cocar/app/console perform:task --endalarm
  6 +0 20 * * * php /srv/gerente/app/console perform:task --endalarm
7 7 1,6,11,16,21,26,31,36,41,46,51,56 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --status
8   -* * * * * php /var/www/cocar/app/console perform:task --monitor
9   -0 20 * * * php /var/www/cocar/app/console perform:task --printer
10 8 \ No newline at end of file
  9 +* * * * * php /srv/gerente/app/console perform:task --monitor
  10 +0 20 * * * php /srv/gerente/app/console perform:task --printer
11 11 \ No newline at end of file
... ...