Browse Source

migraciones

Luciano Andrade 7 years ago
parent
commit
a77d531e27

File diff suppressed because it is too large
+ 6 - 0
app/DoctrineMigrations/Templates20180410130145/zte.yml


+ 27 - 0
app/DoctrineMigrations/Version20180410130145.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+use MigrationsBundle\Migrations\MigrationsBase;
+
+class Version20180410130145 extends MigrationsBase
+{
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        // this up() migration is auto-generated, please modify it to your needs
+        $this->executeYaml(__DIR__, 'Templates20180410130145/zte.yml');
+
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+    }
+}

File diff suppressed because it is too large
+ 56 - 0
app/DoctrineMigrations/Version20180410153401.php


+ 3 - 3
src/FTTHBundle/Entity/ONU.php

@@ -173,21 +173,21 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
 
     /**
      * @ORM\ManyToOne(targetEntity="TContProfile", inversedBy="onus", fetch="EXTRA_LAZY")
-     * @ORM\JoinColumn(name="tcontprofile_id", referencedColumnName="id")
+     * @ORM\JoinColumn(name="tcontprofile_id", referencedColumnName="id", onDelete="SET NULL")
      * @JMS\MaxDepth(1)
      */
     protected $tcontprofile;
 
     /**
      * @ORM\ManyToOne(targetEntity="TrafficProfile", inversedBy="onus", fetch="EXTRA_LAZY")
-     * @ORM\JoinColumn(name="traffic_profile_id", referencedColumnName="id")
+     * @ORM\JoinColumn(name="traffic_profile_id", referencedColumnName="id", onDelete="SET NULL")
      * @JMS\MaxDepth(1)
      */
     protected $traffic_profile;
 
     /**
      * @ORM\ManyToOne(targetEntity="VLanID", inversedBy="onus", fetch="EXTRA_LAZY")
-     * @ORM\JoinColumn(name="vlan_id", referencedColumnName="id")
+     * @ORM\JoinColumn(name="vlan_id", referencedColumnName="id", onDelete="SET NULL")
      * @JMS\MaxDepth(1)
      */
     protected $vlan;

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

@@ -59,10 +59,11 @@ class ONUSubscriber implements EventSubscriber
     {
         $this->execute($args, DoctrineEvents::PRE_PERSIST);
 
+	$entity = $args->getEntity();
         if ($entity instanceof ONU) {
-		$this->assignTrafficProfile($args, DoctrineEvents::PRE_PERSIST)
-		$this->assignTConProfile($args, DoctrineEvents::PRE_PERSIST)
-		$this->assignVLanId($args, DoctrineEvents::PRE_PERSIST)
+		if(!$entity->getTrafficProfile()) $this->assignTrafficProfile($args, DoctrineEvents::PRE_PERSIST);
+		if(!$entity->getTcontprofile()) $this->assignTConProfile($args, DoctrineEvents::PRE_PERSIST);
+		if(!$entity->getVlan()) $this->assignVLanId($args, DoctrineEvents::PRE_PERSIST);
 	}
     }
 
@@ -87,20 +88,33 @@ class ONUSubscriber implements EventSubscriber
     {
         $this->execute($args, DoctrineEvents::PRE_UPDATE);
 
+	$entity = $args->getEntity();
         if ($entity instanceof ONU) {
-		$this->assignTrafficProfile($args, DoctrineEvents::PRE_UPDATE)
-		$this->assignTConProfile($args, DoctrineEvents::PRE_UPDATE)
-		$this->assignVLanId($args, DoctrineEvents::PRE_UPDATE)
+		if(!$entity->getTrafficProfile()) $this->assignTrafficProfile($args, DoctrineEvents::PRE_PERSIST);
+		if(!$entity->getTcontprofile()) $this->assignTConProfile($args, DoctrineEvents::PRE_PERSIST);
+		if(!$entity->getVlan()) $this->assignVLanId($args, DoctrineEvents::PRE_PERSIST);
 	}
     }
 
-    public function assignTrafficProfile(LifecycleEventArgs $args, $eventName = DoctrineEvents::PRE_PERSIST)
+    public function assignTrafficProfile(LifecycleEventArgs $args, $eventName = DoctrineEvents::PRE_PERSIST){
+	$obj = $args->getEntityManager()->getRepository("FTTHBundle:TrafficProfile")->findOneBy( array("used_by_default" => true));
+	if($obj){
+		$args->getEntity()->setTrafficProfile($obj);
+	}
     }
 
-    public function assignTConProfile(LifecycleEventArgs $args, $eventName = DoctrineEvents::PRE_PERSIST)
+    public function assignTConProfile(LifecycleEventArgs $args, $eventName = DoctrineEvents::PRE_PERSIST){
+	$obj = $args->getEntityManager()->getRepository("FTTHBundle:TContProfile")->findOneBy( array("used_by_default" => true));
+	if($obj){
+		$args->getEntity()->setTcontprofile($obj);
+	}
     }
 
-    public function assignVLanId(LifecycleEventArgs $args, $eventName = DoctrineEvents::PRE_PERSIST)
+    public function assignVLanId(LifecycleEventArgs $args, $eventName = DoctrineEvents::PRE_PERSIST){
+	$obj = $args->getEntityManager()->getRepository("FTTHBundle:VLanID")->findOneBy( array("used_by_default" => true));
+	if($obj){
+		$args->getEntity()->setVlan($obj);
+	}
     }
 
     /**