|
@@ -2,23 +2,23 @@
|
|
|
|
|
|
namespace FTTHBundle\EventListener;
|
|
|
|
|
|
+use Base\AdminBundle\Controller\TenancyService;
|
|
|
+use Doctrine\Common\EventSubscriber;
|
|
|
+use Doctrine\ORM\Event\LifecycleEventArgs;
|
|
|
+use Exception;
|
|
|
use FTTHBundle\Entity\ONU;
|
|
|
-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 FTTHBundle\Entity\VLanID;
|
|
|
+use FTTHBundle\Entity\VLanProfile;
|
|
|
use FTTHBundle\Factory\ExceptionFactory;
|
|
|
-use WorkflowBundle\Utils\DoctrineEvents;
|
|
|
-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;
|
|
|
+use Symfony\Component\Translation\TranslatorInterface;
|
|
|
+use WorkflowBundle\Utils\DoctrineEvents;
|
|
|
|
|
|
class ONUSubscriber implements EventSubscriber
|
|
|
{
|
|
@@ -34,7 +34,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
private $session;
|
|
|
|
|
|
/**
|
|
|
- * @var TranslatorInterface
|
|
|
+ * @var TranslatorInterface
|
|
|
*/
|
|
|
private $translator;
|
|
|
|
|
@@ -114,17 +114,19 @@ 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);
|
|
|
+ if(isset($args->getEntityChangeSet()['clientId']) && $args->getOldValue('clientId') != $entity->getClientId()){
|
|
|
+ $this->setStateOnu($entity);
|
|
|
+ }
|
|
|
}
|
|
|
}catch(Exception $ex){
|
|
|
ExceptionFactory::make($ex->getMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
*/
|
|
@@ -133,13 +135,13 @@ class ONUSubscriber implements EventSubscriber
|
|
|
$entity = $args->getEntity();
|
|
|
if ($entity instanceof ONU) {
|
|
|
$this->em = $args->getEntityManager();
|
|
|
-
|
|
|
+
|
|
|
if (!$entity->isDeleted()) {
|
|
|
$this->setServicePorts($entity);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
*/
|
|
@@ -177,7 +179,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
], 'FTTHBundle'));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (!$entity->getTrafficProfile()) {
|
|
|
$this->assignTrafficProfile($args);
|
|
|
}
|
|
@@ -240,7 +242,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
|
|
|
return $position;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
* @param string $eventName
|
|
@@ -253,19 +255,19 @@ class ONUSubscriber implements EventSubscriber
|
|
|
$args->getEntity()->setTrafficProfileIn($obj);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
* @param string $eventName
|
|
|
*/
|
|
|
public function assignVlanProfile(LifecycleEventArgs $args)
|
|
|
{
|
|
|
- $obj = $this->getDefaultObject(VLanProfile::class);
|
|
|
+ $obj = $this->getDefaultObject(VLanProfile::class);
|
|
|
if ($obj) {
|
|
|
$args->getEntity()->setVlanProfile($obj);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
* @param string $eventName
|
|
@@ -277,7 +279,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
$args->getEntity()->setONUProfile($obj);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
* @param string $eventName
|
|
@@ -315,7 +317,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
* Calcula dos ServicePort para t com
|
|
|
*
|
|
|
* @param ONU $onu
|
|
|
- */
|
|
|
+ */
|
|
|
public function setServicePorts(ONU $onu)
|
|
|
{
|
|
|
if ($onu->getNAP() and $onu->getNAP()->getOLT()) {
|
|
@@ -325,7 +327,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
} else {
|
|
|
$model_extra_data = array();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Si la ONU no tiene asignadas vlans, busco alguna que este por default
|
|
|
$vlans = $onu->getVlans() ?: [];
|
|
|
$vlanDefault = $this->getDefaultObject(VLanID::class);
|
|
@@ -334,12 +336,12 @@ class ONUSubscriber implements EventSubscriber
|
|
|
$vlanDefault,
|
|
|
];
|
|
|
}
|
|
|
-
|
|
|
- if (isset($model_extra_data['auto-create-service-ports']) and
|
|
|
+
|
|
|
+ if (isset($model_extra_data['auto-create-service-ports']) and
|
|
|
$model_extra_data['auto-create-service-ports'] === true and count($sp) == 0
|
|
|
and count($vlans)) {
|
|
|
$olt = $onu->getNAP()->getOLT();
|
|
|
-
|
|
|
+
|
|
|
// Se buscan los ServicePort utilizados en la OLT
|
|
|
$used_sp = $this->em->getRepository(ServicePort::class)->findBy(array(
|
|
|
"olt" => $olt,
|
|
@@ -348,16 +350,16 @@ class ONUSubscriber implements EventSubscriber
|
|
|
foreach ($used_sp as $used_service_port) {
|
|
|
$services[$used_service_port->getNumber()] = $used_service_port;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$foundit = array();
|
|
|
$found_at_least = count($vlans);
|
|
|
-
|
|
|
+
|
|
|
// Si existen ServicePort asignados se buscan los números libres
|
|
|
$max_n = 2;
|
|
|
if (count($services)) {
|
|
|
$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;
|
|
@@ -366,16 +368,16 @@ class ONUSubscriber implements EventSubscriber
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for ($i = count($foundit) ; $i < $found_at_least; $i++) {
|
|
|
$foundit[] = 1 + $max_n + $i;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$vlanNumbers = [];
|
|
|
foreach ($vlans as $vlan) {
|
|
|
$vlanNumbers[] = $vlan->getValue();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$gemport = 0;
|
|
|
foreach ($foundit as $key => $num) {
|
|
|
$sp = new ServicePort();
|
|
@@ -383,18 +385,18 @@ class ONUSubscriber implements EventSubscriber
|
|
|
$sp->setGemport($gemport);
|
|
|
$sp->setVlan(array_shift($vlanNumbers));
|
|
|
$onu->addServicePort($sp);
|
|
|
-
|
|
|
+
|
|
|
$gemport++;
|
|
|
}
|
|
|
$this->em->flush();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
*/
|
|
|
- private function fiberHomeRequire(LifecycleEventArgs &$args)
|
|
|
+ private function fiberHomeRequire(LifecycleEventArgs &$args)
|
|
|
{
|
|
|
$olt = $args->getEntity()->getOlt();
|
|
|
$vlanName = "vlanid_data";
|
|
@@ -402,7 +404,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
if (!$olt || $olt->getMark() != "FiberHome") {
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if ($args->getEntity()->getVlanByName($vlanName)) {
|
|
|
return true;
|
|
|
}
|
|
@@ -420,17 +422,17 @@ class ONUSubscriber implements EventSubscriber
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Return the default object for the class parameter filter by current tenancy
|
|
|
* Optional filter by fields
|
|
|
* If there is no result, return the default object for base tenancy
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string $class
|
|
|
* @param array $fields
|
|
|
- *
|
|
|
+ *
|
|
|
* @return mixed
|
|
|
*/
|
|
|
private function getDefaultObject($class, $fields = [])
|
|
@@ -447,5 +449,5 @@ class ONUSubscriber implements EventSubscriber
|
|
|
|
|
|
return $obj;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|