|
@@ -47,6 +47,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
{
|
|
|
return array(
|
|
|
DoctrineEvents::PRE_PERSIST,
|
|
|
+ DoctrineEvents::POST_PERSIST,
|
|
|
DoctrineEvents::PRE_UPDATE,
|
|
|
);
|
|
|
}
|
|
@@ -59,6 +60,21 @@ class ONUSubscriber implements EventSubscriber
|
|
|
$this->execute($args, DoctrineEvents::PRE_PERSIST);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param LifecycleEventArgs $args
|
|
|
+ */
|
|
|
+ public function postPersist(LifecycleEventArgs $args)
|
|
|
+ {
|
|
|
+ $entity = $args->getEntity();
|
|
|
+ if ($entity instanceof ONU) {
|
|
|
+
|
|
|
+ $this->em = $args->getEntityManager();
|
|
|
+ $this->setSerivcePorts($entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
*/
|
|
@@ -96,8 +112,6 @@ class ONUSubscriber implements EventSubscriber
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $this->setSerivcePorts($entity);
|
|
|
-
|
|
|
if ($eventName == DoctrineEvents::PRE_UPDATE) {
|
|
|
$uow = $this->em->getUnitOfWork();
|
|
|
$meta = $this->em->getClassMetadata(get_class($entity));
|
|
@@ -147,56 +161,61 @@ class ONUSubscriber implements EventSubscriber
|
|
|
*/
|
|
|
public function setSerivcePorts(ONU $onu)
|
|
|
{
|
|
|
- if($onu->getNAP() and $onu->getOLT()){
|
|
|
- $sp = $onu->getServicePort();
|
|
|
- if(count($sp) == 0){
|
|
|
- $olt = $onu->getNAP()->getOLT();
|
|
|
- $used_sp = $this->em->getRepository(ServicePort::class)->findBy(
|
|
|
- array("olt" => $olt)
|
|
|
- );
|
|
|
- $services = array();
|
|
|
- foreach($used_sp as $used_service_port){
|
|
|
- $services[$used_service_port->getNumber()] = $used_service_port;
|
|
|
- }
|
|
|
-
|
|
|
- $foundit = array();
|
|
|
- $found_at_least = 2;
|
|
|
- $service_type = array( "data", "voip", /*'iptv'*/);
|
|
|
-
|
|
|
- $max_n = @max(array_keys($services)); //Warning: max(): Array must contain at least one element
|
|
|
-
|
|
|
- for($i = 1; $i <= $max_n; $i++){
|
|
|
- if(!isset($services[$i])){
|
|
|
- $foundit[] = $i;
|
|
|
- }
|
|
|
- if($found_at_least == count($foundit)){
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for($i = count($foundit) ; $i < $found_at_least; $i++){
|
|
|
- $foundit[] = 1 + $max_n + $i;
|
|
|
- }
|
|
|
-
|
|
|
- foreach($foundit as $key => $num){
|
|
|
- $sp = new ServicePort();
|
|
|
- $sp->setOlt($olt);
|
|
|
- $ok = list($skey, $ser) = each($service_type);
|
|
|
- if($ok === false){
|
|
|
- reset($service_type);
|
|
|
- $ok = list($skey, $ser) = current($service_type);
|
|
|
- }
|
|
|
- $sp->setNumber($num);
|
|
|
- $sp->setType($ser);
|
|
|
- $onu->addServicePort($sp);
|
|
|
- $this->em->persist($sp);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ if($onu->getNAP() and $onu->getNAP()->getOLT()){
|
|
|
+ $sp = $onu->getServicePort();
|
|
|
+ if(count($sp) == 0){
|
|
|
+ $olt = $onu->getNAP()->getOLT();
|
|
|
+ $used_sp = $this->em->getRepository(ServicePort::class)->findBy(
|
|
|
+ array("olt" => $olt)
|
|
|
+ );
|
|
|
+ $services = array();
|
|
|
+ foreach($used_sp as $used_service_port){
|
|
|
+ $services[$used_service_port->getNumber()] = $used_service_port;
|
|
|
+ }
|
|
|
+
|
|
|
+ $foundit = array();
|
|
|
+ $found_at_least = 2;
|
|
|
+ $service_type = array( "data", "voip", /*'iptv'*/);
|
|
|
+ $vlangemport_config = array(
|
|
|
+ 'voip' => array('gemport' => 0, 'vlan' => 13),
|
|
|
+ 'data' => array('gemport' => 1, 'vlan' => 10)
|
|
|
+ );
|
|
|
+
|
|
|
+ $max_n = @max(array_keys($services)); //Warning: max(): Array must contain at least one element
|
|
|
+
|
|
|
+ for($i = 1; $i <= $max_n; $i++){
|
|
|
+ if(!isset($services[$i])){
|
|
|
+ $foundit[] = $i;
|
|
|
+ }
|
|
|
+ if($found_at_least == count($foundit)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for($i = count($foundit) ; $i < $found_at_least; $i++){
|
|
|
+ $foundit[] = 1 + $max_n + $i;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($foundit as $key => $num){
|
|
|
+ $sp = new ServicePort();
|
|
|
+ $sp->setOlt($olt);
|
|
|
+ $sp->setOnu($onu);
|
|
|
+ $ok = list($skey, $ser) = each($service_type);
|
|
|
+ if($ok === false){
|
|
|
+ reset($service_type);
|
|
|
+ $ok = list($skey, $ser) = current($service_type);
|
|
|
+ }
|
|
|
+ $sp->setNumber($num);
|
|
|
+ $sp->setGemport($vlangemport_config[$ser]['gemport']);
|
|
|
+ $sp->setVlan($vlangemport_config[$ser]['vlan']);
|
|
|
+ $sp->setType($ser);
|
|
|
+ $onu->addServicePort($sp);
|
|
|
+ $this->em->persist($sp);
|
|
|
+
|
|
|
+ }
|
|
|
+ $this->em->flush();
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|