|
@@ -7,7 +7,7 @@ use DeviceBundle\Interfaces\DeviceInterface;
|
|
|
use WebserviceBundle\Services\Webservice;
|
|
|
use Buzz\Message\RequestInterface as HttpRequestInterface;
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
|
|
-use Symfony\Component\Console\Input\ArrayInput;
|
|
|
+use Symfony\Component\Console\Input\ArgvInput;
|
|
|
use Symfony\Component\Console\Output\BufferedOutput;
|
|
|
use Base\AdminBundle\Interfaces\SoftDeleteInterface;
|
|
|
|
|
@@ -35,7 +35,7 @@ class DeviceListener
|
|
|
private $devicePutUrl;
|
|
|
|
|
|
private $serviceContainer;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @param Webservice $webservice
|
|
@@ -66,46 +66,46 @@ class DeviceListener
|
|
|
$entity = $args->getEntity();
|
|
|
|
|
|
if($entity instanceof SoftDeleteInterface && $entity->isDeleted()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if ($entity instanceof DeviceInterface) {
|
|
|
$cmd_args = array(
|
|
|
'--type:' . get_class($entity),
|
|
|
'--id:' . $entity->getId(),
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
return $this->runCommand('device:crud', $cmd_args);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Corro el comando para crear el device por AMQP
|
|
|
* @global kernel $kernel
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string $name
|
|
|
* @param array $args
|
|
|
- *
|
|
|
+ *
|
|
|
* @return string
|
|
|
*/
|
|
|
public function runCommand($name, $cmd_args = array())
|
|
|
{
|
|
|
|
|
|
$kernel = $this->serviceContainer->get('kernel');
|
|
|
-
|
|
|
+
|
|
|
$application = new Application($kernel);
|
|
|
$application->setAutoExit(false);
|
|
|
-
|
|
|
- $input = new ArrayInput(array(
|
|
|
- 'command' => 'amqp:remote',
|
|
|
- 'name' => $name,
|
|
|
- '--args' => $cmd_args,
|
|
|
- '--route' => getenv("AMQP_KEY"),
|
|
|
+
|
|
|
+ $input = new ArgvInput(array(
|
|
|
+ 'amqp:remote',
|
|
|
+ $name,
|
|
|
+ ' --args=' . implode(' --args=', $cmd_args),
|
|
|
+ '--route=' . getenv("AMQP_KEY"),
|
|
|
));
|
|
|
-
|
|
|
+
|
|
|
$output = new BufferedOutput();
|
|
|
-
|
|
|
+
|
|
|
$application->run($input, $output);
|
|
|
|
|
|
return $output->fetch();
|
|
@@ -113,7 +113,7 @@ class DeviceListener
|
|
|
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
- *
|
|
|
+ *
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public function preRemove(LifecycleEventArgs $args)
|
|
@@ -125,7 +125,7 @@ class DeviceListener
|
|
|
$entity = $args->getEntity();
|
|
|
|
|
|
if ($entity instanceof DeviceInterface) {
|
|
|
-
|
|
|
+
|
|
|
if ($deviceId = $this->getRemoteDeviceId($entity)) {
|
|
|
$cmd_args = array(
|
|
|
'--type:' . get_class($entity),
|
|
@@ -153,8 +153,8 @@ class DeviceListener
|
|
|
$entity = $args->getEntity();
|
|
|
|
|
|
if($entity instanceof SoftDeleteInterface && $entity->isDeleted()) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
if ($entity instanceof DeviceInterface) {
|
|
|
$cmd_args = array(
|
|
@@ -165,7 +165,7 @@ class DeviceListener
|
|
|
$cmd_args[] = "--url:{$this->devicePutUrl}{$deviceId}";
|
|
|
$cmd_args[] = '--method:' . HttpRequestInterface::METHOD_PUT;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return $this->runCommand('device:crud', $cmd_args);
|
|
|
}
|
|
|
|
|
@@ -177,7 +177,7 @@ class DeviceListener
|
|
|
* @param string $url
|
|
|
* @param string $method
|
|
|
* @param array $credentials username y password
|
|
|
- *
|
|
|
+ *
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public function send($entity, $url, $method, $credentials = array())
|
|
@@ -220,7 +220,7 @@ class DeviceListener
|
|
|
|
|
|
/**
|
|
|
* @param object $entity
|
|
|
- *
|
|
|
+ *
|
|
|
* @return mixed
|
|
|
*/
|
|
|
private function getRemoteDeviceId($entity)
|
|
@@ -234,8 +234,8 @@ class DeviceListener
|
|
|
$tenancyId = $entity->getTenancyId();
|
|
|
|
|
|
$filters = array(
|
|
|
- 'deviceId' => $deviceId,
|
|
|
- 'deviceType' => $deviceType,
|
|
|
+ 'deviceId' => $deviceId,
|
|
|
+ 'deviceType' => $deviceType,
|
|
|
'tenancyId' => $tenancyId
|
|
|
);
|
|
|
$data = $this->webservice->getData("device_post_url", $filters);
|