ONUStatusOLTCommand.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace FTTHBundle\Command;
  3. use FTTHBundle\Entity\ONU;
  4. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. /**
  9. * Class ONUStatusOLTCommand
  10. * Update the status of olt comunication
  11. * @package FTTHBundle\Command
  12. */
  13. class ONUStatusOLTCommand extends ContainerAwareCommand
  14. {
  15. protected function configure()
  16. {
  17. $this
  18. ->setName('ik:onu:statusolt')
  19. ->setDescription('Set the status of the execution of the script against the olt')
  20. ->setHelp('Set the status of the execution of the script against the olt')
  21. ->addArgument('onuid', InputArgument::REQUIRED, 'Pon serial number')
  22. ->addArgument('file', InputArgument::REQUIRED, 'File log')
  23. ->addArgument('status', InputArgument::REQUIRED, 'Status 0 (OK), 1 (ERROR) other value (PENDING)');
  24. }
  25. protected function execute(InputInterface $input, OutputInterface $output)
  26. {
  27. try {
  28. $em = $this->getContainer()->get('doctrine')->getManager();
  29. $onuid = $input->getArgument('onuid');
  30. $file = $input->getArgument('file');
  31. $status = $input->getArgument('status');
  32. $onu = $em->getRepository(ONU::class)->findById($onuid);
  33. if ($onu && count($onu) > 0) {
  34. $onu = $onu[0];
  35. if ($status == 1) {
  36. $status = "ERROR";
  37. } elseif ($status == 0) {
  38. $status = "OK";
  39. } else {
  40. $status = "PENDING";
  41. }
  42. $onu->getLogOLT()->setStatus($status);
  43. $onu->getLogOLT()->setDirectory($file);
  44. $onu->getLogOLT()->setDate(new \DateTime());
  45. $em->flush();
  46. }
  47. } catch (\Throwable $e) {
  48. echo("\nERROR CODE: " . $e->getCode() . "\nERROR MESSAGE: " . $e->getMessage() . "\n");
  49. echo("\nTRACE: \n" . $e->getTraceAsString() . "\n\n");
  50. }
  51. }
  52. }