|
@@ -24,6 +24,11 @@ class DeviceListener
|
|
* @var string
|
|
* @var string
|
|
*/
|
|
*/
|
|
private $deviceDeletePostUrl;
|
|
private $deviceDeletePostUrl;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ private $devicePutUrl;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -31,11 +36,12 @@ class DeviceListener
|
|
* @param string $devicePostUrl
|
|
* @param string $devicePostUrl
|
|
* @param string $deviceDeletePostUrl
|
|
* @param string $deviceDeletePostUrl
|
|
*/
|
|
*/
|
|
- public function __construct(Webservice $webservice, $devicePostUrl, $deviceDeletePostUrl)
|
|
|
|
|
|
+ public function __construct(Webservice $webservice, $devicePostUrl, $deviceDeletePostUrl, $devicePutUrl)
|
|
{
|
|
{
|
|
$this->webservice = $webservice;
|
|
$this->webservice = $webservice;
|
|
$this->devicePostUrl = $devicePostUrl;
|
|
$this->devicePostUrl = $devicePostUrl;
|
|
$this->deviceDeletePostUrl = $deviceDeletePostUrl;
|
|
$this->deviceDeletePostUrl = $deviceDeletePostUrl;
|
|
|
|
+ $this->devicePutUrl = $devicePutUrl;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -51,7 +57,30 @@ class DeviceListener
|
|
*/
|
|
*/
|
|
public function preRemove(LifecycleEventArgs $args)
|
|
public function preRemove(LifecycleEventArgs $args)
|
|
{
|
|
{
|
|
- $this->send($args, $this->deviceDeletePostUrl, HttpRequestInterface::METHOD_DELETE);
|
|
|
|
|
|
+ $entity = $args->getEntity();
|
|
|
|
+ if ($entity instanceof DeviceInterface) {
|
|
|
|
+ if($deviceId = $this->getRemoteDeviceId($entity)) {
|
|
|
|
+
|
|
|
|
+ $data = array('id' => $deviceId);
|
|
|
|
+ return $this->webservice->makeGetRequest($this->deviceDeletePostUrl, HttpRequestInterface::METHOD_DELETE, $data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param LifecycleEventArgs $args
|
|
|
|
+ */
|
|
|
|
+ public function postUpdate(LifecycleEventArgs $args)
|
|
|
|
+ {
|
|
|
|
+ $entity = $args->getEntity();
|
|
|
|
+ if ($entity instanceof DeviceInterface) {
|
|
|
|
+ if($deviceId = $this->getRemoteDeviceId($entity)) {
|
|
|
|
+
|
|
|
|
+ $url = "{$this->devicePutUrl}{$deviceId}";
|
|
|
|
+ $this->send($args, $url, HttpRequestInterface::METHOD_PUT);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -69,4 +98,24 @@ class DeviceListener
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param object $entity
|
|
|
|
+ */
|
|
|
|
+ private function getRemoteDeviceId($entity)
|
|
|
|
+ {
|
|
|
|
+ $deviceId = $entity->getId();
|
|
|
|
+ $deviceType = get_class($entity);
|
|
|
|
+ $tenancyId = $entity->getTenancyId();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $filters = array('deviceId'=>$deviceId,'deviceType'=>$deviceType,'tenancyId'=>$tenancyId);
|
|
|
|
+ $data = $this->webservice->getData("device_post_url",$filters);
|
|
|
|
+
|
|
|
|
+ $deviceId = null;
|
|
|
|
+ if(isset($data[0]))
|
|
|
|
+ $deviceId = $data[0]['id'];
|
|
|
|
+
|
|
|
|
+ return $deviceId;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|