Import/Core_geoip.php
[Pman.Core] / Import / Core_geoip.php
index a43f3c6..d0408f0 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,6 +56,8 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
     {
         ini_set("auto_detect_line_endings", true);
         
+        
+        
         $fh = fopen($csv, 'r');
         
         if (!$fh) {
@@ -67,6 +73,10 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
         
         $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;
@@ -97,6 +107,10 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
             }
             
             $this->processLocation($row);
+            
+            $this->processed++;
+            
+            $this->processStatus();
         }
         
     }
@@ -119,6 +133,10 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
         
         $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;
@@ -149,6 +167,11 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
             }
             
             $this->processBlock($row);
+            
+            $this->processed++;
+            
+            $this->processStatus();
+            
         }
         
     }
@@ -300,8 +323,23 @@ class Pman_Core_Import_Core_geoip extends Pman_Roo
         
     }
     
-    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";
+        }
     }
 }