Ver Fonte

Ref #9 - Quoting / Escaping values.

Maximiliano Schvindt há 6 anos atrás
pai
commit
b6534fb9ac
1 ficheiros alterados com 9 adições e 11 exclusões
  1. 9 11
      src/StatsBundle/Command/StatsOnuCommand.php

+ 9 - 11
src/StatsBundle/Command/StatsOnuCommand.php

@@ -38,6 +38,7 @@ class StatsOnuCommand extends BaseCommand
         $now = date("d-m-Y H:i:s");
 
         $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
+        $conn = $doctrine->getConnection();
         
         $deviceOlt = $doctrine->getRepository('\StatsBundle\Entity\Device')->findOneBy(array('deviceId' => $oltDeviceId, 'deviceServer' => $oltServerId, 'deviceType' => 'FTTHBundle\Entity\OLT'));
 
@@ -122,17 +123,17 @@ class StatsOnuCommand extends BaseCommand
 		        $clientId = $devices[$serialNumber]['clientId'];
 		        if(isset($clients[$clientId])) {
 		            $row['clientId'] = $clientId;
-		        	$row['clientExternalId'] = "'".$clients[$clientId]['externalId']."'";
-		        	$row['clientName'] = "'".$clients[$clientId]['name']."'";
-		        	$row['clientAddress'] = "'".$clients[$clientId]['address']."'";
+		        	$row['clientExternalId'] = $conn->quote($clients[$clientId]['externalId']);
+		        	$row['clientName'] = $conn->quote($clients[$clientId]['name']);
+		        	$row['clientAddress'] = $conn->quote($clients[$clientId]['address']);
 		        }
 		    } elseif(isset($devices[$ponSerialNumber]) && isset($devices[$ponSerialNumber]['clientId'])) {
 		        $clientId = $devices[$ponSerialNumber]['clientId'];
 		        if(isset($clients[$clientId])) {
 		            $row['clientId'] = $clientId;
-		        	$row['clientExternalId'] = "'".$clients[$clientId]['externalId']."'";
-		        	$row['clientName'] = "'".$clients[$clientId]['name']."'";
-		            $row['clientAddress'] = "'".$clients[$clientId]['address']."'";
+		        	$row['clientExternalId'] = $conn->quote($clients[$clientId]['externalId']);
+		        	$row['clientName'] = $conn->quote($clients[$clientId]['name']);
+		            $row['clientAddress'] = $conn->quote($clients[$clientId]['address']);
 		        }
 		    }
 
@@ -140,19 +141,16 @@ class StatsOnuCommand extends BaseCommand
         }
 
         if($data) {
-            $conn = $doctrine->getConnection();
             $sql = "DELETE FROM `onu` WHERE device_server_id = {$deviceServerId} AND olt_device_id = {$oltDeviceId};";
             $conn->query($sql);
-            $conn->close();
             
-            $conn = $doctrine->getConnection();
             $sql = "INSERT LOW_PRIORITY IGNORE INTO `onu` (`device_server_id`,`device_id`,`olt_device_id`,`tenancy_id`,`ip`,`mac`,`serial_number`,`pon_serial_number`,`pon_port`,`tx_power`,`rx_power`,`temperature`,`voltage`,`status`,`uptime`,`updated`,`lat`,`lng`,`index`,`in_octets`,`out_octets`,`rx_power_olt`,`client_id`,`client_external_id`,`client_name`,`client_address`) VALUES ".  implode(",", $data).";";
             $conn->query($sql);
-            $conn->close();
         } else {
             print_r("No se encuentran ONUs cargadas en Redis, comprobar onu:scan y onu:stats".PHP_EOL);
         }
-
+        
+        $conn->close();
     }
 
     private function getBandwidth($server, $olt) {