ソースを参照

Fixed problem when the system can't remove a some ONU from OLT

Jean Sumara Leopoldo 4 年 前
コミット
ef21dbb0e6

ファイルの差分が大きいため隠しています
+ 1 - 1
app/DoctrineMigrations/src/action.yml


+ 66 - 0
src/FTTHBundle/Command/ONURecoverCommand.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace FTTHBundle\Command;
+
+use FTTHBundle\Entity\ONU;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class ONUStatusOLTCommand
+ * Update the status of olt comunication
+ * @package FTTHBundle\Command
+ */
+class ONURecoverCommand extends ContainerAwareCommand
+{
+    protected function configure()
+    {
+        $this
+            ->setName('onu:recover')
+            ->setDescription('Set the status of the execution of the script against the olt')
+            ->setHelp('Set the status of the execution of the script against the olt')
+            ->addArgument('onuid', InputArgument::REQUIRED, 'Onu ID')
+            ->addArgument('file', InputArgument::REQUIRED, 'File log')
+            ->addArgument('status', InputArgument::REQUIRED, 'Status 0 (OK), 1 (ERROR) other value (PENDING)');
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        try {
+            $em = $this->getContainer()->get('doctrine')->getManager();
+            $onuId = $input->getArgument('onuid');
+            $file = $input->getArgument('file');
+            $status = $input->getArgument('status');
+
+            if($status == 1){
+                $filters = [];
+                //disable filters to find the onu deleted
+                foreach ($em->getFilters()->getEnabledFilters() as $filterName => $filter) {
+                    array_push($filters, $filterName);
+                    $em->getFilters()->disable($filterName);
+                }
+
+                $onu = $em->getRepository(ONU::class)->findOneById($onuId);
+                if (!is_null($onu)) {
+                    $status = "ERROR";
+                    $onu->getLogOLT()->setStatus($status);
+                    $onu->getLogOLT()->setDirectory($file);
+                    $onu->getLogOLT()->setDate(new \DateTime());
+                    $onu->setDeletedAt(null);
+                    $em->flush();
+                }
+
+                //enable filters again
+                foreach ($filters as $filter){
+                    $em->getFilters()->enable($filter);
+                }
+            }
+
+        } catch (\Throwable $e) {
+            echo("\nERROR CODE: " . $e->getCode() . "\nERROR MESSAGE: " . $e->getMessage() . "\n");
+            echo("\nTRACE: \n" . $e->getTraceAsString() . "\n\n");
+        }
+    }
+}