$this->get();
}
+ var $processed = 0;
+ var $total = 0;
+ var $echo = '';
+
function get()
{
$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");
}
$cols = false;
+ $this->processed = 0;
+ $this->total = count(file($csv));
+ $this->echo = '';
+
while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
if(!array_filter($n)){ // empty row
continue;
}
$this->processLocation($row);
+
+ $this->processed++;
+
+ $this->processStatus();
}
}
$cols = false;
+ $this->processed = 0;
+ $this->total = count(file($csv));
+ $this->echo = '';
+
while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
if(!array_filter($n)){ // empty row
continue;
}
$this->processBlock($row);
+
+ $this->processed++;
+
+ $this->processStatus();
+
}
}
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']));
}
- function log($str)
+ function processStatus()
{
- echo "$str \n";
+ echo "\033[K"; // Erase to end of line:
+
+ if (strlen($this->echo)) {
+ echo "\033[".strlen($this->echo)."D"; // Move $length characters backward
+ }
+
+ $this->echo = str_pad(ROUND(($this->processed / $this->total),2) * 100, 3, ' ', STR_PAD_LEFT) .
+ " % (" . str_pad(($this->processed), strlen($this->total), ' ', STR_PAD_LEFT) .
+ " / {$this->total})";
+
+
+ echo $this->echo;
+
+ if($this->processed == $this->total){
+ echo "\n";
+ }
}
}