浏览代码

Merge branch 'master' of https://bitbucket.org/ikflowdat/cablemodem

Fernando Alonso 6 年之前
父节点
当前提交
c70d71a283
共有 1 个文件被更改,包括 28 次插入14 次删除
  1. 28 14
      src/CablemodemBundle/Command/DHCPHostCRUDCommand.php

+ 28 - 14
src/CablemodemBundle/Command/DHCPHostCRUDCommand.php

@@ -20,7 +20,7 @@ class DHCPHostCRUDCommand extends ContainerAwareCommand
     {
         $params = [
             'CMD_USERNAME' => getenv("CMD_USERNAME") ? getenv("CMD_USERNAME") : 'admin',
-            'CMD_PASSWORD' => getenv("CMD_PASSWORD") ? getenv("CMD_PASSWORD") : 'adminpass'
+            'CMD_PASSWORD' => getenv("CMD_PASSWORD") ? getenv("CMD_PASSWORD") : 'admin'
         ];
 
         $dhcpUrl = getenv("HOST_DHCP");
@@ -107,8 +107,11 @@ EOT
         $url = $ws->buildUrl($urlGET, [
             'mac' => $this->mac,
         ]);
-        if ($hostJSON = $ws->makeGetRequest($url, HttpRequestInterface::METHOD_GET, [], $this->credentials)) {
-            $host = current(json_decode($hostJSON, true));
+        if ($hostJSON = $ws->makeGetRequest($url)) {
+            $hostDecode = json_decode($hostJSON, true);
+            if (json_last_error() == JSON_ERROR_NONE && is_array($hostDecode)) {
+                $host = current($hostDecode);
+            }
         }
         
         // Consulto por Host con HostType MTA o CPE relacionado
@@ -118,8 +121,11 @@ EOT
                 'host' => $hostId,
                 'hostType' => $this->getIdHostType($type),
             ]);
-            if ($hostJSON = $ws->makeGetRequest($url, HttpRequestInterface::METHOD_GET, [], $this->credentials)) {
-                $host = current(json_decode($hostJSON, true));
+            if ($hostJSON = $ws->makeGetRequest($url)) {
+                $hostDecode = json_decode($hostJSON, true);
+                if (json_last_error() == JSON_ERROR_NONE && is_array($hostDecode)) {
+                    $host = current($hostDecode);
+                }
             }
             if (!isset($hostId)) {
                 $this->io->error("No existe el hostType {$type} en DHCP");
@@ -128,7 +134,6 @@ EOT
             }
         }
         
-        
         // Creo, edito o elimino dependiendo los parámetros
         $method = HttpRequestInterface::METHOD_POST;
         if ($this->input->getOption('delete') == true) {
@@ -169,7 +174,7 @@ EOT
         
         $this->io->text('DATA: ' . json_encode($data));
         
-        return $ws->makeGetRequest($this->getUrlParameter($method, $host), $method, $data, $this->credentials);
+        return $ws->makeGetRequest($this->getUrlParameter($method, $host), $method, $data);
     }
     
     /**
@@ -187,8 +192,11 @@ EOT
         $url = $ws->buildUrl($urlGET, [
             'mac' => $this->mac,
         ]);
-        if ($hostJSON = $ws->makeGetRequest($url, HttpRequestInterface::METHOD_GET, [], $this->credentials)) {
-            $host = current(json_decode($hostJSON, true));
+        if ($hostJSON = $ws->makeGetRequest($url)) {
+            $hostDecode = json_decode($hostJSON, true);
+            if (json_last_error() == JSON_ERROR_NONE && is_array($hostDecode)) {
+                $host = current($hostDecode);
+            }
         }
         
         // Consulto por Host con HostType MTA o CPE relacionado
@@ -199,8 +207,11 @@ EOT
                 'host' => $hostId,
                 'hostType' => $this->getIdHostType($type),
             ]);
-            if ($hostJSON = $ws->makeGetRequest($url, HttpRequestInterface::METHOD_GET, [], $this->credentials)) {
-                $deleteHost = current(json_decode($hostJSON, true));
+            if ($hostJSON = $ws->makeGetRequest($url)) {
+                $hostDecode = json_decode($hostJSON, true);
+                if (json_last_error() == JSON_ERROR_NONE && is_array($hostDecode)) {
+                    $deleteHost = current($hostDecode);
+                }
             }
         }
         
@@ -217,7 +228,7 @@ EOT
         
         $this->io->text('DATA: ' . json_encode($data));
 
-        return $ws->makeGetRequest($this->getUrlParameter($method, $deleteHost), $method, $data, $this->credentials);
+        return $ws->makeGetRequest($this->getUrlParameter($method, $deleteHost), $method, $data);
     }
 
     /**
@@ -265,9 +276,12 @@ EOT
         $url = $this->webservice->buildUrl($url, [
             'shortname' => $name,
         ]);
-        $hostTypeJSON = $this->webservice->makeGetRequest($url, HttpRequestInterface::METHOD_GET, [], $this->credentials);
+        $hostTypeJSON = $this->webservice->makeGetRequest($url);
         if ($hostTypeJSON != '' && !is_null($hostTypeJSON)) {
-            $hostType = current(json_decode($hostTypeJSON, true))['id'];
+            $hostDecode = json_decode($hostTypeJSON, true);
+            if (json_last_error() == JSON_ERROR_NONE && is_array($hostDecode)) {
+                $hostType = current($hostDecode)['id'];
+            }
         }
         
         return $hostType;