Procházet zdrojové kódy

Agregue soft-deleteable a ONU, permitiendo re-crear cuando el pon_serial_number ya se encontraba borrado.

Luciano Andrade před 7 roky
rodič
revize
f605207b0a

+ 7 - 1
app/config/config.yml

@@ -86,12 +86,18 @@ doctrine:
         naming_strategy: doctrine.orm.naming_strategy.underscore
         naming_strategy: doctrine.orm.naming_strategy.underscore
         auto_mapping: true
         auto_mapping: true
         filters:
         filters:
-            tenancy_filter: Base\AdminBundle\Filter\TenancyFilter
+            soft_deleteable:
+              class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
+              enabled: true
+            tenancy_filter:
+              class: Base\AdminBundle\Filter\TenancyFilter
+              enabled: true
 
 
 stof_doctrine_extensions:
 stof_doctrine_extensions:
     orm:
     orm:
         default:
         default:
             timestampable: true
             timestampable: true
+            softdeleteable: true
 
 
 # Swiftmailer Configuration
 # Swiftmailer Configuration
 swiftmailer:
 swiftmailer:

+ 16 - 0
src/FTTHBundle/Admin/ONUAdmin.php

@@ -169,4 +169,20 @@ class ONUAdmin extends WorkflowBaseAdmin
         $this->setTemplate('create', 'FTTHBundle:ONU:form.html.twig');
         $this->setTemplate('create', 'FTTHBundle:ONU:form.html.twig');
         $this->setTemplate('edit', 'FTTHBundle:ONU:form.html.twig');
         $this->setTemplate('edit', 'FTTHBundle:ONU:form.html.twig');
     }
     }
+
+    public function create($object){
+	    $em = $this->get("doctrine.orm.entity_manager");
+	    $em->getFilters()->disable('soft_deleteable');
+	    $alt = $em->getRepository("FTTHBundle:ONU")->findOneBy(array('ponSerialNumber' => $object->getPonSerialNumber()));
+	    if($alt and $alt->isDeleted()){
+		    $object->setId($alt->getId());
+		    $object->setDeletedAt(NULL);
+		    $object->setCreated(new \DateTime());
+		    $object->setUpdated(new \DateTime());
+		    $object = $em->merge($object);
+	    }
+
+	    $em->getFilters()->enable('soft_deleteable');
+	    return parent::create($object);
+    }
 }
 }

+ 31 - 29
src/FTTHBundle/Entity/ONU.php

@@ -6,7 +6,6 @@ use Base\AdminBundle\Traits\TenancyIdTrait;
 use Base\AdminBundle\Traits\TenancyIdTraitInterface;
 use Base\AdminBundle\Traits\TenancyIdTraitInterface;
 use Doctrine\ORM\Mapping as ORM;
 use Doctrine\ORM\Mapping as ORM;
 use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
 use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
-use Gedmo\Mapping\Annotation as Gedmo;
 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 use Symfony\Component\Validator\Constraints as Assert;
 use Symfony\Component\Validator\Constraints as Assert;
 use Symfony\Component\Workflow\Exception\ExceptionInterface;
 use Symfony\Component\Workflow\Exception\ExceptionInterface;
@@ -17,6 +16,8 @@ use MapBundle\Entity\Interfaces\LocationInterface;
 use MapBundle\Entity\Traits\LocationTrait;
 use MapBundle\Entity\Traits\LocationTrait;
 use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
 use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
 use WorkflowBundle\Entity\Traits\WorkflowTrait;
 use WorkflowBundle\Entity\Traits\WorkflowTrait;
+use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
+use Gedmo\Mapping\Annotation as Gedmo;
 
 
 /**
 /**
  * ONU
  * ONU
@@ -35,6 +36,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
     use TenancyIdTrait;
     use TenancyIdTrait;
     use LocationTrait;
     use LocationTrait;
     use WorkflowTrait;
     use WorkflowTrait;
+    use SoftDeleteable;
 
 
     /**
     /**
      * @var int
      * @var int
@@ -150,11 +152,6 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
      */
      */
     private $position = 0;
     private $position = 0;
 
 
-    /**
-     * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
-     */
-    private $deletedAt;
-
     /**
     /**
      * @return string
      * @return string
      */
      */
@@ -173,6 +170,20 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         return $this->id;
         return $this->id;
     }
     }
 
 
+    /**
+     * Get id
+     *
+     * @param int
+     *
+     * @return ONU
+     */
+    public function setId($id)
+    {
+        $this->id = $id;
+
+	return $this;
+    }
+
     /**
     /**
      * Set ip
      * Set ip
      *
      *
@@ -303,6 +314,20 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         return $this->created;
         return $this->created;
     }
     }
 
 
+    /**
+     * Set created
+     *
+     * @param \DateTime
+     *
+     * @return ONU
+     */
+    public function setCreated($d)
+    {
+        $this->created = $d;
+	return $this;
+    }
+
+
     /**
     /**
      * Get updated
      * Get updated
      *
      *
@@ -540,27 +565,4 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         return $deviceData;
         return $deviceData;
     }
     }
 
 
-    /**
-     * Get deletedAt
-     *
-     * @return \DateTime
-     */
-    public function getDeletedAt()
-    {
-        return $this->deletedAt;
-    }
-
-    /**
-     * Set deletedAt
-     * @param \DateTime $deletedAt
-     *
-     */
-    public function setDeletedAt($deletedAt)
-    {
-        $this->deletedAt = $deletedAt;
-        return $this;
-    }
-
-
-
 }
 }