|
@@ -75,6 +75,7 @@ EOT
|
|
|
'username' => $input->getOption('api-username'),
|
|
|
'password' => $input->getOption('api-password'),
|
|
|
];
|
|
|
+ $this->connection = $this->getContainer()->get('database_connection');
|
|
|
$this->webservice = $this->getContainer()->get('webservice');
|
|
|
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
|
|
|
|
|
@@ -108,15 +109,35 @@ EOT
|
|
|
*/
|
|
|
private function findCablemodem($mac)
|
|
|
{
|
|
|
- $ws = $this->webservice;
|
|
|
- $urlGET = $this->input->getOption('url-get');
|
|
|
-
|
|
|
- // Consulto en Cablemodem
|
|
|
- $cablemodem = null;
|
|
|
- $url = $ws->buildUrl($urlGET, compact('mac'));
|
|
|
- $cablemodemJSON = $ws->makeGetRequest($url);
|
|
|
- if ($cablemodemJSON) {
|
|
|
- $cablemodem = current(json_decode($cablemodemJSON, true));
|
|
|
+ // Se consulta MySQL, de lo contrario se consulta por ws
|
|
|
+ try {
|
|
|
+ $cablemodem = null;
|
|
|
+
|
|
|
+ $query = "SELECT * FROM fd3_cablemodem.cablemodem WHERE mac=:mac;";
|
|
|
+ $stmt = $this->connection->prepare($query);
|
|
|
+ $stmt->bindValue('mac', $mac);
|
|
|
+ $stmt->execute();
|
|
|
+ $result = $stmt->fetchAll();
|
|
|
+ if (isset($result[0])) {
|
|
|
+ $cablemodem = $result[0];
|
|
|
+ } else {
|
|
|
+ $ws = $this->webservice;
|
|
|
+ $urlGET = $this->input->getOption('url-get');
|
|
|
+
|
|
|
+ // Consulto en Cablemodem por ws
|
|
|
+ $url = $ws->buildUrl($urlGET, compact('mac'));
|
|
|
+ $cablemodemJSON = $ws->makeGetRequest($url);
|
|
|
+ if ($cablemodemJSON) {
|
|
|
+ $decode = json_decode($cablemodemJSON, true);
|
|
|
+ if (json_last_error() == JSON_ERROR_NONE) {
|
|
|
+ $cablemodem = current($decode);
|
|
|
+ } else {
|
|
|
+ var_dump(json_last_error_msg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (\Exception $ex) {
|
|
|
+ var_dump($ex->getMessage());
|
|
|
}
|
|
|
|
|
|
return $cablemodem;
|
|
@@ -130,29 +151,56 @@ EOT
|
|
|
*/
|
|
|
private function updateCablemodem($cablemodem, $host)
|
|
|
{
|
|
|
- $ws = $this->webservice;
|
|
|
- $id = $cablemodem['id'];
|
|
|
- $urlPUT = str_replace('{id}', $id, $this->input->getOption('url-put'));
|
|
|
- $fixedAddress = $host->getFixedAddress();
|
|
|
- $data = [];
|
|
|
- switch ($host->getHostType()->getShortname()) {
|
|
|
- case 'cablemodem':
|
|
|
- $data['fixedIP'] = $fixedAddress;
|
|
|
- break;
|
|
|
- case 'cpe':
|
|
|
- $data['cpeFixedIP'] = $fixedAddress;
|
|
|
- break;
|
|
|
- case 'mta':
|
|
|
- $data['mtaFixedIP'] = $fixedAddress;
|
|
|
- break;
|
|
|
- default:
|
|
|
- $data['fixedIP'] = $fixedAddress;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- $cablemodemJSON = $ws->makeGetRequest($urlPUT, HttpRequestInterface::METHOD_PUT, $data);
|
|
|
- if ($cablemodemJSON) {
|
|
|
- $cablemodem = current(json_decode($cablemodemJSON, true));
|
|
|
+ // actualizo por db o ws
|
|
|
+ try {
|
|
|
+ $fixedAddress = $host->getFixedAddress();
|
|
|
+ $data = [];
|
|
|
+ switch ($host->getHostType()->getShortname()) {
|
|
|
+ case 'cablemodem':
|
|
|
+ $data['fixedIP'] = $fixedAddress;
|
|
|
+ $set = 'fixed_ip=:fixed_ip';
|
|
|
+ break;
|
|
|
+ case 'cpe':
|
|
|
+ $data['cpeFixedIP'] = $fixedAddress;
|
|
|
+ $set = 'cpe_fixed_ip=:fixed_ip';
|
|
|
+ break;
|
|
|
+ case 'mta':
|
|
|
+ $data['mtaFixedIP'] = $fixedAddress;
|
|
|
+ $set = 'mta_fixed_ip=:fixed_ip';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $data['fixedIP'] = $fixedAddress;
|
|
|
+ $set = 'fixed_ip=:fixed_ip';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $query = sprintf("UPDATE fd3_cablemodem.cablemodem
|
|
|
+ SET %s
|
|
|
+ WHERE mac=:mac;
|
|
|
+ ", $set);
|
|
|
+
|
|
|
+ $stmt = $this->connection->prepare($query);
|
|
|
+ $stmt->bindValue('mac', $cablemodem['mac']);
|
|
|
+ $stmt->bindValue('fixed_ip', $fixedAddress);
|
|
|
+ $result = $stmt->execute();
|
|
|
+
|
|
|
+ if (!$result) {
|
|
|
+ $ws = $this->webservice;
|
|
|
+ $id = $cablemodem['id'];
|
|
|
+ $urlPUT = str_replace('{id}', $id, $this->input->getOption('url-put'));
|
|
|
+
|
|
|
+ $cablemodemJSON = $ws->makeGetRequest($urlPUT, HttpRequestInterface::METHOD_PUT, $data);
|
|
|
+ if ($cablemodemJSON) {
|
|
|
+ $decode = json_decode($cablemodemJSON, true);
|
|
|
+ if (json_last_error() == JSON_ERROR_NONE) {
|
|
|
+ $cablemodem = current($decode);
|
|
|
+ } else {
|
|
|
+ var_dump(json_last_error_msg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (\Exception $ex) {
|
|
|
+ var_dump($ex->getMessage());
|
|
|
}
|
|
|
|
|
|
return $cablemodem;
|