Browse Source

Add registration of the script execution on olt

gabriel 6 years ago
parent
commit
6332b1e54c

+ 15 - 19
src/FTTHBundle/Admin/ONUAdmin.php

@@ -56,7 +56,10 @@ class ONUAdmin extends WorkflowBaseAdmin
             ->add('profile')
             ->add('nap')
             ->add('model')
-            ->add('olt');
+            ->add('olt')
+            ->add('logOLT.status')
+            ->add('logOLT.date')
+        ;
     }
 
     /**
@@ -93,13 +96,17 @@ class ONUAdmin extends WorkflowBaseAdmin
             ))
             ->add('catv')
             ->add('created')
+            ->add('logOLT.status', 'string', array(
+                'template' => 'FTTHBundle:Type:list_status_field_type.html.twig'))
+            ->add('logOLT.date')
             ->add('_action', 'with-workflow-action', array(
                 'actions' => array(
                     'show' => array(),
                     'edit' => array(),
                     'delete' => array(),
                     'state' => array('template' => 'WorkflowBundle:Workflow:show_transitions.html.twig')
-                )));
+                )))
+        ;
     }
 
     /**
@@ -484,6 +491,12 @@ class ONUAdmin extends WorkflowBaseAdmin
             ->end()
             ->tab('Log')
                 ->with('Log')
+                    ->add('logOLT.status', 'string', array(
+                        'label' => 'Status',
+                        'template' => 'FTTHBundle:Type:show_status_field_type.html.twig'
+                    ))
+                    ->add('logOLT.date')
+                    ->add('logOLT.directory')
                     ->add('log', 'string', array('template' => 'FTTHBundle:ONU:show_log.html.twig'))
                     ->add('deviceLog', 'string', array(
                         'template' => 'DeviceBundle::show_device_log.html.twig',
@@ -597,23 +610,6 @@ class ONUAdmin extends WorkflowBaseAdmin
         return $onuShowUrl;
     }
 
-    /**
-     * @param string $action
-     * @param Object $object
-     *
-     * @return array
-     */
-    public function configureActionButtons($action, $object = null)
-    {
-        $actions = parent::configureActionButtons($action, $object);
-
-        if($action == "list") {
-            $actions['import_onu'] = array('template' => 'FTTHBundle:ONU:import_button.html.twig');
-        }
-
-        return $actions;
-    }
-
     public function configure()
     {
         $this->setTemplate('create', 'FTTHBundle:ONU:form.html.twig');

+ 56 - 0
src/FTTHBundle/Command/ONUStatusOLTCommand.php

@@ -0,0 +1,56 @@
+<?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 ONUStatusOLTCommand extends ContainerAwareCommand
+{
+    protected function configure()
+    {
+        $this
+            ->setName('ik:onu:statusolt')
+            ->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, 'Pon serial number')
+            ->addArgument('file', InputArgument::REQUIRED, 'File log')
+            ->addArgument('status', InputArgument::REQUIRED, 'Status 1 (OK), 0 (ERROR) or -1 (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');
+            $onu = $em->getRepository(ONU::class)->findById($onuid);
+            if ($onu && count($onu) > 0) {
+                $onu = $onu[0];
+                if ($status == 1) {
+                    $status = "ERROR";
+                } elseif ($status == 0) {
+                    $status = "OK";
+                } else {
+                    $status = "PENDING";
+                }
+                $onu->getLogOLT()->setStatus($status);
+                $onu->getLogOLT()->setDirectory($file);
+                $onu->getLogOLT()->setDate(new \DateTime());
+                $em->flush();
+            }
+        } catch (\Throwable $e) {
+            echo("\nERROR CODE: " . $e->getCode() . "\nERROR MESSAGE: " . $e->getMessage() . "\n");
+            echo("\nTRACE: \n" . $e->getTraceAsString() . "\n\n");
+        }
+    }
+}

+ 26 - 0
src/FTTHBundle/Entity/ONU.php

@@ -14,6 +14,8 @@ use MapBundle\Entity\Traits\LocationTrait;
 use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
 use WorkflowBundle\Entity\Traits\WorkflowTrait;
 use Doctrine\ORM\Mapping as ORM;
+use Doctrine\ORM\Mapping\JoinColumn;
+use Doctrine\ORM\Mapping\OneToOne;
 use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
 use Gedmo\Mapping\Annotation as Gedmo;
 use JMS\Serializer\Annotation as JMS;
@@ -266,6 +268,11 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
      */
     protected $activationCode;
 
