Add progress bar for all import process
[civicrm-core.git] / CRM / Member / Import / Parser.php
index fe2ae708ada4e7fd3c9b5d025c97e71e78c43381..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;
@@ -191,11 +199,9 @@ abstract class CRM_Member_Import_Parser extends CRM_Import_Parser {
 
       if ($returnCode & self::ERROR) {
         $this->_invalidRowCount++;
-        if ($this->_invalidRowCount < $this->_maxErrorCount) {
-          $recordNumber = $this->_lineCount;
-          array_unshift($values, $recordNumber);
-          $this->_errors[] = $values;
-        }
+        $recordNumber = $this->_lineCount;
+        array_unshift($values, $recordNumber);
+        $this->_errors[] = $values;
       }
 
       if ($returnCode & self::CONFLICT) {