Import/Core_geoip.php
[Pman.Core] / Import / Core_geoip.php
index e9b446f..8f01de9 100644 (file)
@@ -37,9 +37,15 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
             $this->jerr('GeoLite2-City-Locations.csv OR GeoLite2-City-Blocks.csv does not exists?!');
         }
         
-//        $this->insertLocation($location);
+        $this->log("Insert location data started");
+        
+        $this->insertLocation($location);
+        
+        $this->log("Insert Block data end");
         
         $this->insertBlock($block);
+        
+        $this->jok("DONE");
     }
     
     function insertLocation($csv)
@@ -249,6 +255,12 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
     
     function processBlock($row)
     {
+        if(empty($this->id_mapping[$row['GEONAME_ID']])){
+            $this->log("Missing mapping for {$row['GEONAME_ID']}");
+            $this->log("IP : {$row['NETWORK_START_IP']}");
+            return;
+        }
+        
         $network_mapping = DB_DataObject::factory('core_geoip_network_mapping');
         
         $start_ip = array_pop(explode(":", $row['NETWORK_START_IP']));
@@ -263,6 +275,16 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
             $network_mapping->insert();
         }
         
+        $location = DB_DataObject::factory('core_geoip_location');
+        if(!$location->get('city_id', $network_mapping->city_id)){
+            $location->setFrom(array(
+                'latitude' => $row['LATITUDE'],
+                'longitude' => $row['LONGITUDE'],
+                'city_id' => $network_mapping->city_id
+            ));
+        }
+        
+        
         if(!empty($row['POSTAL_CODE'])){
             $city = DB_DataObject::factory('core_geoip_city');
             if($city->get($network_mapping->city_id)){
@@ -275,10 +297,8 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
             $city->update($oc);
         }
         
-        
     }
     
-    
     function log($str)
     {
         echo "$str \n";