$this->jerr('GeoLite2-City-Locations.csv OR GeoLite2-City-Blocks.csv does not exists?!');
}
-// $this->insertLocation($location);
+ $this->log("Insert location data start");
+
+ $this->insertLocation($location);
+
+ $this->log("Insert Block data start");
$this->insertBlock($block);
+
+ $this->jok("DONE");
}
function insertLocation($csv)
ini_set("auto_detect_line_endings", true);
$fh = fopen($csv, 'r');
+
if (!$fh) {
$this->jerr("invalid location file");
}
+ $linecount = count(file($csv));
+
+ print_r($linecount);exit;
+
$req = array(
'GEONAME_ID', 'CONTINENT_CODE', 'CONTINENT_NAME',
'COUNTRY_ISO_CODE', 'COUNTRY_NAME', 'SUBDIVISION_ISO_CODE',
function processLocation($row)
- {
+ {
$continent = $this->processContinent($row['CONTINENT_CODE'], $row['CONTINENT_NAME']);
$country = $this->processCountry($row['COUNTRY_ISO_CODE'], $row['COUNTRY_NAME'], $continent);
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']));
$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)){
$city->update($oc);
}
-
}
-
function log($str)
{
echo "$str \n";