|
@@ -4,6 +4,7 @@ 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;
|
|
@@ -34,15 +35,22 @@ class ONUSubscriber implements EventSubscriber
|
|
|
*/
|
|
|
private $translator;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var TenancyService
|
|
|
+ */
|
|
|
+ private $tenancyService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @param SessionInterface $session
|
|
|
* @param TranslatorInterface $translator
|
|
|
+ * @param TenancyService $tenancyService
|
|
|
*/
|
|
|
- public function __construct(SessionInterface $session, TranslatorInterface $translator)
|
|
|
+ public function __construct(SessionInterface $session, TranslatorInterface $translator, TenancyService $tenancyService)
|
|
|
{
|
|
|
$this->session = $session;
|
|
|
$this->translator = $translator;
|
|
|
+ $this->tenancyService = $tenancyService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -219,11 +227,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
*/
|
|
|
public function assignTrafficProfile(LifecycleEventArgs $args)
|
|
|
{
|
|
|
- $obj = $args->getEntityManager()
|
|
|
- ->getRepository(TrafficProfile::class)
|
|
|
- ->findOneBy(array(
|
|
|
- "usedByDefault" => true,
|
|
|
- ));
|
|
|
+ $obj = $this->getDefaultObject(TrafficProfile::class);
|
|
|
if ($obj) {
|
|
|
$args->getEntity()->setTrafficProfileOut($obj);
|
|
|
$args->getEntity()->setTrafficProfileIn($obj);
|
|
@@ -236,11 +240,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
*/
|
|
|
public function assignVlanProfile(LifecycleEventArgs $args)
|
|
|
{
|
|
|
- $obj = $args->getEntityManager()
|
|
|
- ->getRepository(VLanProfile::class)
|
|
|
- ->findOneBy(array(
|
|
|
- "usedByDefault" => true,
|
|
|
- ));
|
|
|
+ $obj = $this->getDefaultObject(VLanProfile::class);
|
|
|
if ($obj) {
|
|
|
$args->getEntity()->setVlanProfile($obj);
|
|
|
}
|
|
@@ -252,11 +252,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
*/
|
|
|
public function assignONUProfile(LifecycleEventArgs $args)
|
|
|
{
|
|
|
- $obj = $args->getEntityManager()
|
|
|
- ->getRepository(ONUProfile::class)
|
|
|
- ->findOneBy(array(
|
|
|
- "usedByDefault" => true,
|
|
|
- ));
|
|
|
+ $obj = $this->getDefaultObject(ONUProfile::class);
|
|
|
if ($obj) {
|
|
|
$args->getEntity()->setONUProfile($obj);
|
|
|
}
|
|
@@ -268,11 +264,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
*/
|
|
|
public function assignTConProfile(LifecycleEventArgs $args)
|
|
|
{
|
|
|
- $obj = $args->getEntityManager()
|
|
|
- ->getRepository(TContProfile::class)
|
|
|
- ->findOneBy(array(
|
|
|
- "usedByDefault" => true,
|
|
|
- ));
|
|
|
+ $obj = $this->getDefaultObject(TContProfile::class);
|
|
|
if ($obj) {
|
|
|
$args->getEntity()->setTcontprofile($obj);
|
|
|
}
|
|
@@ -284,11 +276,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
*/
|
|
|
public function assignVLanId(LifecycleEventArgs $args)
|
|
|
{
|
|
|
- $obj = $args->getEntityManager()
|
|
|
- ->getRepository(VLanID::class)
|
|
|
- ->findOneBy(array(
|
|
|
- "usedByDefault" => true,
|
|
|
- ));
|
|
|
+ $obj = $this->getDefaultObject(VLanID::class);
|
|
|
if ($obj) {
|
|
|
$args->getEntity()->setVlan($obj);
|
|
|
}
|
|
@@ -311,10 +299,7 @@ class ONUSubscriber implements EventSubscriber
|
|
|
|
|
|
// Si la ONU no tiene asignadas vlans, busco alguna que este por default
|
|
|
$vlans = $onu->getVlans() ?: [];
|
|
|
- $vlanDefault = $this->em->getRepository(VLanID::class)
|
|
|
- ->findOneBy(array(
|
|
|
- "usedByDefault" => true,
|
|
|
- ));
|
|
|
+ $vlanDefault = $this->getDefaultObject(VLanID::class);
|
|
|
if ((is_null($vlans) || count($vlans) == 0) && $vlanDefault) {
|
|
|
$vlans = [
|
|
|
$vlanDefault,
|
|
@@ -385,13 +370,15 @@ class ONUSubscriber implements EventSubscriber
|
|
|
$olt = $args->getEntity()->getOlt();
|
|
|
$vlanName = "vlanid_data";
|
|
|
|
|
|
- if(!$olt || $olt->getMark() != "FiberHome")
|
|
|
+ if (!$olt || $olt->getMark() != "FiberHome") {
|
|
|
return true;
|
|
|
+ }
|
|
|
|
|
|
- if($args->getEntity()->getVlanByName($vlanName))
|
|
|
+ if ($args->getEntity()->getVlanByName($vlanName)) {
|
|
|
return true;
|
|
|
+ }
|
|
|
|
|
|
- $obj = $this->em->getRepository(VLanID::class)->findOneBy(array("usedByDefault" => true, "name" => $vlanName));
|
|
|
+ $obj = $this->getDefaultObject(VLanID::class, ['name' => $vlanName,]);
|
|
|
if ($obj) {
|
|
|
$args->getEntity()->addVlan($obj);
|
|
|
$this->em->flush();
|
|
@@ -401,11 +388,35 @@ class ONUSubscriber implements EventSubscriber
|
|
|
$args->getEntity()->addVlan($obj);
|
|
|
$this->em->flush();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
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 = [])
|
|
|
+ {
|
|
|
+ $filter = $fields + [
|
|
|
+ 'usedByDefault' => true,
|
|
|
+ 'tenancyId' => $this->tenancyService->getTenancyIdCurrent(),
|
|
|
+ ];
|
|
|
+ $obj = $this->em->getRepository($class)->findOneBy($filter);
|
|
|
+ if (is_null($obj)) {
|
|
|
+ $filter['tenancyId'] = 1;
|
|
|
+ $obj = $this->em->getRepository($class)->findOneBy($filter);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $obj;
|
|
|
+ }
|
|
|
|
|
|
}
|