Add progress bar for all import process
[civicrm-core.git] / CRM / Member / Import / Parser.php
index fdf5014a5c750e251fac21d4eff1bf66bbce084c..b8ffc0f91ee0773b80bd32631af61ccfccb82014 100644 (file)
@@ -81,7 +81,9 @@ abstract class CRM_Member_Import_Parser extends CRM_Import_Parser {
     $skipColumnHeader = FALSE,
     $mode = self::MODE_PREVIEW,
     $contactType = self::CONTACT_INDIVIDUAL,
-    $onDuplicate = self::DUPLICATE_SKIP
+    $onDuplicate = self::DUPLICATE_SKIP,
+    $statusID = NULL,
+    $totalRowCount = NULL
   ) {
     if (!is_array($fileName)) {
       CRM_Core_Error::fatal();
@@ -128,6 +130,10 @@ abstract class CRM_Member_Import_Parser extends CRM_Import_Parser {
     else {
       $this->_activeFieldCount = count($this->_activeFields);
     }
+    if ($statusID) {
+      $this->progressImport($statusID);
+      $startTimestamp = $currTimestamp = $prevTimestamp = time();
+    }
 
     while (!feof($fd)) {
       $this->_lineCount++;
@@ -146,7 +152,6 @@ abstract class CRM_Member_Import_Parser extends CRM_Import_Parser {
       }
 
       /* trim whitespace around the values */
-
       $empty = TRUE;
       foreach ($values as $k => $v) {
         $values[$k] = trim($v, " \t\r\n");
@@ -168,6 +173,9 @@ abstract class CRM_Member_Import_Parser extends CRM_Import_Parser {
       }
       elseif ($mode == self::MODE_IMPORT) {
         $returnCode = $this->import($onDuplicate, $values);
+        if ($statusID && (($this->_lineCount % 50) == 0)) {
+          $prevTimestamp = $this->progressImport($statusID, FALSE, $startTimestamp, $prevTimestamp, $totalRowCount);
+        }
       }
       else {
         $returnCode = self::ERROR;