Przeglądaj źródła

Updated method to update ONUS when client state is changed

Jean Sumara 5 lat temu
rodzic
commit
e6884e718d

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

@@ -7,8 +7,6 @@ use Buzz\Message\RequestInterface as HttpRequestInterface;
 use Doctrine\ORM\EntityRepository;
 use FTTHBundle\Entity\NAP;
 use FTTHBundle\Entity\ONU;
-use FTTHBundle\Factory\ExceptionFactory;
-use FTTHBundle\Service\ClientProxyService;
 use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
 use Sonata\AdminBundle\Datagrid\DatagridMapper;
 use Sonata\AdminBundle\Datagrid\ListMapper;
@@ -742,7 +740,6 @@ class ONUAdmin extends WorkflowBaseAdmin
             if(!is_null($status)) $aux = $tr069->setWstatus($id, $status);
         }
 
-        $this->makeProxyUpdateStateOnu($onu);
     }
 
 
@@ -753,18 +750,6 @@ class ONUAdmin extends WorkflowBaseAdmin
     public function prePersist($onu)
     {
         $onu->setOlt($onu->getNap()->getOlt());
-        $this->makeProxyUpdateStateOnu($onu);
-    }
-
-    private function makeProxyUpdateStateOnu($onu){
-        $webService = $this->get("webservice");
-
-        try{
-            $clientProxyService = new ClientProxyService($webService, $this->getConfigurationPool()->getContainer());
-            $clientProxyService->setStateOnu($onu);
-        } catch (Exception $ex){
-            ExceptionFactory::make($ex->getMessage());
-        }
     }
 
 

+ 46 - 9
src/FTTHBundle/EventListener/ONUSubscriber.php

@@ -2,20 +2,23 @@
 
 namespace FTTHBundle\EventListener;
 
-use Doctrine\Common\EventSubscriber;
-use Doctrine\ORM\Event\LifecycleEventArgs;
-use Base\AdminBundle\Controller\TenancyService;
 use FTTHBundle\Entity\ONU;
-use FTTHBundle\Entity\ONUProfile;
 use FTTHBundle\Entity\VLanID;
+use FTTHBundle\Entity\ONUProfile;
+use FTTHBundle\Entity\ServicePort;
 use FTTHBundle\Entity\VLanProfile;
 use FTTHBundle\Entity\TContProfile;
+use Doctrine\Common\EventSubscriber;
 use FTTHBundle\Entity\TrafficProfile;
-use Symfony\Component\HttpFoundation\Session\SessionInterface;
-use Symfony\Component\Translation\TranslatorInterface;
+use FTTHBundle\Factory\ExceptionFactory;
 use WorkflowBundle\Utils\DoctrineEvents;
-
-use FTTHBundle\Entity\ServicePort;
+use Doctrine\ORM\Event\LifecycleEventArgs;
+use FTTHBundle\Service\ClientProxyService;
+use Base\AdminBundle\Controller\TenancyService;
+use Exception;
+use Symfony\Component\Translation\TranslatorInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
 
 class ONUSubscriber implements EventSubscriber
 {
@@ -40,17 +43,24 @@ class ONUSubscriber implements EventSubscriber
      */
     private $tenancyService;
 
+    /**
+     * @var ContainerInterface
+     */
+    private $containerInterface;
+
 
     /**
      * @param SessionInterface $session
      * @param TranslatorInterface $translator
      * @param TenancyService $tenancyService
+     * @param ContainerInterface $containerInterface
      */
-    public function __construct(SessionInterface $session, TranslatorInterface $translator, TenancyService $tenancyService)
+    public function __construct(SessionInterface $session, TranslatorInterface $translator, TenancyService $tenancyService, ContainerInterface $containerInterface)
     {
         $this->session = $session;
         $this->translator = $translator;
         $this->tenancyService = $tenancyService;
+        $this->containerInterface = $containerInterface;
     }
 
     /**
@@ -73,6 +83,15 @@ class ONUSubscriber implements EventSubscriber
     public function prePersist(LifecycleEventArgs $args)
     {
         $this->execute($args, DoctrineEvents::PRE_PERSIST);
+
+        try{
+            $entity = $args->getEntity();
+            if($entity instanceof ONU){
+                $this->setStateOnu($entity);
+            }
+        }catch(Exception $ex){
+            ExceptionFactory::make($ex->getMessage());
+        }
     }
 
     /**
@@ -95,6 +114,15 @@ class ONUSubscriber implements EventSubscriber
     public function preUpdate(LifecycleEventArgs $args)
     {
         $this->execute($args, DoctrineEvents::PRE_UPDATE);
+        
+        try{
+            $entity = $args->getEntity();
+            if($entity instanceof ONU){
+                $this->setStateOnu($entity);
+            }
+        }catch(Exception $ex){
+            ExceptionFactory::make($ex->getMessage());
+        }
     }
         
     /**
@@ -274,6 +302,15 @@ class ONUSubscriber implements EventSubscriber
         }
     }
 
+    public function setStateOnu($onu){
+        try{
+            $clientProxyService = new ClientProxyService($this->containerInterface->get('webservice'), $this->containerInterface);
+            $clientProxyService->setStateOnu($onu);
+        } catch (Exception $ex){
+            ExceptionFactory::make($ex->getMessage());
+        }
+    }
+
     /**
      * Calcula dos ServicePort para t com
      *

+ 1 - 1
src/FTTHBundle/Resources/config/services.yml

@@ -60,7 +60,7 @@ services:
         class: FTTHBundle\EventListener\ONUSubscriber
         tags:
             - { name: doctrine.event_subscriber, connection: default }
-        arguments: ["@session", "@translator", "@base_tenancy.tenancy_service"]
+        arguments: ["@session", "@translator", "@base_tenancy.tenancy_service", "@service_container"]
 
     ftth.onu.form:
         class: FTTHBundle\Form\ONUType