Commit 4e8aee083583a422130c8f88228590a0fe2cd08b
Exists in
master
and in
2 other branches
Corrige erro nas impressoras e bug da coleta
Showing
1 changed file
with
38 additions
and
2 deletions
Show diff stats
Controller/PrinterController.php
| @@ -603,12 +603,47 @@ class PrinterController extends Controller | @@ -603,12 +603,47 @@ class PrinterController extends Controller | ||
| 603 | ->getForm(); | 603 | ->getForm(); |
| 604 | } | 604 | } |
| 605 | 605 | ||
| 606 | + /** | ||
| 607 | + * Totalize results by limit and offset parameters | ||
| 608 | + * | ||
| 609 | + * @return Response | ||
| 610 | + */ | ||
| 606 | public function totalizer() | 611 | public function totalizer() |
| 607 | { | 612 | { |
| 613 | + $n_printers = $this->em->createQuery('SELECT count(p) FROM CocarBundle:Printer p')->getSingleScalarResult(); | ||
| 614 | + | ||
| 615 | + $limit = 1000; | ||
| 616 | + $iterations = (int)($n_printers / 1000); | ||
| 617 | + $iterations = $iterations + 1; | ||
| 618 | + | ||
| 619 | + $i = 0; | ||
| 620 | + while ($i < $iterations) { | ||
| 621 | + // O objetivo é executar a coleta a cada 1000 impressoras | ||
| 622 | + $offset = $limit * $i; | ||
| 623 | + $this->selectPrinters($limit, $offset); | ||
| 624 | + $i = $i + 1; | ||
| 625 | + } | ||
| 626 | + | ||
| 627 | + | ||
| 628 | + return new Response(); | ||
| 629 | + } | ||
| 630 | + | ||
| 631 | + /** | ||
| 632 | + * Select printers by offset and limit | ||
| 633 | + */ | ||
| 634 | + private function selectPrinters($limit, $offset) { | ||
| 608 | ini_set('memory_limit', '1024M'); | 635 | ini_set('memory_limit', '1024M'); |
| 609 | gc_enable(); | 636 | gc_enable(); |
| 610 | 637 | ||
| 611 | - $printers = $this->em->getRepository('CocarBundle:Printer')->findAll(); | 638 | + $printers = $this->em |
| 639 | + ->createQuery('SELECT p FROM CocarBundle:Printer p ORDER BY p.id desc') | ||
| 640 | + ->setMaxResults($limit) | ||
| 641 | + ->setFirstResult($offset) | ||
| 642 | + ->getResult(); | ||
| 643 | + | ||
| 644 | + //$printers = $this->em->getRepository('CocarBundle:Printer')->findAll(); | ||
| 645 | + | ||
| 646 | + $this->get('logger')->info("Executando coleta de $limit impressoras começando no número $offset"); | ||
| 612 | 647 | ||
| 613 | foreach($printers as $printer) | 648 | foreach($printers as $printer) |
| 614 | { | 649 | { |
| @@ -617,6 +652,8 @@ class PrinterController extends Controller | @@ -617,6 +652,8 @@ class PrinterController extends Controller | ||
| 617 | $community = $printer->getCommunitySnmpPrinter(); | 652 | $community = $printer->getCommunitySnmpPrinter(); |
| 618 | $host = $printer->getHost(); | 653 | $host = $printer->getHost(); |
| 619 | 654 | ||
| 655 | + $this->get('logger')->info("Coletando impressora $host"); | ||
| 656 | + | ||
| 620 | $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1"; | 657 | $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1"; |
| 621 | 658 | ||
| 622 | if($outPut = shell_exec($com)) | 659 | if($outPut = shell_exec($com)) |
| @@ -631,7 +668,6 @@ class PrinterController extends Controller | @@ -631,7 +668,6 @@ class PrinterController extends Controller | ||
| 631 | $this->get('logger')->error("Erro na coleta da impressora $host \n".$e->getMessage()); | 668 | $this->get('logger')->error("Erro na coleta da impressora $host \n".$e->getMessage()); |
| 632 | } | 669 | } |
| 633 | } | 670 | } |
| 634 | - return new Response(); | ||
| 635 | } | 671 | } |
| 636 | 672 | ||
| 637 | /** | 673 | /** |