Explorar o código

agregue un metodo para desactivar las acciones remotas

Luciano Andrade %!s(int64=7) %!d(string=hai) anos
pai
achega
55ea61e1c1
Modificáronse 1 ficheiros con 18 adicións e 1 borrados
  1. 18 1
      EventListener/DeviceListener.php

+ 18 - 1
EventListener/DeviceListener.php

@@ -42,6 +42,7 @@ class DeviceListener
         $this->devicePostUrl = $devicePostUrl;
         $this->deviceDeletePostUrl = $deviceDeletePostUrl;
         $this->devicePutUrl = $devicePutUrl;
+	$this->enabled = true;
     }
 
     /**
@@ -49,7 +50,9 @@ class DeviceListener
      */
     public function postPersist(LifecycleEventArgs $args)
     {
-        $this->send($args, $this->devicePostUrl, HttpRequestInterface::METHOD_POST);
+	if(!$this->enabled) return ;
+
+	$this->send($args, $this->devicePostUrl, HttpRequestInterface::METHOD_POST);
     }
 
     /**
@@ -57,6 +60,8 @@ class DeviceListener
      */
     public function preRemove(LifecycleEventArgs $args)
     {
+	if(!$this->enabled) return ;
+
         $entity = $args->getEntity();
         if ($entity instanceof DeviceInterface) {
             if($deviceId = $this->getRemoteDeviceId($entity)) {
@@ -72,6 +77,8 @@ class DeviceListener
      */
     public function postUpdate(LifecycleEventArgs $args)
     {
+	if(!$this->enabled) return ;
+
         $entity = $args->getEntity();
         if ($entity instanceof DeviceInterface) {
             if($deviceId = $this->getRemoteDeviceId($entity)) {
@@ -91,6 +98,8 @@ class DeviceListener
      */
     private function send(LifecycleEventArgs $args, $url, $method)
     {
+	if(!$this->enabled) return ;
+
         $entity = $args->getEntity();
         if ($entity instanceof DeviceInterface) {
             $data = $entity->getDeviceData();
@@ -110,6 +119,8 @@ class DeviceListener
      */
     private function addLocationData($entity, $data)
     {
+	$this->enabled = true;
+
         $locationInterface = 'MapBundle\Entity\Interfaces\LocationInterface';
         if (interface_exists($locationInterface) && is_a($entity, $locationInterface)) {
             $extraData = json_decode($data['extraData'], true);
@@ -125,6 +136,8 @@ class DeviceListener
      */
     private function getRemoteDeviceId($entity) 
     {
+	$this->enabled = true;
+
         $deviceId = $entity->getId();
         $deviceType = get_class($entity);
         $tenancyId = $entity->getTenancyId();
@@ -142,4 +155,8 @@ class DeviceListener
         return $deviceId;
     }
 
+    function remoteCheck($enabled = true){
+	$this->enabled = true;
+    }
+
 }