Import/Core_geoip.php
[Pman.Core] / Import / Core_geoip.php
index 3ef0f43..0a7c0e1 100644 (file)
@@ -25,6 +25,10 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
         $this->get();
     }
     
+    var $processed = 0;
+    var $total = 0;
+    var $echo = '';
+    
     function get()
     {
         
@@ -52,7 +56,10 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
     {
         ini_set("auto_detect_line_endings", true);
         
+        $linecount = count(file($csv));
+        
         $fh = fopen($csv, 'r');
+        
         if (!$fh) {
             $this->jerr("invalid location file");
         }
@@ -66,6 +73,8 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
         
         $cols = false;
         
+        $processed = 0
+        
         while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
             if(!array_filter($n)){ // empty row
                 continue;
@@ -96,6 +105,25 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
             }
             
             $this->processLocation($row);
+            
+            echo "\033[K"; // Erase to end of line:
+            
+            $echo = '';
+            
+            if (strlen($echo)) {
+                echo "\033[".strlen($echo)."D";    // Move $length characters backward
+            }
+            
+            $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}) - out {$this->out_count}";
+
+
+            echo $this->echo;
+
+            if($this->processed == $this->total){
+                echo "\n";
+            }
         }
         
     }
@@ -155,9 +183,7 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
     
     
     function processLocation($row)
-    {
-        $this->log("Processing Location : Continent - {$row['CONTINENT_NAME']}({$row['CONTINENT_CODE']}) | Country - {$row['COUNTRY_NAME']}({$row['COUNTRY_ISO_CODE']}) | Division - {$row['SUBDIVISION_ISO_CODE']}({$row['SUBDIVISION_NAME']}) | City - {$row['CITY_NAME']}");
-        
+    {   
         $continent = $this->processContinent($row['CONTINENT_CODE'], $row['CONTINENT_NAME']);
         
         $country = $this->processCountry($row['COUNTRY_ISO_CODE'], $row['COUNTRY_NAME'], $continent);
@@ -263,8 +289,6 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
             return;
         }
         
-        $this->log("Processing Block : IP - {$row['NETWORK_START_IP']} | City_id - {$this->id_mapping[$row['GEONAME_ID']]}");
-        
         $network_mapping = DB_DataObject::factory('core_geoip_network_mapping');
         
         $start_ip = array_pop(explode(":", $row['NETWORK_START_IP']));