Procházet zdrojové kódy

FD3-797 - Agregar siempre una vlanid_data para FiberHome

Maximiliano Schvindt před 6 roky
rodič
revize
2c84ccc71f

+ 11 - 0
src/FTTHBundle/Entity/OLT.php

@@ -724,5 +724,16 @@ class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         $this->sshConnect = $sshConnect;
     }
 
+    /**
+     * return string | null
+     */
+    public function getMark()
+    {
+        if($this->model)
+            return $this->model->getMark();
+        
+        return null;
+    }
+
 
 }

+ 33 - 0
src/FTTHBundle/EventListener/ONUSubscriber.php

@@ -166,6 +166,8 @@ class ONUSubscriber implements EventSubscriber
                 $this->assignVLanId($args);
             }
 
+            $this->fiberHomeRequire($args);
+
             if ($eventName == DoctrineEvents::PRE_UPDATE) {
                 $uow = $this->em->getUnitOfWork();
                 $meta = $this->em->getClassMetadata(get_class($entity));
@@ -375,4 +377,35 @@ class ONUSubscriber implements EventSubscriber
         }
     }
     
+    /**
+     * @param LifecycleEventArgs $args
+     */
+    private function fiberHomeRequire(LifecycleEventArgs &$args) 
+    {
+        $olt = $args->getEntity()->getOlt();
+        $vlanName = "vlanid_data";
+
+        if(!$olt || $olt->getMark() != "FiberHome") 
+            return true;
+        
+        if($args->getEntity()->getVlanByName($vlanName)) 
+            return true;
+
+        $obj = $this->em->getRepository(VLanID::class)->findOneBy(array("usedByDefault" => true, "name" => $vlanName));
+        if ($obj) {
+            $args->getEntity()->addVlan($obj);
+            $this->em->flush();
+        } else {
+            $obj = $this->em->getRepository(VLanID::class)->findOneBy(array("name" => $vlanName));
+            if ($obj) {
+                $args->getEntity()->addVlan($obj);
+                $this->em->flush();
+            }
+
+        }
+
+        return true;
+        
+    }
+    
 }