+    /**
+     * @OneToOne(targetEntity="ONULogOLT", cascade={"persist"})
+     * @JoinColumn(name="id", referencedColumnName="id")
+     */
+    protected $logOLT;
 
     /**
      * Constructor
@@ -1041,12 +1048,31 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         }, $this->servicePorts->toArray()));
     }
 
+    /**
+     * @return mixed
+     */
+    public function getLogOLT()
+    {
+        return $this->logOLT;
+    }
+
+    /**
+     * @param mixed $logOLT
+     * @return $this
+     */
+    public function setLogOLT($logOLT)
+    {
+        $this->logOLT = $logOLT;
+        return $this;
+    }
+
     /**
      * @ORM\PrePersist()
      */
     public function prePersist()
     {
         $this->correctSerialNumber();
+        $this->setLogOLT(new  ONULogOLT());
     }
 
     /**

+ 131 - 0
src/FTTHBundle/Entity/ONULogOLT.php

@@ -0,0 +1,131 @@
+<?php
+
+namespace FTTHBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Doctrine\ORM\Mapping\OneToOne;
+use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
+
+/**
+ * ONULogOLT
+ *
+ * @ORM\Entity
+ */
+class ONULogOLT
+{
+    /**
+     * @ORM\Column(name="id", type="integer", nullable=false)
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    protected $id;
+
+    /**
+     * @ORM\Column(type="string", options={"default": ""})
+     */
+    protected $status;
+
+    /**
+     * @ORM\Column(type="string", options={"default": ""})
+     */
+    protected $directory;
+
+    /**
+     * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
+     */
+    protected $date;
+
+
+    /**
+     * Constructor
+     */
+    public function __construct()
+    {
+        $this->setStatus("");
+        $this->setDirectory("");
+        $this->setDate(new \DateTime());
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * @param mixed $id
+     * @return ONULogOLT
+     */
+    public function setId($id)
+    {
+        $this->id = $id;
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getStatus()
+    {
+        return $this->status;
+    }
+
+    /**
+     * @param mixed $status
+     * @return ONULogOLT
+     */
+    public function setStatus($status)
+    {
+        $this->status = $status;
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getDirectory()
+    {
+        return $this->directory;
+    }
+
+    /**
+     * @param mixed $directory
+     * @return ONULogOLT
+     */
+    public function setDirectory($directory)
+    {
+        $this->directory = $directory;
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getDate()
+    {
+        return $this->date;
+    }
+
+    /**
+     * @param mixed $date
+     * @return ONULogOLT
+     */
+    public function setDate($date)
+    {
+        $this->date = $date;
+        return $this;
+    }
+
+    /**
+     * @return $this
+     */
+    public function setPending()
+    {
+        $this->setStatus("PENDING");
+        $this->setDirectory("");
+        $this->setDate(new \DateTime());
+        return $this;
+    }
+}

+ 7 - 2
src/FTTHBundle/Resources/translations/FTTHBundle.es.yml

@@ -54,6 +54,8 @@ filter:
     label_value: Valor
     label_comments: Comentarios
     label_template: Template
+    label_log_o_l_t_status: Conf. Status
+    label_log_o_l_t_date: Fecha OLT
 
 breadcrumb:
     link_t_cont_profile_list: Listado Perfiles tcon
@@ -234,7 +236,8 @@ list:
     label_enable_pass: Enable Password
     label_ssh_port: SSH Port
     label_ssh_connect: Conexión por SSH
-
+    label_log_o_l_t_status: Conf. Status
+    label_log_o_l_t_date: Fecha OLT
 show:
     label_id: Id
     label_ip: Ip
@@ -308,7 +311,9 @@ show:
     label_traffic_profile_in: Perfil de Tráfico In
     label_traffic_profile_out: Perfil de Tráfico Out
     label_tcontprofile: Perfil tcont
-
+    label_log_o_l_t_status: Conf. Status
+    label_log_o_l_t_date: Fecha OLT
+    label_log_o_l_t_directory: Directorio log OLT
 helps:
     check_address: Verifique la dirección para el cálculo de distancias.
     onu_serial_number: Serial Number de la ONU conformado por 16 caracteres, si es vacío lo calculamos desde el Identificador.

+ 15 - 0
src/FTTHBundle/Resources/views/Type/list_status_field_type.html.twig

@@ -0,0 +1,15 @@
+{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
+
+{% block field %}
+    {% if object is defined and object.getLogOLT() is defined and object.getLogOLT().getStatus() is defined %}
+        {% if object.getLogOLT().getStatus() == 'OK' %}
+            <span class="label alert-success">
+        {% elseif object.getLogOLT().getStatus() == 'ERROR' %}
+            <span class="label alert-error">
+        {% else %}
+            <span class="label alert-warning">
+        {% endif %}
+        {{ object.getLogOLT().getStatus() }}
+        </span>
+    {% endif %}
+{% endblock %}

+ 15 - 0
src/FTTHBundle/Resources/views/Type/show_status_field_type.html.twig

@@ -0,0 +1,15 @@
+{% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
+
+{% block field %}
+    {% if object is defined and object.getLogOLT() is defined and object.getLogOLT().getStatus() is defined %}
+        {% if object.getLogOLT().getStatus() == 'OK' %}
+            <span class="label alert-success">
+        {% elseif object.getLogOLT().getStatus() == 'ERROR' %}
+            <span class="label alert-error">
+        {% else %}
+            <span class="label alert-warning">
+        {% endif %}
+        {{ object.getLogOLT().getStatus() }}
+        </span>
+    {% endif %}
+{% endblock %}